splitclient-rb 7.2.3-java → 7.3.0.pre.rc3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -0
  3. data/lib/splitclient-rb.rb +24 -9
  4. data/lib/splitclient-rb/cache/adapters/redis_adapter.rb +4 -0
  5. data/lib/splitclient-rb/cache/fetchers/segment_fetcher.rb +13 -9
  6. data/lib/splitclient-rb/cache/fetchers/split_fetcher.rb +8 -7
  7. data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +6 -3
  8. data/lib/splitclient-rb/cache/repositories/events_repository.rb +4 -3
  9. data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +8 -0
  10. data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +2 -0
  11. data/lib/splitclient-rb/cache/repositories/repository.rb +0 -4
  12. data/lib/splitclient-rb/cache/repositories/segments_repository.rb +20 -0
  13. data/lib/splitclient-rb/cache/repositories/splits_repository.rb +4 -0
  14. data/lib/splitclient-rb/cache/senders/localhost_repo_cleaner.rb +1 -3
  15. data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +9 -0
  16. data/lib/splitclient-rb/clients/split_client.rb +59 -25
  17. data/lib/splitclient-rb/engine/api/client.rb +3 -2
  18. data/lib/splitclient-rb/engine/api/events.rb +10 -1
  19. data/lib/splitclient-rb/engine/api/impressions.rb +19 -2
  20. data/lib/splitclient-rb/engine/api/segments.rb +20 -18
  21. data/lib/splitclient-rb/engine/api/splits.rb +10 -10
  22. data/lib/splitclient-rb/engine/api/telemetry_api.rb +39 -0
  23. data/lib/splitclient-rb/engine/auth_api_client.rb +21 -8
  24. data/lib/splitclient-rb/engine/common/impressions_manager.rb +27 -3
  25. data/lib/splitclient-rb/engine/metrics/binary_search_latency_tracker.rb +3 -65
  26. data/lib/splitclient-rb/engine/push_manager.rb +10 -2
  27. data/lib/splitclient-rb/engine/sync_manager.rb +42 -20
  28. data/lib/splitclient-rb/engine/synchronizer.rb +13 -12
  29. data/lib/splitclient-rb/split_config.rb +46 -21
  30. data/lib/splitclient-rb/split_factory.rb +31 -13
  31. data/lib/splitclient-rb/split_factory_registry.rb +12 -0
  32. data/lib/splitclient-rb/sse/event_source/client.rb +10 -1
  33. data/lib/splitclient-rb/sse/notification_manager_keeper.rb +17 -3
  34. data/lib/splitclient-rb/sse/sse_handler.rb +10 -6
  35. data/lib/splitclient-rb/telemetry/domain/constants.rb +42 -0
  36. data/lib/splitclient-rb/telemetry/domain/structs.rb +31 -0
  37. data/lib/splitclient-rb/telemetry/evaluation_consumer.rb +14 -0
  38. data/lib/splitclient-rb/telemetry/evaluation_producer.rb +21 -0
  39. data/lib/splitclient-rb/telemetry/init_consumer.rb +14 -0
  40. data/lib/splitclient-rb/telemetry/init_producer.rb +19 -0
  41. data/lib/splitclient-rb/telemetry/memory/memory_evaluation_consumer.rb +32 -0
  42. data/lib/splitclient-rb/telemetry/memory/memory_evaluation_producer.rb +24 -0
  43. data/lib/splitclient-rb/telemetry/memory/memory_init_consumer.rb +28 -0
  44. data/lib/splitclient-rb/telemetry/memory/memory_init_producer.rb +34 -0
  45. data/lib/splitclient-rb/telemetry/memory/memory_runtime_consumer.rb +112 -0
  46. data/lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb +81 -0
  47. data/lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb +192 -0
  48. data/lib/splitclient-rb/telemetry/redis/redis_evaluation_producer.rb +38 -0
  49. data/lib/splitclient-rb/telemetry/redis/redis_init_producer.rb +37 -0
  50. data/lib/splitclient-rb/telemetry/redis/redis_synchronizer.rb +28 -0
  51. data/lib/splitclient-rb/telemetry/runtime_consumer.rb +24 -0
  52. data/lib/splitclient-rb/telemetry/runtime_producer.rb +24 -0
  53. data/lib/splitclient-rb/telemetry/storages/memory.rb +139 -0
  54. data/lib/splitclient-rb/telemetry/sync_task.rb +38 -0
  55. data/lib/splitclient-rb/telemetry/synchronizer.rb +29 -0
  56. data/lib/splitclient-rb/version.rb +1 -1
  57. metadata +26 -11
  58. data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +0 -163
  59. data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +0 -131
  60. data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +0 -23
  61. data/lib/splitclient-rb/cache/senders/metrics_sender.rb +0 -55
  62. data/lib/splitclient-rb/engine/api/metrics.rb +0 -61
  63. data/lib/splitclient-rb/engine/metrics/metrics.rb +0 -80
  64. data/lib/splitclient-rb/redis_metrics_fixer.rb +0 -36
