Skip to content

Commit 9825f2d

Browse files
authored
[FSSDK-9632] feat: Implement notification consistency across agent nodes (#399)
* start basic implementation * resolve conflict * change notification.go logic * modify notification handler * Update config * add redis pubsub struct * update config * implement & use redis center as notification.center * use opticlient from middleware * rename notification handler name * update config management * update notidication sender * cleaner syncup code * update test * add notification filtering * fix bug * rename syncer struct * not using pointers * fix test * implement data channel * update tests * add unit tests for default receiver * add unit tests for redis receiver * add unit test * add comments * clean up * fix license header year * update config * use default response writer * filter on sdk keys * update unit test * fix failing acceptance test * rename
1 parent 8448a4d commit 9825f2d

File tree

12 files changed

+703
-145
lines changed

12 files changed

+703
-145
lines changed

cmd/optimizely/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func main() {
267267

268268
ctx, cancel := context.WithCancel(context.Background()) // Create default service context
269269
sg := server.NewGroup(ctx, conf.Server) // Create a new server group to manage the individual http listeners
270-
optlyCache := optimizely.NewCache(ctx, conf.Client, sdkMetricsRegistry)
270+
optlyCache := optimizely.NewCache(ctx, *conf, sdkMetricsRegistry)
271271
optlyCache.Init(conf.SDKKeys)
272272

273273
// goroutine to check for signals to gracefully shutdown listeners
@@ -281,7 +281,7 @@ func main() {
281281
cancel()
282282
}()
283283

284-
apiRouter := routers.NewDefaultAPIRouter(optlyCache, conf.API, agentMetricsRegistry)
284+
apiRouter := routers.NewDefaultAPIRouter(optlyCache, *conf, agentMetricsRegistry)
285285
adminRouter := routers.NewAdminRouter(*conf)
286286

287287
log.Info().Str("version", conf.Version).Msg("Starting services.")

config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,17 @@ runtime:
243243
## To just read the current rate, pass rate < 0.
244244
## (For n>1 the details of sampling may change.)
245245
mutexProfileFraction: 0
246+
247+
## synchronization should be enabled when multiple replicas of agent is deployed
248+
## if notification synchronization is enabled, then the active notification event-stream API
249+
## will get the notifications from multiple replicas
250+
synchronization:
251+
pubsub:
252+
redis:
253+
host: "redis.demo.svc:6379"
254+
password: ""
255+
database: 0
256+
channel: "optimizely-sync"
257+
notification:
258+
enable: false
259+
default: "redis"

config/config.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ func NewDefaultConfig() *AgentConfig {
126126
Webhook: WebhookConfig{
127127
Port: "8085",
128128
},
129+
Synchronization: SyncConfig{
130+
Pubsub: map[string]interface{}{
131+
"redis": map[string]interface{}{
132+
"host": "localhost:6379",
133+
"password": "",
134+
"database": 0,
135+
"channel": "optimizely-notifications",
136+
},
137+
},
138+
Notification: NotificationConfig{
139+
Enable: false,
140+
Default: "redis",
141+
},
142+
},
129143
}
130144

131145
return &config
@@ -139,14 +153,27 @@ type AgentConfig struct {
139153

140154
SDKKeys []string `yaml:"sdkKeys" json:"sdkKeys"`
141155

142-
Admin AdminConfig `json:"admin"`
143-
API APIConfig `json:"api"`
144-
Log LogConfig `json:"log"`
145-
Tracing TracingConfig `json:"tracing"`
146-
Client ClientConfig `json:"client"`
147-
Runtime RuntimeConfig `json:"runtime"`
148-
Server ServerConfig `json:"server"`
149-
Webhook WebhookConfig `json:"webhook"`
156+
Admin AdminConfig `json:"admin"`
157+
API APIConfig `json:"api"`
158+
Log LogConfig `json:"log"`
159+
Tracing TracingConfig `json:"tracing"`
160+
Client ClientConfig `json:"client"`
161+
Runtime RuntimeConfig `json:"runtime"`
162+
Server ServerConfig `json:"server"`
163+
Webhook WebhookConfig `json:"webhook"`
164+
Synchronization SyncConfig `json:"synchronization"`
165+
}
166+
167+
// SyncConfig contains Synchronization configuration for the multiple Agent nodes
168+
type SyncConfig struct {
169+
Pubsub map[string]interface{} `json:"pubsub"`
170+
Notification NotificationConfig `json:"notification"`
171+
}
172+
173+
// NotificationConfig contains Notification Synchronization configuration for the multiple Agent nodes
174+
type NotificationConfig struct {
175+
Enable bool `json:"enable"`
176+
Default string `json:"default"`
150177
}
151178

152179
// HTTPSDisabledWarning is logged when keyfile and certfile are not provided in server configuration

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/golang-jwt/jwt/v4 v4.5.0
1313
github.com/google/uuid v1.3.0
1414
github.com/lestrrat-go/jwx v0.9.0
15-
github.com/optimizely/go-sdk v1.8.4-0.20230515121609-7ffed835c991
15+
github.com/optimizely/go-sdk v1.8.4-0.20230911163718-b10e161e39b8
1616
github.com/orcaman/concurrent-map v1.0.0
1717
github.com/prometheus/client_golang v1.11.0
1818
github.com/rakyll/statik v0.1.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
244244
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
245245
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
246246
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
247-
github.com/optimizely/go-sdk v1.8.4-0.20230515121609-7ffed835c991 h1:bRoRDKRa7EgSTCEb54qaDuU6IDegQKQumun8buDV/cY=
248-
github.com/optimizely/go-sdk v1.8.4-0.20230515121609-7ffed835c991/go.mod h1:06VK8mwwQTEh7QzP+qivf16tXtXEpoeblqtlhfvWEgk=
247+
github.com/optimizely/go-sdk v1.8.4-0.20230911163718-b10e161e39b8 h1:1LhZsu7IB7LR3PzwIzfP56cdOkUAKRXxW1wljd352sg=
248+
github.com/optimizely/go-sdk v1.8.4-0.20230911163718-b10e161e39b8/go.mod h1:zITWqffjOXsae/Z0PlCN5kgJRgJF/0g/k8RBEsxNrxg=
249249
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
250250
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
251251
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=

0 commit comments

Comments
 (0)