diff --git a/lib/splitclient-rb/telemetry/domain/constants.rb b/lib/splitclient-rb/telemetry/domain/constants.rb index c3ad34eb..44113b80 100644 --- a/lib/splitclient-rb/telemetry/domain/constants.rb +++ b/lib/splitclient-rb/telemetry/domain/constants.rb @@ -35,6 +35,10 @@ class Constants TREATMENTS = 'treatments' TREATMENT_WITH_CONFIG = 'treatmentWithConfig' TREATMENTS_WITH_CONFIG = 'treatmentsWithConfig' + TREATMENTS_BY_FLAG_SET = 'treatmentsByFlagSet' + TREATMENTS_BY_FLAG_SETS = 'treatmentsByFlagSets' + TREATMENTS_WITH_CONFIG_BY_FLAG_SET = 'treatmentWithConfigByFlagSet' + TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = 'treatmentsWithConfigByFlagSets' TRACK = 'track' SPLITS = 'splits' diff --git a/lib/splitclient-rb/telemetry/domain/structs.rb b/lib/splitclient-rb/telemetry/domain/structs.rb index c2d8b9d9..ab4297c0 100644 --- a/lib/splitclient-rb/telemetry/domain/structs.rb +++ b/lib/splitclient-rb/telemetry/domain/structs.rb @@ -16,8 +16,8 @@ module Telemetry # om: operationMode, st: storage, af: activeFactories, rf: redundantActiveFactories, t: tags, se: streamingEnabled, # rr: refreshRate, uo: urlOverrides, iq: impressionsQueueSize, eq: eventsQueueSize, im: impressionsMode, # il: impressionListenerEnabled, hp: httpProxyDetected, tr: timeUntilSdkReady, bt: burTimeouts, - # nr: sdkNotReadyUsage, i: integrations - ConfigInit = Struct.new(:om, :st, :af, :rf, :t, :se, :rr, :uo, :iq, :eq, :im, :il, :hp, :tr, :bt, :nr, :i) + # nr: sdkNotReadyUsage, i: integrations, fsT: Total flagsets, fsI: Invalid flagsets + ConfigInit = Struct.new(:om, :st, :af, :rf, :t, :fsT, :fsI, :se, :rr, :uo, :iq, :eq, :im, :il, :hp, :tr, :bt, :nr, :i) # ls: lastSynchronization, ml: clientMethodLatencies, me: clientMethodExceptions, he: httpErros, hl: httpLatencies, # tr: tokenRefreshes, ar: authRejections, iq: impressionsQueued, ide: impressionsDeduped, idr: impressionsDropped, @@ -26,8 +26,8 @@ module Telemetry Usage = Struct.new(:ls, :ml, :me, :he, :hl, :tr, :ar, :iq, :ide, :idr, :spc, :sec, :skc, :sl, :eq, :ed, :se, :t, :ufs) # t: treatment, ts: treatments, tc: treatmentWithConfig, tcs: treatmentsWithConfig, tr: track - ClientMethodLatencies = Struct.new(:t, :ts, :tc, :tcs, :tr) - ClientMethodExceptions = Struct.new(:t, :ts, :tc, :tcs, :tr) + ClientMethodLatencies = Struct.new(:t, :ts, :tc, :tcs, :tf, :tfs, :tcf, :tcfs, :tr) + ClientMethodExceptions = Struct.new(:t, :ts, :tc, :tcs, :tf, :tfs, :tcf, :tcfs, :tr) # sp: splits UpdatesFromSSE = Struct.new(:sp) diff --git a/lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb b/lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb index 45df5c59..8129a34e 100644 --- a/lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb +++ b/lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb @@ -42,7 +42,7 @@ def synchronize_stats @config.log_found_exception(__method__.to_s, e) end - def synchronize_config(active_factories = nil, redundant_active_factories = nil, time_until_ready = nil) + def synchronize_config(active_factories = nil, redundant_active_factories = nil, time_until_ready = nil, flag_sets = nil, flag_sets_invalid = nil) rates = Rates.new(@config.features_refresh_rate, @config.segments_refresh_rate, @config.impressions_refresh_rate, @@ -64,6 +64,8 @@ def synchronize_config(active_factories = nil, redundant_active_factories = nil, active_factories, redundant_active_factories, @telemetry_runtime_consumer.pop_tags, + flag_sets, + flag_sets_invalid, @config.streaming_enabled, rates, url_overrides, @@ -113,7 +115,9 @@ def fornat_init_config(init) bT: init.bt, nR: init.nr, t: init.t, - i: init.i + i: init.i, + fsT: init.fsT, + fsI: init.fsI } end @@ -125,6 +129,10 @@ def format_stats(usage) ts: usage.ml[Telemetry::Domain::Constants::TREATMENTS], tc: usage.ml[Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG], tcs: usage.ml[Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG], + tf: usage.ml[Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET], + tfs: usage.ml[Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS], + tcf: usage.ml[Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET], + tcfs: usage.ml[Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS], tr: usage.ml[Telemetry::Domain::Constants::TRACK] }, mE: { @@ -132,6 +140,10 @@ def format_stats(usage) ts: usage.me[Telemetry::Domain::Constants::TREATMENTS], tc: usage.me[Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG], tcs: usage.me[Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG], + tf: usage.me[Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET], + tfs: usage.me[Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS], + tcf: usage.me[Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET], + tcfs: usage.me[Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS], tr: usage.me[Telemetry::Domain::Constants::TRACK] }, hE: { diff --git a/lib/splitclient-rb/telemetry/redis/redis_init_producer.rb b/lib/splitclient-rb/telemetry/redis/redis_init_producer.rb index 22f26fc3..a6f5a676 100644 --- a/lib/splitclient-rb/telemetry/redis/redis_init_producer.rb +++ b/lib/splitclient-rb/telemetry/redis/redis_init_producer.rb @@ -11,7 +11,7 @@ def initialize(config) def record_config(config_data) return if config_data.nil? - data = { t: { oM: config_data.om, st: config_data.st, aF: config_data.af, rF: config_data.rf, t: config_data.t } } + data = { t: { oM: config_data.om, st: config_data.st, aF: config_data.af, rF: config_data.rf, t: config_data.t, fsT: config_data.fsT, fsI: config_data.fsI } } field = "#{@config.language}-#{@config.version}/#{@config.machine_name}/#{@config.machine_ip}" @adapter.add_to_map(config_key, field, data.to_json) diff --git a/lib/splitclient-rb/telemetry/redis/redis_synchronizer.rb b/lib/splitclient-rb/telemetry/redis/redis_synchronizer.rb index 38f879f0..d70e0019 100644 --- a/lib/splitclient-rb/telemetry/redis/redis_synchronizer.rb +++ b/lib/splitclient-rb/telemetry/redis/redis_synchronizer.rb @@ -13,11 +13,11 @@ def synchronize_stats # No-op end - def synchronize_config(active_factories = nil, redundant_active_factories = nil, tags = nil) + def synchronize_config(active_factories = nil, redundant_active_factories = nil, tags = nil, flag_sets = nil, flag_sets_invalid = nil) active_factories ||= SplitIoClient.split_factory_registry.active_factories redundant_active_factories ||= SplitIoClient.split_factory_registry.redundant_active_factories - init_config = ConfigInit.new(@config.mode, 'redis', active_factories, redundant_active_factories, tags) + init_config = ConfigInit.new(@config.mode, 'redis', active_factories, redundant_active_factories, tags, flag_sets, flag_sets_invalid) @telemetry_init_producer.record_config(init_config) rescue StandardError => e diff --git a/lib/splitclient-rb/telemetry/storages/memory.rb b/lib/splitclient-rb/telemetry/storages/memory.rb index bbe243db..b7991258 100644 --- a/lib/splitclient-rb/telemetry/storages/memory.rb +++ b/lib/splitclient-rb/telemetry/storages/memory.rb @@ -44,6 +44,10 @@ def init_latencies @latencies << { method: Domain::Constants::TREATMENTS, latencies: Concurrent::Array.new(array_size, 0) } @latencies << { method: Domain::Constants::TREATMENT_WITH_CONFIG, latencies: Concurrent::Array.new(array_size, 0) } @latencies << { method: Domain::Constants::TREATMENTS_WITH_CONFIG, latencies: Concurrent::Array.new(array_size, 0) } + @latencies << { method: Domain::Constants::TREATMENTS_BY_FLAG_SET, latencies: Concurrent::Array.new(array_size, 0) } + @latencies << { method: Domain::Constants::TREATMENTS_BY_FLAG_SETS, latencies: Concurrent::Array.new(array_size, 0) } + @latencies << { method: Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET, latencies: Concurrent::Array.new(array_size, 0) } + @latencies << { method: Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, latencies: Concurrent::Array.new(array_size, 0) } @latencies << { method: Domain::Constants::TRACK, latencies: Concurrent::Array.new(array_size, 0) } end @@ -54,6 +58,10 @@ def init_exceptions @exceptions << { method: Domain::Constants::TREATMENTS, exceptions: Concurrent::AtomicFixnum.new(0) } @exceptions << { method: Domain::Constants::TREATMENT_WITH_CONFIG, exceptions: Concurrent::AtomicFixnum.new(0) } @exceptions << { method: Domain::Constants::TREATMENTS_WITH_CONFIG, exceptions: Concurrent::AtomicFixnum.new(0) } + @exceptions << { method: Domain::Constants::TREATMENTS_BY_FLAG_SET, exceptions: Concurrent::AtomicFixnum.new(0) } + @exceptions << { method: Domain::Constants::TREATMENTS_BY_FLAG_SETS, exceptions: Concurrent::AtomicFixnum.new(0) } + @exceptions << { method: Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET, exceptions: Concurrent::AtomicFixnum.new(0) } + @exceptions << { method: Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, exceptions: Concurrent::AtomicFixnum.new(0) } @exceptions << { method: Domain::Constants::TRACK, exceptions: Concurrent::AtomicFixnum.new(0) } end diff --git a/spec/telemetry/synchronizer_spec.rb b/spec/telemetry/synchronizer_spec.rb index 94b4e716..e40a2439 100644 --- a/spec/telemetry/synchronizer_spec.rb +++ b/spec/telemetry/synchronizer_spec.rb @@ -8,9 +8,9 @@ context 'Redis' do let(:config) { SplitIoClient::SplitConfig.new(logger: Logger.new(log), cache_adapter: :redis, mode: :consumer, redis_namespace: 'synch-test') } let(:adapter) { config.telemetry_adapter } - let(:init_producer) { SplitIoClient::Telemetry::InitProducer.new(config) } + let(:init_producer) { SplitIoClient::Telemetry::InitProducer.new(config) } let(:synchronizer) { SplitIoClient::Telemetry::Synchronizer.new(config, nil, init_producer, nil, nil) } - let(:config_key) { 'synch-test.SPLITIO.telemetry.init' } + let(:config_key) { 'synch-test.SPLITIO.telemetry.init' } it 'synchronize_config with data' do adapter.redis.del(config_key) @@ -42,11 +42,11 @@ let(:init_producer) { SplitIoClient::Telemetry::InitProducer.new(config) } let(:telemetry_api) { SplitIoClient::Api::TelemetryApi.new(config, api_key, runtime_producer) } let(:telemetry_consumers) { { init: init_consumer, runtime: runtime_consumer, evaluation: evaluation_consumer } } - let(:body_usage) { "{\"lS\":{\"sp\":111111222,\"se\":111111222,\"im\":111111222,\"ic\":111111222,\"ev\":111111222,\"te\":111111222,\"to\":111111222},\"mL\":{\"t\":[0,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ts\":[0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tc\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tr\":[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"mE\":{\"t\":2,\"ts\":1,\"tc\":1,\"tcs\":0,\"tr\":1},\"hE\":{\"sp\":{},\"se\":{\"400\":1},\"im\":{},\"ic\":{},\"ev\":{\"500\":2,\"501\":1},\"te\":{},\"to\":{}},\"hL\":{\"sp\":[0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"se\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"im\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ic\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ev\":[0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"te\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"to\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"tR\":1,\"aR\":1,\"iQ\":3,\"iDe\":1,\"iDr\":2,\"spC\":3,\"seC\":3,\"skC\":7,\"sL\":444555,\"eQ\":4,\"eD\":1,\"sE\":[{\"e\":50,\"d\":222222333,\"t\":222222333},{\"e\":70,\"d\":0,\"t\":222222333},{\"e\":70,\"d\":1,\"t\":222222333}],\"t\":[\"tag-1\",\"tag-2\"],\"ufs\":{\"sp\":5}}" } - let(:empty_body_usage) { "{\"lS\":{\"sp\":0,\"se\":0,\"im\":0,\"ic\":0,\"ev\":0,\"te\":0,\"to\":0},\"mL\":{\"t\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ts\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tc\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tr\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"mE\":{\"t\":0,\"ts\":0,\"tc\":0,\"tcs\":0,\"tr\":0},\"hE\":{\"sp\":{},\"se\":{},\"im\":{},\"ic\":{},\"ev\":{},\"te\":{},\"to\":{}},\"hL\":{\"sp\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"se\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"im\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ic\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ev\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"te\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"to\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"tR\":0,\"aR\":0,\"iQ\":0,\"iDe\":0,\"iDr\":0,\"spC\":0,\"seC\":0,\"skC\":0,\"sL\":0,\"eQ\":0,\"eD\":0,\"sE\":[],\"t\":[],\"ufs\":{\"sp\":0}}" } - let(:body_custom_config) { "{\"oM\":0,\"sE\":true,\"st\":\"memory\",\"rR\":{\"sp\":100,\"se\":110,\"im\":120,\"ev\":130,\"te\":140},\"iQ\":5000,\"eQ\":500,\"iM\":0,\"uO\":{\"s\":true,\"e\":true,\"a\":true,\"st\":false,\"t\":false},\"iL\":false,\"hP\":false,\"aF\":1,\"rF\":1,\"tR\":100,\"bT\":2,\"nR\":1,\"t\":[],\"i\":null}" } - let(:body_default_config) { "{\"oM\":0,\"sE\":true,\"st\":\"memory\",\"rR\":{\"sp\":60,\"se\":60,\"im\":300,\"ev\":60,\"te\":3600},\"iQ\":5000,\"eQ\":500,\"iM\":0,\"uO\":{\"s\":false,\"e\":false,\"a\":false,\"st\":false,\"t\":false},\"iL\":false,\"hP\":false,\"aF\":1,\"rF\":1,\"tR\":500,\"bT\":0,\"nR\":0,\"t\":[],\"i\":null}" } - let(:body_proxy_config) { "{\"oM\":0,\"sE\":true,\"st\":\"memory\",\"rR\":{\"sp\":60,\"se\":60,\"im\":300,\"ev\":60,\"te\":3600},\"iQ\":5000,\"eQ\":500,\"iM\":0,\"uO\":{\"s\":false,\"e\":false,\"a\":false,\"st\":false,\"t\":false},\"iL\":false,\"hP\":true,\"aF\":1,\"rF\":1,\"tR\":500,\"bT\":0,\"nR\":0,\"t\":[],\"i\":null}" } + let(:body_usage) { "{\"lS\":{\"sp\":111111222,\"se\":111111222,\"im\":111111222,\"ic\":111111222,\"ev\":111111222,\"te\":111111222,\"to\":111111222},\"mL\":{\"t\":[0,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ts\":[0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tc\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tf\":[0,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tfs\":[0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcf\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcfs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tr\":[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"mE\":{\"t\":2,\"ts\":1,\"tc\":1,\"tcs\":0,\"tf\":2,\"tfs\":1,\"tcf\":1,\"tcfs\":0,\"tr\":1},\"hE\":{\"sp\":{},\"se\":{\"400\":1},\"im\":{},\"ic\":{},\"ev\":{\"500\":2,\"501\":1},\"te\":{},\"to\":{}},\"hL\":{\"sp\":[0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"se\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"im\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ic\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ev\":[0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"te\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"to\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"tR\":1,\"aR\":1,\"iQ\":3,\"iDe\":1,\"iDr\":2,\"spC\":3,\"seC\":3,\"skC\":7,\"sL\":444555,\"eQ\":4,\"eD\":1,\"sE\":[{\"e\":50,\"d\":222222333,\"t\":222222333},{\"e\":70,\"d\":0,\"t\":222222333},{\"e\":70,\"d\":1,\"t\":222222333}],\"t\":[\"tag-1\",\"tag-2\"],\"ufs\":{\"sp\":5}}" } + let(:empty_body_usage) { "{\"lS\":{\"sp\":0,\"se\":0,\"im\":0,\"ic\":0,\"ev\":0,\"te\":0,\"to\":0},\"mL\":{\"t\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ts\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tc\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tf\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tfs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcf\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tcfs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"tr\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"mE\":{\"t\":0,\"ts\":0,\"tc\":0,\"tcs\":0,\"tf\":0,\"tfs\":0,\"tcf\":0,\"tcfs\":0,\"tr\":0},\"hE\":{\"sp\":{},\"se\":{},\"im\":{},\"ic\":{},\"ev\":{},\"te\":{},\"to\":{}},\"hL\":{\"sp\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"se\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"im\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ic\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"ev\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"te\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"to\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"tR\":0,\"aR\":0,\"iQ\":0,\"iDe\":0,\"iDr\":0,\"spC\":0,\"seC\":0,\"skC\":0,\"sL\":0,\"eQ\":0,\"eD\":0,\"sE\":[],\"t\":[],\"ufs\":{\"sp\":0}}" } + let(:body_custom_config) { "{\"oM\":0,\"sE\":true,\"st\":\"memory\",\"rR\":{\"sp\":100,\"se\":110,\"im\":120,\"ev\":130,\"te\":140},\"iQ\":5000,\"eQ\":500,\"iM\":0,\"uO\":{\"s\":true,\"e\":true,\"a\":true,\"st\":false,\"t\":false},\"iL\":false,\"hP\":false,\"aF\":1,\"rF\":1,\"tR\":100,\"bT\":2,\"nR\":1,\"t\":[],\"i\":null,\"fsT\":1,\"fsI\":0}" } + let(:body_default_config) { "{\"oM\":0,\"sE\":true,\"st\":\"memory\",\"rR\":{\"sp\":60,\"se\":60,\"im\":300,\"ev\":60,\"te\":3600},\"iQ\":5000,\"eQ\":500,\"iM\":0,\"uO\":{\"s\":false,\"e\":false,\"a\":false,\"st\":false,\"t\":false},\"iL\":false,\"hP\":false,\"aF\":1,\"rF\":1,\"tR\":500,\"bT\":0,\"nR\":0,\"t\":[],\"i\":null,\"fsT\":1,\"fsI\":0}" } + let(:body_proxy_config) { "{\"oM\":0,\"sE\":true,\"st\":\"memory\",\"rR\":{\"sp\":60,\"se\":60,\"im\":300,\"ev\":60,\"te\":3600},\"iQ\":5000,\"eQ\":500,\"iM\":0,\"uO\":{\"s\":false,\"e\":false,\"a\":false,\"st\":false,\"t\":false},\"iL\":false,\"hP\":true,\"aF\":1,\"rF\":1,\"tR\":500,\"bT\":0,\"nR\":0,\"t\":[],\"i\":null,\"fsT\":1,\"fsI\":0}" } context 'synchronize_stats' do before do @@ -111,12 +111,22 @@ evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT, 1) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS, 2) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS, 3) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 1) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 3) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 2) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 1) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS, 2) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS, 3) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TRACK, 3) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TRACK) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET) synchronizer.synchronize_stats @@ -136,10 +146,10 @@ before do stub_request(:post, 'https://telemetry.split.io/api/v1/metrics/config') .to_return(status: 200, body: 'ok') - + SplitIoClient.load_factory_registry end - + it 'with custom data' do config.features_refresh_rate = 100 config.segments_refresh_rate = 110 @@ -160,7 +170,7 @@ { splits: splits_repository, segments: segments_repository }, telemetry_api) - synchronizer.synchronize_config(1, 1, 100) + synchronizer.synchronize_config(1, 1, 100, 1, 0) expect(a_request(:post, 'https://telemetry.split.io/api/v1/metrics/config') .with(body: body_custom_config)).to have_been_made @@ -172,14 +182,14 @@ init_producer, { splits: splits_repository, segments: segments_repository }, telemetry_api) - - synchronizer.synchronize_config(1, 1, 500) - + + synchronizer.synchronize_config(1, 1, 500, 1, 0) + expect(a_request(:post, 'https://telemetry.split.io/api/v1/metrics/config') .with(body: body_default_config)).to have_been_made end - it 'with proxy' do + it 'with proxy' do ENV['HTTPS_PROXY'] = 'https://proxy.test.io/api/v1/metrics/config' synchronizer = SplitIoClient::Telemetry::Synchronizer.new(config, @@ -188,7 +198,7 @@ { splits: splits_repository, segments: segments_repository }, telemetry_api) - synchronizer.synchronize_config(1, 1, 500) + synchronizer.synchronize_config(1, 1, 500, 1, 0) expect(a_request(:post, 'https://telemetry.split.io/api/v1/metrics/config') .with(body: body_proxy_config)).to have_been_made diff --git a/spec/telemetry/telemetry_evaluation_spec.rb b/spec/telemetry/telemetry_evaluation_spec.rb index 6fc52e5c..dbd96f35 100644 --- a/spec/telemetry/telemetry_evaluation_spec.rb +++ b/spec/telemetry/telemetry_evaluation_spec.rb @@ -12,64 +12,95 @@ it 'record and pop latencies' do latencies = evaluation_consumer.pop_latencies - expect(latencies.length).to eq(5) + expect(latencies.length).to eq(9) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TRACK].length).to eq(23) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT, 1) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT, 2) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS, 3) evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG, 4) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 3) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS, 2) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 1) + evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, 5) latencies = evaluation_consumer.pop_latencies - expect(latencies.length).to eq(5) + expect(latencies.length).to eq(9) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT][1]).to eq(1) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT][2]).to eq(1) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS][3]).to eq(1) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG][4]).to eq(1) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET][3]).to eq(1) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS][2]).to eq(1) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET][1]).to eq(1) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS][5]).to eq(1) latencies = evaluation_consumer.pop_latencies - expect(latencies.length).to eq(5) + expect(latencies.length).to eq(9) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET].length).to eq(23) + expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS].length).to eq(23) expect(latencies[SplitIoClient::Telemetry::Domain::Constants::TRACK].length).to eq(23) end it 'record and pop exceptions' do exceptions = evaluation_consumer.pop_exceptions - expect(exceptions.length).to eq(5) + expect(exceptions.length).to eq(9) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENT]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TRACK]).to eq(0) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT) evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS) + evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET) exceptions = evaluation_consumer.pop_exceptions - expect(exceptions.length).to eq(5) + expect(exceptions.length).to eq(9) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENT]).to eq(2) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS]).to eq(1) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET]).to eq(1) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS]).to eq(1) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET]).to eq(1) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TRACK]).to eq(0) exceptions = evaluation_consumer.pop_exceptions - expect(exceptions.length).to eq(5) + expect(exceptions.length).to eq(9) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENT]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET]).to eq(0) + expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS]).to eq(0) expect(exceptions[SplitIoClient::Telemetry::Domain::Constants::TRACK]).to eq(0) end end @@ -92,11 +123,18 @@ expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS, 4444)).to eq(1) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG, 222)).to eq(1) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG, 2)).to eq(1) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 2123)).to eq(1) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS, 25555)).to eq(1) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 24444)).to eq(1) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, 22)).to eq(1) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TRACK, 3)).to eq(1) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT, 123)).to eq(2) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT, 5555)).to eq(2) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS, 4444)).to eq(2) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET, 2123)).to eq(2) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS, 25555)).to eq(2) + expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 24444)).to eq(2) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG, 222)).to eq(2) expect(evaluation_producer.record_latency(SplitIoClient::Telemetry::Domain::Constants::TREATMENT, 123)).to eq(3) @@ -108,6 +146,10 @@ expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatments/4444").to_i).to eq(3) expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatmentWithConfig/222").to_i).to eq(3) expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatmentsWithConfig/2").to_i).to eq(1) + expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatmentsByFlagSet/2123").to_i).to eq(2) + expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatmentsByFlagSets/25555").to_i).to eq(2) + expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatmentWithConfigByFlagSet/24444").to_i).to eq(2) + expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/treatmentsWithConfigByFlagSets/22").to_i).to eq(1) expect(adapter.redis.hget(latency_key, "#{sdk_version}/#{name}/#{ip}/track/3").to_i).to eq(1) end @@ -122,12 +164,22 @@ expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT)).to eq(3) expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENT_WITH_CONFIG)).to eq(1) expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG)).to eq(1) + expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET)).to eq(1) + expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SET)).to eq(2) + expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_BY_FLAG_SETS)).to eq(1) + expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SET)).to eq(1) + expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS)).to eq(1) + expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TREATMENTS_WITH_CONFIG_BY_FLAG_SETS)).to eq(2) expect(evaluation_producer.record_exception(SplitIoClient::Telemetry::Domain::Constants::TRACK)).to eq(1) expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatment").to_i).to eq(3) expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatments").to_i).to eq(3) expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatmentWithConfig").to_i).to eq(1) expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatmentsWithConfig").to_i).to eq(1) + expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatmentsByFlagSet").to_i).to eq(2) + expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatmentsByFlagSets").to_i).to eq(1) + expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatmentWithConfigByFlagSet").to_i).to eq(1) + expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/treatmentsWithConfigByFlagSets").to_i).to eq(2) expect(adapter.redis.hget(exception_key, "#{sdk_version}/#{name}/#{ip}/track").to_i).to eq(1) end end diff --git a/spec/telemetry/telemetry_init_spec.rb b/spec/telemetry/telemetry_init_spec.rb index 95181439..333d7df3 100644 --- a/spec/telemetry/telemetry_init_spec.rb +++ b/spec/telemetry/telemetry_init_spec.rb @@ -61,7 +61,7 @@ it 'record config_init' do adapter.redis.del(telemetry_config_key) - config_init = SplitIoClient::Telemetry::ConfigInit.new('CONSUMER', 'REDIS', 1, 0, %w[t1 t2]) + config_init = SplitIoClient::Telemetry::ConfigInit.new('CONSUMER', 'REDIS', 1, 0, %w[t1 t2], 1, 0) init_producer.record_config(config_init) @@ -73,6 +73,8 @@ expect(result[:t][:aF]).to eq(1) expect(result[:t][:rF]).to eq(0) expect(result[:t][:t]).to eq(%w[t1 t2]) + expect(result[:t][:fsT]).to eq(1) + expect(result[:t][:fsI]).to eq(0) adapter.redis.del(telemetry_config_key) end