@@ -4,11 +4,12 @@ module SplitIoClient
4
4
  module Engine
5
5
  module Common
6
6
  class ImpressionManager
7
- def initialize(config, impressions_repository, impression_counter)
7
+ def initialize(config, impressions_repository, impression_counter, telemetry_runtime_producer)
8
8
  @config = config
9
9
  @impressions_repository = impressions_repository
10
10
  @impression_counter = impression_counter
11
11
  @impression_observer = SplitIoClient::Observers::ImpressionObserver.new
12
+ @telemetry_runtime_producer = telemetry_runtime_producer
12
13
  end
13
14
 
14
15
  # added param time for test
@@ -29,18 +30,41 @@ module SplitIoClient
29
30
 
30
31
  impression_router.add_bulk(impressions)
31
32
 
33
+ dropped = 0
34
+ queued = 0
35
+ dedupe = 0
36
+
32
37
  if optimized? && !redis?
33
38
  optimized_impressions = impressions.select { |imp| should_queue_impression?(imp[:i]) }
34
- @impressions_repository.add_bulk(optimized_impressions)
39
+
40
+ unless optimized_impressions.empty?
41
+ dropped = @impressions_repository.add_bulk(optimized_impressions)
42
+ dedupe = impressions.length - optimized_impressions.length
43
+ queued = optimized_impressions.length - dropped
44
+ end
35
45
  else
36
- @impressions_repository.add_bulk(impressions)
46
+ dropped = @impressions_repository.add_bulk(impressions)
47
+ queued = impressions.length - dropped
37
48
  end
49
+
50
+ record_stats(queued, dropped, dedupe)
38
51
  rescue StandardError => error
39
52
  @config.log_found_exception(__method__.to_s, error)
40
53
  end
41
54
 
42
55
  private
43
56
 
57
+ def record_stats(queued, dropped, dedupe)
58
+ return if redis?
59
+
60
+ imp_queued = Telemetry::Domain::Constants::IMPRESSIONS_QUEUED
61
+ imp_dropped = Telemetry::Domain::Constants::IMPRESSIONS_DROPPED
62
+ imp_dedupe = Telemetry::Domain::Constants::IMPRESSIONS_DEDUPE
63
+ @telemetry_runtime_producer.record_impressions_stats(imp_queued, queued) unless queued.zero?
64
+ @telemetry_runtime_producer.record_impressions_stats(imp_dropped, dropped) unless dropped.zero?
65
+ @telemetry_runtime_producer.record_impressions_stats(imp_dedupe, dedupe) unless dedupe.zero?
66
+ end
67
+
44
68
  # added param time for test
45
69
  def impression_data(matching_key, bucketing_key, split_name, treatment, time = nil)
