Skip to content

Commit

Permalink
[SDKS-7683] Set init config telemetry with FlagSetsTotal and FlagSets…
Browse files Browse the repository at this point in the history
…Invalid
  • Loading branch information
nmayorsplit committed Nov 16, 2023
1 parent bee091f commit 758be91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/splitio/go-client/v6
go 1.18

require (
github.com/splitio/go-split-commons/v5 v5.0.1-0.20231114174555-e7fa17527a05
github.com/splitio/go-split-commons/v5 v5.0.1-0.20231115165340-19ae11b6b7d5
github.com/splitio/go-toolkit/v5 v5.3.2-0.20231106173125-49e72b9823dc
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/redis/go-redis/v9 v9.0.4 h1:FC82T+CHJ/Q/PdyLW++GeCO+Ol59Y4T7R4jbgjvktgc=
github.com/redis/go-redis/v9 v9.0.4/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/splitio/go-split-commons/v5 v5.0.1-0.20231114174555-e7fa17527a05 h1:rDWd6xVhU/XCmWH28+8CnWkJOZ+8yoKxm2+rbX3HahI=
github.com/splitio/go-split-commons/v5 v5.0.1-0.20231114174555-e7fa17527a05/go.mod h1:PSkBLDXQW7NAhZ7JO1va7QJyTeDvpE7MEDnTdn5evRM=
github.com/splitio/go-split-commons/v5 v5.0.1-0.20231115165340-19ae11b6b7d5 h1:tXHXzigms5Umk2HCOv72QqXGVypNSrzpl6E0Mwpxoq4=
github.com/splitio/go-split-commons/v5 v5.0.1-0.20231115165340-19ae11b6b7d5/go.mod h1:PSkBLDXQW7NAhZ7JO1va7QJyTeDvpE7MEDnTdn5evRM=
github.com/splitio/go-toolkit/v5 v5.3.2-0.20231106173125-49e72b9823dc h1:14jdJE/rBEYfs1CO8kOQrj/8azszRFU4yw5FQIGpoJg=
github.com/splitio/go-toolkit/v5 v5.3.2-0.20231106173125-49e72b9823dc/go.mod h1:xYhUvV1gga9/1029Wbp5pjnR6Cy8nvBpjw99wAbsMko=
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
Expand Down
27 changes: 16 additions & 11 deletions splitio/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,25 @@ func (f *SplitFactory) IsReady() bool {
}

// initializates tasks for in-memory mode
func (f *SplitFactory) initializationManager(readyChannel chan int) {
func (f *SplitFactory) initializationManager(readyChannel chan int, flagSetsInvalid int64) {
go f.syncManager.Start()
msg := <-readyChannel
switch msg {
case synchronizer.Ready:
// Broadcast ready status for SDK
f.broadcastReadiness(sdkStatusReady, make([]string, 0))
f.broadcastReadiness(sdkStatusReady, make([]string, 0), flagSetsInvalid)
default:
f.broadcastReadiness(sdkInitializationFailed, make([]string, 0))
f.broadcastReadiness(sdkInitializationFailed, make([]string, 0), flagSetsInvalid)
}
}

func (f *SplitFactory) initializationRedis() {
func (f *SplitFactory) initializationRedis(flagSetsInvalid int64) {
go f.syncManager.Start()
f.broadcastReadiness(sdkStatusReady, make([]string, 0))
f.broadcastReadiness(sdkStatusReady, make([]string, 0), flagSetsInvalid)
}

// recordInitTelemetry In charge of recording init stats from redis and memory
func (f *SplitFactory) recordInitTelemetry(tags []string, currentFactories map[string]int64) {
func (f *SplitFactory) recordInitTelemetry(tags []string, currentFactories map[string]int64, flagSetsInvalid int64) {
f.logger.Debug("Sending init telemetry")
f.telemetrySync.SynchronizeConfig(
telemetry.InitConfig{
Expand All @@ -173,6 +173,8 @@ func (f *SplitFactory) recordInitTelemetry(tags []string, currentFactories map[s
TaskPeriods: config.TaskPeriods(f.cfg.TaskPeriods),
ImpressionsMode: f.cfg.ImpressionsMode,
ListenerEnabled: f.cfg.Advanced.ImpressionListener != nil,
FlagSetsTotal: int64(len(f.cfg.Advanced.FlagSetFilter)),
FlagSetsInvalid: flagSetsInvalid,
},
time.Now().UTC().Sub(f.startTime).Milliseconds(),
currentFactories,
Expand All @@ -181,7 +183,7 @@ func (f *SplitFactory) recordInitTelemetry(tags []string, currentFactories map[s
}

// broadcastReadiness broadcasts message to all the subscriptors
func (f *SplitFactory) broadcastReadiness(status int, tags []string) {
func (f *SplitFactory) broadcastReadiness(status int, tags []string, flagSetsInvalid int64) {
f.mutex.Lock()
defer f.mutex.Unlock()
if f.status.Load() == sdkStatusInitializing && status == sdkStatusReady {
Expand All @@ -191,7 +193,7 @@ func (f *SplitFactory) broadcastReadiness(status int, tags []string) {
subscriptor <- status
}
// At this point the SDK is ready for sending telemetry
go f.recordInitTelemetry(tags, getFactories())
go f.recordInitTelemetry(tags, getFactories(), flagSetsInvalid)
}

// subscribes listener
Expand Down Expand Up @@ -286,6 +288,7 @@ func setupInMemoryFactory(
) (*SplitFactory, error) {
advanced, warnings := conf.NormalizeSDKConf(cfg.Advanced)
printWarnings(logger, warnings)
flagSetsInvalid := int64(len(cfg.Advanced.FlagSetFilter) - len(advanced.FlagSetsFilter))
if strings.TrimSpace(cfg.SplitSyncProxyURL) != "" {
advanced.StreamingEnabled = false
}
Expand Down Expand Up @@ -380,7 +383,7 @@ func setupInMemoryFactory(
splitFactory.status.Store(sdkStatusInitializing)
setFactory(splitFactory.apikey, splitFactory.logger)

go splitFactory.initializationManager(readyChannel)
go splitFactory.initializationManager(readyChannel, flagSetsInvalid)

return &splitFactory, nil
}
Expand All @@ -402,6 +405,7 @@ func setupRedisFactory(apikey string, cfg *conf.SplitSdkConfig, logger logging.L
impressionStorage := redis.NewImpressionStorage(redisClient, metadata, logger)

flagSets, errs := flagsets.SanitizeMany(cfg.Advanced.FlagSetFilter)
flagSetsInvalid := int64(len(cfg.Advanced.FlagSetFilter) - len(flagSets))
printWarnings(logger, errs)
flagSetFilter := flagsets.NewFlagSetFilter(flagSets)

Expand Down Expand Up @@ -456,7 +460,7 @@ func setupRedisFactory(apikey string, cfg *conf.SplitSdkConfig, logger logging.L
factory.status.Store(sdkStatusInitializing)
setFactory(factory.apikey, factory.logger)

factory.initializationRedis()
factory.initializationRedis(flagSetsInvalid)

return factory, nil
}
Expand All @@ -468,6 +472,7 @@ func setupLocalhostFactory(
metadata dtos.Metadata,
) (*SplitFactory, error) {
flagSets, errs := flagsets.SanitizeMany(cfg.Advanced.FlagSetFilter)
flagSetsInvalid := int64(len(cfg.Advanced.FlagSetFilter) - len(flagSets))
printWarnings(logger, errs)
flagSetFilter := flagsets.NewFlagSetFilter(flagSets)
splitStorage := mutexmap.NewMMSplitStorage(flagSetFilter)
Expand Down Expand Up @@ -542,7 +547,7 @@ func setupLocalhostFactory(
setFactory(splitFactory.apikey, splitFactory.logger)

// Call fetching tasks as goroutine
go splitFactory.initializationManager(readyChannel)
go splitFactory.initializationManager(readyChannel, flagSetsInvalid)

return splitFactory, nil
}
Expand Down

0 comments on commit 758be91

Please sign in to comment.