From 758be91d36f728dcc8116fd5a71c6d5b4b4e5539 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Thu, 16 Nov 2023 11:24:23 -0300 Subject: [PATCH] [SDKS-7683] Set init config telemetry with FlagSetsTotal and FlagSetsInvalid --- go.mod | 2 +- go.sum | 4 ++-- splitio/client/factory.go | 27 ++++++++++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index cd4331f..944fe4d 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 907f417..de223f6 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/splitio/client/factory.go b/splitio/client/factory.go index 48d35ed..3db2471 100644 --- a/splitio/client/factory.go +++ b/splitio/client/factory.go @@ -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{ @@ -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, @@ -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 { @@ -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 @@ -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 } @@ -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 } @@ -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) @@ -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 } @@ -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) @@ -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 }