46
70
  {
@@ -42,75 +42,13 @@ module SplitIoClient
42
42
 
43
43
  MAX_LATENCY = 7481828
44
44
 
45
- attr_accessor :latencies
46
-
47
- def initialize
48
- @latencies = Array.new(BUCKETS.length, 0)
49
- end
50
-
51
- #
52
- # Increment the internal counter for the bucket this latency falls into.
53
- # @param millis
54
- #
55
- def add_latency_millis(millis, return_index = false)
56
- index = find_bucket_index(millis * 1000)
57
-
58
- return index if return_index
59
-
60
- @latencies[index] += 1
61
- @latencies
62
- end
63
-
64
- # Increment the internal counter for the bucket this latency falls into.
65
- # @param micros
66
- def add_latency_micros(micros, return_index = false)
67
- index = find_bucket_index(micros)
68
-
69
- return index if return_index
70
-
71
- @latencies[index] += 1
72
- @latencies
73
- end
74
-
75
- # Returns the list of latencies buckets as an array.
76
- #
77
- #
78
- # @return the list of latencies buckets as an array.
79
- def get_latencies
80
- @latencies
81
- end
82
-
83
- def get_latency(index)
84
- return @latencies[index]
85
- end
86
-
87
- def clear
88
- @latencies = Array.new(BUCKETS.length, 0)
89
- end
90
-
91
- #
92
- # Returns the counts in the bucket this latency falls into.
93
- # The latencies will not be updated.
94
- # @param latency
95
- # @return the bucket content for the latency.
96
- #
97
- def get_bucket_for_latency_millis(latency)
98
- return @latencies[find_bucket_index(latency * 1000)]
99
- end
100
-
101
- #
102
- # Returns the counts in the bucket this latency falls into.
103
- # The latencies will not be updated.
104
- # @param latency
105
- # @return the bucket content for the latency.
106
- #
107
- def get_bucket_for_latency_micros(latency)
108
- return @latencies[find_bucket_index(latency)]
45
+ def self.get_bucket(latency)
46
+ return find_bucket_index(latency * 1000)
109
47
  end
110
48
 
111
49
  private
112
50
 
113
- def find_bucket_index(micros)
51
+ def self.find_bucket_index(micros)
114
52
  if (micros > MAX_LATENCY) then
115
53
  return BUCKETS.length - 1
116
54
  end
@@ -3,12 +3,13 @@
3
3
  module SplitIoClient
4
4
  module Engine
5
5
  class PushManager
6
- def initialize(config, sse_handler, api_key)
6
+ def initialize(config, sse_handler, api_key, telemetry_runtime_producer)
7
7
  @config = config
8
8
  @sse_handler = sse_handler
9
- @auth_api_client = AuthApiClient.new(@config)
9
+ @auth_api_client = AuthApiClient.new(@config, telemetry_runtime_producer)
10
10
  @api_key = api_key
11
11
  @back_off = SplitIoClient::SSE::EventSource::BackOff.new(@config.auth_retry_back_off_base, 1)
12
+ @telemetry_runtime_producer = telemetry_runtime_producer
12
13
  end
13
14
 
14
15
  def start_sse
@@ -19,6 +20,8 @@ module SplitIoClient
19
20
  if response[:push_enabled] && @sse_handler.start(response[:token], response[:channels])
20
21
  schedule_next_token_refresh(response[:exp])
21
22
  @back_off.reset
23
+ record_telemetry(response[:exp])
24
+
22
25
  return true
23
26
  end
24
27
 
@@ -51,6 +54,11 @@ module SplitIoClient
51
54
  end
52
55
  end
53
56
  end
57
+
58
+ def record_telemetry(time)
59
+ data = (Time.now.to_f * 1000.0).to_i + (time * 1000.0).to_i
60
+ @telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::TOKEN_REFRESH, data)
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -3,29 +3,38 @@
3
3
  module SplitIoClient
4
4
  module Engine
5
5
  class SyncManager
6
+ SYNC_MODE_STREAMING = 0
7
+ SYNC_MODE_POLLING = 1
8
+
6
9
  def initialize(
7
10
  repositories,
8
11
  api_key,
9
12
  config,
10
- synchronizer
13
+ synchronizer,
14
+ telemetry_runtime_producer,
15
+ sdk_blocker,
16
+ telemetry_synchronizer
11
17
  )
