splitclient-rb 7.2.2.pre.rc1-java → 7.3.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/CHANGES.txt +10 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/splitclient-rb.rb +24 -9
- data/lib/splitclient-rb/cache/adapters/redis_adapter.rb +4 -0
- data/lib/splitclient-rb/cache/fetchers/segment_fetcher.rb +21 -9
- data/lib/splitclient-rb/cache/fetchers/split_fetcher.rb +10 -9
- data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +6 -3
- data/lib/splitclient-rb/cache/repositories/events_repository.rb +4 -3
- data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +8 -0
- data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +2 -0
- data/lib/splitclient-rb/cache/repositories/repository.rb +0 -4
- data/lib/splitclient-rb/cache/repositories/segments_repository.rb +20 -0
- data/lib/splitclient-rb/cache/repositories/splits_repository.rb +4 -0
- data/lib/splitclient-rb/cache/senders/localhost_repo_cleaner.rb +1 -3
- data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +9 -0
- data/lib/splitclient-rb/clients/split_client.rb +59 -25
- data/lib/splitclient-rb/constants.rb +6 -1
- data/lib/splitclient-rb/engine/api/client.rb +3 -2
- data/lib/splitclient-rb/engine/api/events.rb +10 -1
- data/lib/splitclient-rb/engine/api/impressions.rb +19 -2
- data/lib/splitclient-rb/engine/api/segments.rb +20 -18
- data/lib/splitclient-rb/engine/api/splits.rb +10 -10
- data/lib/splitclient-rb/engine/api/telemetry_api.rb +39 -0
- data/lib/splitclient-rb/engine/auth_api_client.rb +21 -8
- data/lib/splitclient-rb/engine/common/impressions_manager.rb +27 -3
- data/lib/splitclient-rb/engine/metrics/binary_search_latency_tracker.rb +3 -65
- data/lib/splitclient-rb/engine/push_manager.rb +12 -3
- data/lib/splitclient-rb/engine/sync_manager.rb +85 -46
- data/lib/splitclient-rb/engine/synchronizer.rb +14 -22
- data/lib/splitclient-rb/split_config.rb +46 -21
- data/lib/splitclient-rb/split_factory.rb +31 -13
- data/lib/splitclient-rb/split_factory_registry.rb +12 -0
- data/lib/splitclient-rb/sse/event_source/client.rb +53 -28
- data/lib/splitclient-rb/sse/event_source/event_parser.rb +10 -1
- data/lib/splitclient-rb/sse/notification_manager_keeper.rb +45 -26
- data/lib/splitclient-rb/sse/sse_handler.rb +16 -21
- data/lib/splitclient-rb/sse/workers/segments_worker.rb +5 -4
- data/lib/splitclient-rb/sse/workers/splits_worker.rb +6 -3
- data/lib/splitclient-rb/telemetry/domain/constants.rb +42 -0
- data/lib/splitclient-rb/telemetry/domain/structs.rb +31 -0
- data/lib/splitclient-rb/telemetry/evaluation_consumer.rb +14 -0
- data/lib/splitclient-rb/telemetry/evaluation_producer.rb +21 -0
- data/lib/splitclient-rb/telemetry/init_consumer.rb +14 -0
- data/lib/splitclient-rb/telemetry/init_producer.rb +19 -0
- data/lib/splitclient-rb/telemetry/memory/memory_evaluation_consumer.rb +32 -0
- data/lib/splitclient-rb/telemetry/memory/memory_evaluation_producer.rb +24 -0
- data/lib/splitclient-rb/telemetry/memory/memory_init_consumer.rb +28 -0
- data/lib/splitclient-rb/telemetry/memory/memory_init_producer.rb +34 -0
- data/lib/splitclient-rb/telemetry/memory/memory_runtime_consumer.rb +112 -0
- data/lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb +81 -0
- data/lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb +192 -0
- data/lib/splitclient-rb/telemetry/redis/redis_evaluation_producer.rb +38 -0
- data/lib/splitclient-rb/telemetry/redis/redis_init_producer.rb +37 -0
- data/lib/splitclient-rb/telemetry/redis/redis_synchronizer.rb +28 -0
- data/lib/splitclient-rb/telemetry/runtime_consumer.rb +24 -0
- data/lib/splitclient-rb/telemetry/runtime_producer.rb +24 -0
- data/lib/splitclient-rb/telemetry/storages/memory.rb +139 -0
- data/lib/splitclient-rb/telemetry/sync_task.rb +38 -0
- data/lib/splitclient-rb/telemetry/synchronizer.rb +29 -0
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +26 -11
- data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +0 -163
- data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +0 -131
- data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +0 -23
- data/lib/splitclient-rb/cache/senders/metrics_sender.rb +0 -55
- data/lib/splitclient-rb/engine/api/metrics.rb +0 -61
- data/lib/splitclient-rb/engine/metrics/metrics.rb +0 -80
- data/lib/splitclient-rb/redis_metrics_fixer.rb +0 -36
@@ -4,6 +4,8 @@ module SplitIoClient
|
|
4
4
|
module SSE
|
5
5
|
module EventSource
|
6
6
|
class EventParser
|
7
|
+
BAD_REQUEST_CODE = 400
|
8
|
+
|
7
9
|
def initialize(config)
|
8
10
|
@config = config
|
9
11
|
end
|
@@ -27,10 +29,17 @@ module SplitIoClient
|
|
27
29
|
|
28
30
|
events
|
29
31
|
rescue StandardError => e
|
30
|
-
@config.logger.
|
32
|
+
@config.logger.debug("Error during parsing a event: #{e.inspect}")
|
31
33
|
[]
|
32
34
|
end
|
33
35
|
|
36
|
+
def first_event(raw_data)
|
37
|
+
raw_data.split("\n")[0].split(' ')[1].to_i
|
38
|
+
rescue StandardError => e
|
39
|
+
@config.logger.debug("Error parsing first event: #{e.inspect}")
|
40
|
+
BAD_REQUEST_CODE
|
41
|
+
end
|
42
|
+
|
34
43
|
private
|
35
44
|
|
36
45
|
def parse_event_data(data, type)
|
@@ -1,14 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'concurrent
|
3
|
+
require 'concurrent'
|
4
4
|
|
5
5
|
module SplitIoClient
|
6
6
|
module SSE
|
7
7
|
class NotificationManagerKeeper
|
8
|
-
|
8
|
+
DISABLED = 0
|
9
|
+
ENABLED = 1
|
10
|
+
PAUSED = 2
|
11
|
+
|
12
|
+
def initialize(config, telemetry_runtime_producer)
|
9
13
|
@config = config
|
10
14
|
@publisher_available = Concurrent::AtomicBoolean.new(true)
|
11
|
-
@
|
15
|
+
@publishers_pri = Concurrent::AtomicFixnum.new
|
16
|
+
@publishers_sec = Concurrent::AtomicFixnum.new
|
17
|
+
@on = { action: ->(_) {} }
|
18
|
+
@telemetry_runtime_producer = telemetry_runtime_producer
|
12
19
|
|
13
20
|
yield self if block_given?
|
14
21
|
end
|
@@ -16,19 +23,16 @@ module SplitIoClient
|
|
16
23
|
def handle_incoming_occupancy_event(event)
|
17
24
|
if event.data['type'] == 'CONTROL'
|
18
25
|
process_event_control(event.data['controlType'])
|
19
|
-
|
20
|
-
process_event_occupancy(event.data['metrics']['publishers'])
|
26
|
+
else
|
27
|
+
process_event_occupancy(event.channel, event.data['metrics']['publishers'])
|
21
28
|
end
|
22
29
|
rescue StandardError => e
|
30
|
+
p e
|
23
31
|
@config.logger.error(e)
|
24
32
|
end
|
25
33
|
|
26
|
-
def
|
27
|
-
@on[:
|
28
|
-
end
|
29
|
-
|
30
|
-
def on_push_shutdown(&action)
|
31
|
-
@on[:push_shutdown] = action
|
34
|
+
def on_action(&action)
|
35
|
+
@on[:action] = action
|
32
36
|
end
|
33
37
|
|
34
38
|
private
|
@@ -36,35 +40,50 @@ module SplitIoClient
|
|
36
40
|
def process_event_control(type)
|
37
41
|
case type
|
38
42
|
when 'STREAMING_PAUSED'
|
39
|
-
|
43
|
+
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, PAUSED)
|
44
|
+
dispatch_action(Constants::PUSH_SUBSYSTEM_DOWN)
|
40
45
|
when 'STREAMING_RESUMED'
|
41
|
-
|
46
|
+
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, ENABLED)
|
47
|
+
dispatch_action(Constants::PUSH_SUBSYSTEM_READY) if @publisher_available.value
|
42
48
|
when 'STREAMING_DISABLED'
|
43
|
-
|
49
|
+
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, DISABLED)
|
50
|
+
dispatch_action(Constants::PUSH_SUBSYSTEM_OFF)
|
44
51
|
else
|
45
52
|
@config.logger.error("Incorrect event type: #{incoming_notification}")
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
49
|
-
def process_event_occupancy(publishers)
|
50
|
-
@config.logger.debug("
|
51
|
-
|
56
|
+
def process_event_occupancy(channel, publishers)
|
57
|
+
@config.logger.debug("Processed occupancy event with #{publishers} publishers. Channel: #{channel}")
|
58
|
+
|
59
|
+
update_publishers(channel, publishers)
|
60
|
+
|
61
|
+
if !are_publishers_available? && @publisher_available.value
|
52
62
|
@publisher_available.make_false
|
53
|
-
|
54
|
-
elsif
|
63
|
+
dispatch_action(Constants::PUSH_SUBSYSTEM_DOWN)
|
64
|
+
elsif are_publishers_available? && !@publisher_available.value
|
55
65
|
@publisher_available.make_true
|
56
|
-
|
66
|
+
dispatch_action(Constants::PUSH_SUBSYSTEM_READY)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_publishers(channel, publishers)
|
71
|
+
if channel == Constants::CONTROL_PRI
|
72
|
+
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::OCCUPANCY_PRI, publishers)
|
73
|
+
@publishers_pri.value = publishers
|
74
|
+
elsif channel == Constants::CONTROL_SEC
|
75
|
+
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::OCCUPANCY_SEC, publishers)
|
76
|
+
@publishers_sec.value = publishers
|
57
77
|
end
|
58
78
|
end
|
59
79
|
|
60
|
-
def
|
61
|
-
@
|
62
|
-
@on[:occupancy].call(push_enable)
|
80
|
+
def are_publishers_available?
|
81
|
+
@publishers_pri.value.positive? || @publishers_sec.value.positive?
|
63
82
|
end
|
64
83
|
|
65
|
-
def
|
66
|
-
@config.logger.debug(
|
67
|
-
@on[:
|
84
|
+
def dispatch_action(action)
|
85
|
+
@config.logger.debug("Dispatching action: #{action}")
|
86
|
+
@on[:action].call(action)
|
68
87
|
end
|
69
88
|
end
|
70
89
|
end
|
@@ -5,19 +5,22 @@ module SplitIoClient
|
|
5
5
|
class SSEHandler
|
6
6
|
attr_reader :sse_client
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(metadata,
|
9
|
+
synchronizer,
|
10
|
+
repositories,
|
11
|
+
notification_manager_keeper,
|
12
|
+
telemetry_runtime_producer)
|
13
|
+
@config = metadata[:config]
|
10
14
|
@notification_manager_keeper = notification_manager_keeper
|
11
|
-
@splits_worker = SplitIoClient::SSE::Workers::SplitsWorker.new(synchronizer, config,
|
12
|
-
@segments_worker = SplitIoClient::SSE::Workers::SegmentsWorker.new(synchronizer, config,
|
13
|
-
@notification_processor = SplitIoClient::SSE::NotificationProcessor.new(config, @splits_worker, @segments_worker)
|
14
|
-
@sse_client = SSE::EventSource::Client.new(@config) do |client|
|
15
|
+
@splits_worker = SplitIoClient::SSE::Workers::SplitsWorker.new(synchronizer, @config, repositories[:splits])
|
16
|
+
@segments_worker = SplitIoClient::SSE::Workers::SegmentsWorker.new(synchronizer, @config, repositories[:segments])
|
17
|
+
@notification_processor = SplitIoClient::SSE::NotificationProcessor.new(@config, @splits_worker, @segments_worker)
|
18
|
+
@sse_client = SSE::EventSource::Client.new(@config, metadata[:api_key], telemetry_runtime_producer) do |client|
|
15
19
|
client.on_event { |event| handle_incoming_message(event) }
|
16
|
-
client.
|
17
|
-
client.on_disconnect { |reconnect| process_disconnect(reconnect) }
|
20
|
+
client.on_action { |action| process_action(action) }
|
18
21
|
end
|
19
22
|
|
20
|
-
@on = {
|
23
|
+
@on = { action: ->(_) {} }
|
21
24
|
|
22
25
|
yield self if block_given?
|
23
26
|
end
|
@@ -48,22 +51,14 @@ module SplitIoClient
|
|
48
51
|
@segments_worker.stop
|
49
52
|
end
|
50
53
|
|
51
|
-
def
|
52
|
-
@on[:
|
53
|
-
end
|
54
|
-
|
55
|
-
def on_disconnect(&action)
|
56
|
-
@on[:disconnect] = action
|
57
|
-
end
|
58
|
-
|
59
|
-
def process_disconnect(reconnect)
|
60
|
-
@on[:disconnect].call(reconnect)
|
54
|
+
def on_action(&action)
|
55
|
+
@on[:action] = action
|
61
56
|
end
|
62
57
|
|
63
58
|
private
|
64
59
|
|
65
|
-
def
|
66
|
-
@on[:
|
60
|
+
def process_action(action)
|
61
|
+
@on[:action].call(action)
|
67
62
|
end
|
68
63
|
|
69
64
|
def handle_incoming_message(notification)
|
@@ -48,12 +48,13 @@ module SplitIoClient
|
|
48
48
|
def perform
|
49
49
|
while (item = @queue.pop)
|
50
50
|
segment_name = item[:segment_name]
|
51
|
-
|
52
|
-
|
51
|
+
cn = item[:change_number]
|
52
|
+
@config.logger.debug("SegmentsWorker change_number dequeue #{segment_name}, #{cn}")
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
attempt = 0
|
55
|
+
while cn > @segments_repository.get_change_number(segment_name).to_i && attempt <= Workers::MAX_RETRIES_ALLOWED
|
56
56
|
@synchronizer.fetch_segment(segment_name)
|
57
|
+
attempt += 1
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module SplitIoClient
|
4
4
|
module SSE
|
5
5
|
module Workers
|
6
|
+
MAX_RETRIES_ALLOWED = 10
|
7
|
+
|
6
8
|
class SplitsWorker
|
7
9
|
def initialize(synchronizer, config, splits_repository)
|
8
10
|
@synchronizer = synchronizer
|
@@ -59,11 +61,12 @@ module SplitIoClient
|
|
59
61
|
|
60
62
|
def perform
|
61
63
|
while (change_number = @queue.pop)
|
62
|
-
|
64
|
+
@config.logger.debug("SplitsWorker change_number dequeue #{change_number}")
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
+
attempt = 0
|
67
|
+
while change_number > @splits_repository.get_change_number.to_i && attempt <= Workers::MAX_RETRIES_ALLOWED
|
66
68
|
@synchronizer.fetch_splits
|
69
|
+
attempt += 1
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
module Domain
|
6
|
+
class Constants
|
7
|
+
BUR_TIMEOUT = 'bur_timeout'
|
8
|
+
NON_READY_USAGES = 'non_ready_usages'
|
9
|
+
|
10
|
+
IMPRESSIONS_DROPPED = 'impressions_dropped'
|
11
|
+
IMPRESSIONS_DEDUPE = 'impressions_deduped'
|
12
|
+
IMPRESSIONS_QUEUED = 'impressions_queued'
|
13
|
+
|
14
|
+
EVENTS_DROPPED = 'events_dropped'
|
15
|
+
EVENTS_QUEUED = 'events_queued'
|
16
|
+
|
17
|
+
SPLIT_SYNC = 'split_sync'
|
18
|
+
SEGMENT_SYNC = 'segment_sync'
|
19
|
+
IMPRESSIONS_SYNC = 'impressions_sync'
|
20
|
+
IMPRESSION_COUNT_SYNC = 'impression_count_sync'
|
21
|
+
EVENT_SYNC = 'event_sync'
|
22
|
+
TELEMETRY_SYNC = 'telemetry_sync'
|
23
|
+
TOKEN_SYNC = 'token_sync'
|
24
|
+
|
25
|
+
SSE_CONNECTION_ESTABLISHED = 0
|
26
|
+
OCCUPANCY_PRI = 10
|
27
|
+
OCCUPANCY_SEC = 20
|
28
|
+
STREAMING_STATUS = 30
|
29
|
+
CONNECTION_ERROR = 40
|
30
|
+
TOKEN_REFRESH = 50
|
31
|
+
ABLY_ERROR = 60
|
32
|
+
SYNC_MODE = 70
|
33
|
+
|
34
|
+
TREATMENT = 'treatment'
|
35
|
+
TREATMENTS = 'treatments'
|
36
|
+
TREATMENT_WITH_CONFIG = 'treatment_with_config'
|
37
|
+
TREATMENTS_WITH_CONFIG = 'treatments_with_config'
|
38
|
+
TRACK = 'track'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
# sp: splits, se: segments, im: impressions, ic:impression count, ev: events, te: telemetry, to: token.
|
6
|
+
LastSynchronization = Struct.new(:sp, :se, :im, :ic, :ev, :te, :to)
|
7
|
+
HttpErrors = Struct.new(:sp, :se, :im, :ic, :ev, :te, :to)
|
8
|
+
HttpLatencies = Struct.new(:sp, :se, :im, :ic, :ev, :te, :to)
|
9
|
+
|
10
|
+
# sp: splits, se: segmentos, im: impressions, ev: events, t: telemetry
|
11
|
+
Rates = Struct.new(:sp, :se, :im, :ev, :te)
|
12
|
+
|
13
|
+
# s: sdkUrl, e: eventsUrl, a: authUrl, st: streamUrl, t: telemetryUrl
|
14
|
+
UrlOverrides = Struct.new(:s, :e, :a, :st, :t)
|
15
|
+
|
16
|
+
# om: operationMode, se: streamingEnabled, st: storage, rr: refreshRate, uo: urlOverrides, iq: impressionsQueueSize,
|
17
|
+
# eq: eventsQueueSize, im: impressionsMode, il: impressionListenerEnabled, hp: httpProxyDetected, af: activeFactories,
|
18
|
+
# rf: redundantActiveFactories, tr: timeUntilSdkReady, bt: burTimeouts, nr: sdkNotReadyUsage, t: tags, i: integrations
|
19
|
+
ConfigInit = Struct.new(:om, :st, :af, :rf, :t, :se, :rr, :uo, :iq, :eq, :im, :il, :hp, :tr, :bt, :nr, :i)
|
20
|
+
|
21
|
+
# ls: lastSynchronization, ml: clientMethodLatencies, me: clientMethodExceptions, he: httpErros, hl: httpLatencies,
|
22
|
+
# tr: tokenRefreshes, ar: authRejections, iq: impressionsQueued, ide: impressionsDeduped, idr: impressionsDropped,
|
23
|
+
# spc: splitsCount, sec: segmentCount, skc: segmentKeyCount, sl: sessionLengthMs, eq: eventsQueued, ed: eventsDropped,
|
24
|
+
# se: streamingEvents, t: tags
|
25
|
+
Usage = Struct.new(:ls, :ml, :me, :he, :hl, :tr, :ar, :iq, :ide, :idr, :spc, :sec, :skc, :sl, :eq, :ed, :se, :t)
|
26
|
+
|
27
|
+
# t: treatment, ts: treatments, tc: treatmentWithConfig, tcs: treatmentsWithConfig, tr: track
|
28
|
+
ClientMethodLatencies = Struct.new(:t, :ts, :tc, :tcs, :tr)
|
29
|
+
ClientMethodExceptions = Struct.new(:t, :ts, :tc, :tcs, :tr)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
class EvaluationConsumer
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@evaluation, :pop_latencies, :pop_exceptions
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@evaluation = SplitIoClient::Telemetry::MemoryEvaluationConsumer.new(config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
class EvaluationProducer
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@evaluation,
|
8
|
+
:record_latency,
|
9
|
+
:record_exception
|
10
|
+
|
11
|
+
def initialize(config)
|
12
|
+
@evaluation = case config.telemetry_adapter.class.to_s
|
13
|
+
when 'SplitIoClient::Cache::Adapters::RedisAdapter'
|
14
|
+
SplitIoClient::Telemetry::RedisEvaluationProducer.new(config)
|
15
|
+
else
|
16
|
+
SplitIoClient::Telemetry::MemoryEvaluationProducer.new(config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
class InitConsumer
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@init, :non_ready_usages, :bur_timeouts
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@init = SplitIoClient::Telemetry::MemoryInitConsumer.new(config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
class InitProducer
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@init, :record_config, :record_non_ready_usages, :record_bur_timeout
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@init = case config.telemetry_adapter.class.to_s
|
11
|
+
when 'SplitIoClient::Cache::Adapters::RedisAdapter'
|
12
|
+
SplitIoClient::Telemetry::RedisInitProducer.new(config)
|
13
|
+
else
|
14
|
+
SplitIoClient::Telemetry::MemoryInitProducer.new(config)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
class MemoryEvaluationConsumer < EvaluationConsumer
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
@adapter = config.telemetry_adapter
|
9
|
+
end
|
10
|
+
|
11
|
+
def pop_latencies
|
12
|
+
to_return = @adapter.latencies.each_with_object({}) do |latency, memo|
|
13
|
+
memo[latency[:method]] = latency[:latencies]
|
14
|
+
end
|
15
|
+
|
16
|
+
@adapter.init_latencies
|
17
|
+
|
18
|
+
to_return
|
19
|
+
end
|
20
|
+
|
21
|
+
def pop_exceptions
|
22
|
+
to_return = @adapter.exceptions.each_with_object({}) do |exception, memo|
|
23
|
+
memo[exception[:method]] = exception[:exceptions].value
|
24
|
+
end
|
25
|
+
|
26
|
+
@adapter.init_exceptions
|
27
|
+
|
28
|
+
to_return
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SplitIoClient
|
4
|
+
module Telemetry
|
5
|
+
class MemoryEvaluationProducer < EvaluationProducer
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
@adapter = config.telemetry_adapter
|
9
|
+
end
|
10
|
+
|
11
|
+
def record_latency(method, bucket)
|
12
|
+
@adapter.latencies.find { |l| l[:method] == method }[:latencies][bucket] += 1
|
13
|
+
rescue StandardError => error
|
14
|
+
@config.log_found_exception(__method__.to_s, error)
|
15
|
+
end
|
16
|
+
|
17
|
+
def record_exception(method)
|
18
|
+
@adapter.exceptions.find { |l| l[:method] == method }[:exceptions].increment
|
19
|
+
rescue StandardError => error
|
20
|
+
@config.log_found_exception(__method__.to_s, error)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|