Skip to content

Commit

Permalink
feat: enable SSE connections by default (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathannorris authored Jan 20, 2025
1 parent 36fbf05 commit 681b1c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
23 changes: 11 additions & 12 deletions configmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func NewEnvironmentConfigManager(
configManager.context, configManager.shutdown = context.WithCancel(context.Background())
configManager.eventManager = manager

if options.EnableBetaRealtimeUpdates {
if options.DisableRealtimeUpdates {
configManager.StartPolling(options.ConfigPollingIntervalMS)
} else {
sseManager, err := newSSEManager(configManager, options, cfg)
if err != nil {
return nil, err
}
configManager.sseManager = sseManager
go configManager.ssePollingManager()
} else {
configManager.StartPolling(options.ConfigPollingIntervalMS)
}
return configManager, err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (e *EnvironmentConfigManager) ssePollingManager() {
case api.ClientEventType_ConfigUpdated:
eventData := event.EventData.(map[string]string)

if url, ok := eventData["sseUrl"]; ok && e.options.EnableBetaRealtimeUpdates && e.sseManager != nil {
if url, ok := eventData["sseUrl"]; ok && !e.options.DisableRealtimeUpdates && e.sseManager != nil {
// Reconnect SSE
if url != "" && (e.sseManager.url != url || !e.sseManager.Connected.Load()) {
err := e.StartSSE(url)
Expand All @@ -149,7 +149,7 @@ func (e *EnvironmentConfigManager) ssePollingManager() {
}

func (e *EnvironmentConfigManager) StartSSE(url string) error {
if !e.options.EnableBetaRealtimeUpdates {
if e.options.DisableRealtimeUpdates {
return fmt.Errorf("realtime updates are disabled. Cannot start SSE")
}
return e.sseManager.StartSSEOverride(url)
Expand Down Expand Up @@ -391,17 +391,16 @@ func (e *EnvironmentConfigManager) setConfig(config []byte, eTag, rayId, lastMod
}

func (e *EnvironmentConfigManager) getConfigURL() string {
configBasePath := e.cfg.ConfigCDNBasePath
configBasePath := e.cfg.ConfigCDNBasePath

version := "v2"
if e.options.AdvancedOptions.OverrideConfigWithV1 {
version = "v1"
}
version := "v2"
if e.options.AdvancedOptions.OverrideConfigWithV1 {
version = "v1"
}

return fmt.Sprintf("%s/config/%s/server/%s.json", configBasePath, version, e.sdkKey)
return fmt.Sprintf("%s/config/%s/server/%s.json", configBasePath, version, e.sdkKey)
}


func (e *EnvironmentConfigManager) HasConfig() bool {
return e.localBucketing.HasConfig()
}
Expand Down
20 changes: 11 additions & 9 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type EventQueueOptions = api.EventQueueOptions

type AdvancedOptions struct {
OverridePlatformData *api.PlatformData
OverrideConfigWithV1 bool
OverrideConfigWithV1 bool
}

type Options struct {
Expand All @@ -28,14 +28,16 @@ type Options struct {
DisableAutomaticEventLogging bool `json:"disableAutomaticEventLogging,omitempty"`
DisableCustomEventLogging bool `json:"disableCustomEventLogging,omitempty"`
DisableETagMatching bool `json:"disableETagMatching,omitempty"`
EnableBetaRealtimeUpdates bool `json:"enableRealtimeUpdates,omitempty"`
MaxEventQueueSize int `json:"maxEventsPerFlush,omitempty"`
FlushEventQueueSize int `json:"minEventsPerFlush,omitempty"`
ConfigCDNURI string
EventsAPIURI string
ClientEventHandler chan api.ClientEvent
BucketingAPIURI string
Logger util.Logger
DisableRealtimeUpdates bool `json:"disableRealtimeUpdates,omitempty"`
// Deprecated: EnableBetaRealtimeUpdates is no longer supported. SSE connections are enabled by default.
EnableBetaRealtimeUpdates bool `json:"enableRealtimeUpdates,omitempty"`
MaxEventQueueSize int `json:"maxEventsPerFlush,omitempty"`
FlushEventQueueSize int `json:"minEventsPerFlush,omitempty"`
ConfigCDNURI string
EventsAPIURI string
ClientEventHandler chan api.ClientEvent
BucketingAPIURI string
Logger util.Logger
AdvancedOptions
}

Expand Down
6 changes: 3 additions & 3 deletions testing_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ var (
// use defaults that will be set by the CheckDefaults
EventFlushIntervalMS: time.Second * 30,
ConfigPollingIntervalMS: time.Second * 10,
DisableRealtimeUpdates: true,
}
test_options_sse = &Options{
// use defaults that will be set by the CheckDefaults
EventFlushIntervalMS: time.Second * 30,
ConfigPollingIntervalMS: time.Second * 10,
EnableBetaRealtimeUpdates: true,
EventFlushIntervalMS: time.Second * 30,
ConfigPollingIntervalMS: time.Second * 10,
}
benchmarkEnableConfigUpdates bool
benchmarkEnableEvents bool
Expand Down

0 comments on commit 681b1c9

Please sign in to comment.