12
18
  @synchronizer = synchronizer
13
- notification_manager_keeper = SplitIoClient::SSE::NotificationManagerKeeper.new(config) do |manager|
19
+ notification_manager_keeper = SSE::NotificationManagerKeeper.new(config, telemetry_runtime_producer) do |manager|
14
20
  manager.on_action { |action| process_action(action) }
15
21
  end
16
- @sse_handler = SplitIoClient::SSE::SSEHandler.new(
17
- config,
22
+ @sse_handler = SSE::SSEHandler.new(
23
+ { config: config, api_key: api_key },
18
24
  @synchronizer,
19
- repositories[:splits],
20
- repositories[:segments],
21
- notification_manager_keeper
25
+ repositories,
26
+ notification_manager_keeper,
27
+ telemetry_runtime_producer
22
28
  ) do |handler|
23
29
  handler.on_action { |action| process_action(action) }
24
30
  end
25
31
 
26
- @push_manager = PushManager.new(config, @sse_handler, api_key)
32
+ @push_manager = PushManager.new(config, @sse_handler, api_key, telemetry_runtime_producer)
27
33
  @sse_connected = Concurrent::AtomicBoolean.new(false)
28
34
  @config = config
35
+ @telemetry_runtime_producer = telemetry_runtime_producer
36
+ @sdk_blocker = sdk_blocker
37
+ @telemetry_synchronizer = telemetry_synchronizer
29
38
  end
30
39
 
31
40
  def start
@@ -35,6 +44,8 @@ module SplitIoClient
35
44
  elsif @config.standalone?
36
45
  start_poll
37
46
  end
47
+
48
+ synchronize_telemetry_config
38
49
  end
39
50
 
40
51
  private
@@ -42,7 +53,7 @@ module SplitIoClient
42
53
  # Starts tasks if stream is enabled.
43
54
  def start_stream
44
55
  @config.logger.debug('Starting push mode ...')
45
- sync_all_thread
56
+ @synchronizer.sync_all
46
57
  @synchronizer.start_periodic_data_recording
47
58
 
48
59
  start_sse_connection_thread
@@ -52,21 +63,11 @@ module SplitIoClient
52
63
  @config.logger.debug('Starting polling mode ...')
53
64
  @synchronizer.start_periodic_fetch
54
65
  @synchronizer.start_periodic_data_recording
66
+ record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
55
67
  rescue StandardError => e
56
68
  @config.logger.error("start_poll error : #{e.inspect}")
57
69
  end
58
70
 
59
- # Starts thread which fetch splits and segments once and trigger task to periodic data recording.
60
- def sync_all_thread
61
- @config.threads[:sync_manager_start_stream] = Thread.new do
62
- begin
63
- @synchronizer.sync_all
64
- rescue StandardError => e
65
- @config.logger.error("sync_all_thread error : #{e.inspect}")
66
- end
67
- end
68
- end
69
-
70
71
  # Starts thread which connect to sse and after that fetch splits and segments once.
71
72
  def start_sse_connection_thread
72
73
  @config.threads[:sync_manager_start_sse] = Thread.new do
@@ -108,17 +109,20 @@ module SplitIoClient
108
109
  @synchronizer.stop_periodic_fetch
109
110
  @synchronizer.sync_all
110
111
  @sse_handler.start_workers
112
+ record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_STREAMING)
111
113
  end
112
114
 
113
115
  def process_subsystem_down
114
116
  @sse_handler.stop_workers
115
117
  @synchronizer.start_periodic_fetch
118
+ record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
116
119
  end
117
120
 
118
121
  def process_push_shutdown
119
122
  @push_manager.stop_sse
120
123
  @sse_handler.stop_workers
121
124
  @synchronizer.start_periodic_fetch
125
+ record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
122
126
  rescue StandardError => e
123
127
  @config.logger.error("process_push_shutdown error: #{e.inspect}")
124
128
  end
@@ -133,6 +137,7 @@ module SplitIoClient
133
137
  @synchronizer.stop_periodic_fetch
134
138
  @synchronizer.sync_all
135
139
  @sse_handler.start_workers
140
+ record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_STREAMING)
136
141
  rescue StandardError => e
137
142
  @config.logger.error("process_connected error: #{e.inspect}")
138
143
  end
@@ -146,6 +151,7 @@ module SplitIoClient
146
151
  @sse_connected.make_false
147
152
  @sse_handler.stop_workers
148
153
  @synchronizer.start_periodic_fetch
154
+ record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
149
155
 
150
156
  if reconnect
151
157
  @synchronizer.sync_all
@@ -154,6 +160,22 @@ module SplitIoClient
154
160
  rescue StandardError => e
155
161
  @config.logger.error("process_disconnect error: #{e.inspect}")
156
162
  end
163
+
164
+ def record_telemetry(type, data)
165
+ @telemetry_runtime_producer.record_streaming_event(type, data)
166
+ end
167
+
168
+ def synchronize_telemetry_config
169
+ @config.threads[:telemetry_config_sender] = Thread.new do
170
+ begin
171
+ @sdk_blocker.wait_unitil_internal_ready unless @config.consumer?
172
+ @telemetry_synchronizer.synchronize_config
173
+ rescue SplitIoClient::SDKShutdownException
174
+ @telemetry_synchronizer.synchronize_config
175
+ @config.logger.info('Posting Telemetry config due to shutdown')
176
+ end
177
+ end
178
+ end
157
179
  end
158
180
  end
159
181
  end
@@ -6,6 +6,8 @@ module SplitIoClient
6
6
  include SplitIoClient::Cache::Fetchers
7
7
  include SplitIoClient::Cache::Senders
8
8
 
9
+ FORCE_CACHE_CONTROL_HEADERS = true
10
+
9
11
  def initialize(
10
12
  repositories,
11
13
  api_key,
@@ -16,30 +18,30 @@ module SplitIoClient
16
18
  @splits_repository = repositories[:splits]
17
19
  @segments_repository = repositories[:segments]
18
20
  @impressions_repository = repositories[:impressions]
19
- @metrics_repository = repositories[:metrics]
20
21
  @events_repository = repositories[:events]
21
22
  @api_key = api_key
22
23
  @config = config
23
24
  @sdk_blocker = sdk_blocker
24
25
  @split_fetcher = params[:split_fetcher]
25
26
  @segment_fetcher = params[:segment_fetcher]
26
- @impressions_api = SplitIoClient::Api::Impressions.new(@api_key, @config)
27
+ @impressions_api = SplitIoClient::Api::Impressions.new(@api_key, @config, params[:telemetry_runtime_producer])
27
28
  @impression_counter = params[:imp_counter]
29
+ @telemetry_synchronizer = params[:telemetry_synchronizer]
28
30
  end
29
31
 
30
32
  def sync_all
31
33
  @config.threads[:sync_all_thread] = Thread.new do
32
34
  @config.logger.debug('Synchronizing Splits and Segments ...') if @config.debug_enabled
33
35
  @split_fetcher.fetch_splits
34
- fetch_segments
36
+ @segment_fetcher.fetch_segments
35
37
  end
36
38
  end
37
39
 
38
40
  def start_periodic_data_recording
39
41
  impressions_sender
40
- metrics_sender
41
42
  events_sender
42
43
  impressions_count_sender
44
+ start_telemetry_sync_task
43
45
  end
44
46
 
45
47
  def start_periodic_fetch
@@ -53,12 +55,12 @@ module SplitIoClient
53
55
  end
54
56
 
55
57
  def fetch_splits
56
- segment_names = @split_fetcher.fetch_splits
57
- @segment_fetcher.fetch_segments_if_not_exists(segment_names) unless segment_names.empty?
58
+ segment_names = @split_fetcher.fetch_splits(FORCE_CACHE_CONTROL_HEADERS)
59
+ @segment_fetcher.fetch_segments_if_not_exists(segment_names, FORCE_CACHE_CONTROL_HEADERS) unless segment_names.empty?
58
60
  end
59
61
 
60
62
  def fetch_segment(name)
61
- @segment_fetcher.fetch_segment(name)
63
+ @segment_fetcher.fetch_segment(name, FORCE_CACHE_CONTROL_HEADERS)
62
64
  end
63
65
 
64
66
  private
@@ -72,11 +74,6 @@ module SplitIoClient
72
74
  ImpressionsSender.new(@impressions_repository, @config, @impressions_api).call
73
75
  end
74
76
 
75
- # Starts thread which loops constantly and sends metrics to the Split API
76
- def metrics_sender
77
- MetricsSender.new(@metrics_repository, @api_key, @config).call
78
- end
79
-
80
77
  # Starts thread which loops constantly and sends events to the Split API
81
78
  def events_sender
82
79
  EventsSender.new(@events_repository, @config).call
@@ -86,6 +83,10 @@ module SplitIoClient
86
83
  def impressions_count_sender
87
84
  ImpressionsCountSender.new(@config, @impression_counter, @impressions_api).call
88
85
  end
86
+
87
+ def start_telemetry_sync_task
88
+ Telemetry::SyncTask.new(@config, @telemetry_synchronizer).call
89
+ end
89
90
  end
90
91
  end
91
92
  end
@@ -17,7 +17,6 @@ module SplitIoClient
17
17
  # @option opts [Int] :connection_timeout (2) The connect timeout for network connections in seconds.
18
18
  # @option opts [Int] :features_refresh_rate The SDK polls Split servers for changes to feature roll-out plans. This parameter controls this polling period in seconds.
19
19
  # @option opts [Int] :segments_refresh_rate
20
- # @option opts [Int] :metrics_refresh_rate
21
20
  # @option opts [Int] :impressions_refresh_rate
22
21
  # @option opts [Object] :logger a logger to user for messages from the client. Defaults to stdout
23
22
  # @option opts [Boolean] :debug_enabled (false) The value for the debug flag
@@ -51,7 +50,6 @@ module SplitIoClient
51
50
  end
52
51
 
53
52
  @segments_refresh_rate = opts[:segments_refresh_rate] || SplitConfig.default_segments_refresh_rate
54
- @metrics_refresh_rate = opts[:metrics_refresh_rate] || SplitConfig.default_metrics_refresh_rate
55
53
 
56
54
  @impressions_mode = init_impressions_mode(opts[:impressions_mode])
57
55
 
@@ -63,10 +61,6 @@ module SplitIoClient
63
61
  #Safeguard for users of older SDK versions.
64
62
  @impressions_bulk_size = opts[:impressions_bulk_size] || @impressions_queue_size > 0 ? @impressions_queue_size : 0
65
63
 
66
- @metrics_adapter = SplitConfig.init_cache_adapter(
67
- opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter, nil, @redis_url
68
- )
69
-
70
64
  @debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug
71
65
  @transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug
72
66
  @block_until_ready = SplitConfig.default_block_until_ready
@@ -97,6 +91,10 @@ module SplitIoClient
97
91
  opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @events_queue_size, @redis_url
98
92
  )
99
93
 
94
+ @telemetry_adapter = SplitConfig.init_telemetry_adapter(
95
+ opts[:cache_adapter] || SplitConfig.default_cache_adapter, @redis_url
96
+ )
97
+
100
98
  @split_file = opts[:split_file] || SplitConfig.default_split_file
101
99
 
102
100
  @valid_mode = true
@@ -110,6 +108,11 @@ module SplitIoClient
110
108
  @auth_retry_back_off_base = SplitConfig.init_auth_retry_back_off(opts[:auth_retry_back_off_base] || SplitConfig.default_auth_retry_back_off_base)
111
109
  @streaming_reconnect_back_off_base = SplitConfig.init_streaming_reconnect_back_off(opts[:streaming_reconnect_back_off_base] || SplitConfig.default_streaming_reconnect_back_off_base)
112
110
 
111
+ @telemetry_refresh_rate = SplitConfig.init_telemetry_refresh_rate(opts[:telemetry_refresh_rate])
112
+ @telemetry_service_url = opts[:telemetry_service_url] || SplitConfig.default_telemetry_service_url
113
+
114
+ @sdk_start_time = Time.now
115
+
113
116
  startup_log
114
117
  end
115
118
 
@@ -148,12 +151,6 @@ module SplitIoClient
148
151
  # @return [Object] Impressions adapter instance
149
152
  attr_accessor :impressions_adapter
150
153
 
151
- #
152
- # The cache adapter to store metrics in
153
- #
154
- # @return [Symbol] Metrics adapter
155
- attr_accessor :metrics_adapter
156
-
157
154
  #
158
155
  # The cache adapter to store events in
159
156
  #
@@ -224,7 +221,6 @@ module SplitIoClient
224
221
 
225
222
  attr_accessor :features_refresh_rate
226
223
  attr_accessor :segments_refresh_rate
227
- attr_accessor :metrics_refresh_rate
228
224
  attr_accessor :impressions_refresh_rate
229
225
 
230
226
  attr_accessor :impression_listener
@@ -274,6 +270,14 @@ module SplitIoClient
274
270
 
275
271
  attr_accessor :impressions_mode
276
272
 
273
+ attr_accessor :telemetry_adapter
274
+
275
+ attr_accessor :telemetry_refresh_rate
276
+
277
+ attr_accessor :telemetry_service_url
278
+
279
+ attr_accessor :sdk_start_time
280
+
277
281
  def self.default_impressions_mode
278
282
  :optimized
279
283
  end
@@ -296,6 +300,12 @@ module SplitIoClient
296
300
  return refresh_rate.nil? || refresh_rate <= 0 ? SplitConfig.default_impressions_refresh_rate_optimized : [default_rate, refresh_rate].max
297
301
  end
298
302
 
303
+ def self.init_telemetry_refresh_rate(refresh_rate)
304
+ return SplitConfig.default_telemetry_refresh_rate if refresh_rate.nil? || refresh_rate < 60
305
+
306
+ refresh_rate
307
+ end
308
+
299
309
  def self.default_streaming_enabled
300
310
  true
301
311
  end
@@ -359,6 +369,21 @@ module SplitIoClient
359
369
  end
360
370
  end
361
371
 
372
+ def self.init_telemetry_adapter(adapter, redis_url)
373
+ case adapter
374
+ when :memory
375
+ Telemetry::Storages::Memory.new
376
+ when :redis
377
+ begin
378
+ require 'redis'
379
+ rescue LoadError
380
+ fail StandardError, 'To use Redis as a cache adapter you must include it in your Gemfile'
381
+ end
382
+
383
+ SplitIoClient::Cache::Adapters::RedisAdapter.new(redis_url)
384
+ end
385
+ end
386
+
362
387
  def self.map_memory_adapter(name, queue_size)
363
388
  case name
364
389
  when :map_adapter
@@ -377,10 +402,6 @@ module SplitIoClient
377
402
  :memory
378
403
  end
379
404
 
380
- def self.default_metrics_adapter
381
- :memory
382
- end
383
-
384
405
  #
385
406
  # The default read timeout value
386
407
  #
@@ -405,10 +426,6 @@ module SplitIoClient
405
426
  60
406
427
  end
407
428
 
408
- def self.default_metrics_refresh_rate
409
- 60
410
- end
411
-
412
429
  def self.default_impressions_refresh_rate
413
430
  60
414
431
  end
@@ -433,6 +450,14 @@ module SplitIoClient
433
450
  500
434
451
  end
435
452
 
453
+ def self.default_telemetry_refresh_rate
454
+ 3600
455
+ end
456
+
457
+ def self.default_telemetry_service_url
458
+ 'https://telemetry.split.io/api/v1'
459
+ end
460
+
436
461
  def self.default_split_file
437
462
  File.join(Dir.home, '.split')
438
463
  end