splitclient-rb 8.10.1.pre.rc1-java → 8.11.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.txt +10 -1
  3. data/LICENSE +169 -13
  4. data/NOTICE.txt +5 -0
  5. data/lib/splitclient-rb/cache/repositories/rule_based_segments_repository.rb +14 -1
  6. data/lib/splitclient-rb/cache/repositories/segments_repository.rb +13 -2
  7. data/lib/splitclient-rb/cache/repositories/splits_repository.rb +23 -1
  8. data/lib/splitclient-rb/clients/split_client.rb +12 -3
  9. data/lib/splitclient-rb/engine/api/faraday_middleware/gzip.rb +1 -0
  10. data/lib/splitclient-rb/engine/api/splits.rb +2 -2
  11. data/lib/splitclient-rb/engine/auth_api_client.rb +7 -3
  12. data/lib/splitclient-rb/engine/events/events_delivery.rb +20 -0
  13. data/lib/splitclient-rb/engine/events/events_manager.rb +194 -0
  14. data/lib/splitclient-rb/engine/events/events_manager_config.rb +96 -0
  15. data/lib/splitclient-rb/engine/events/events_task.rb +50 -0
  16. data/lib/splitclient-rb/engine/events/noop_events_queue.rb +13 -0
  17. data/lib/splitclient-rb/engine/matchers/rule_based_segment_matcher.rb +7 -4
  18. data/lib/splitclient-rb/engine/models/event_active_subscriptions.rb +14 -0
  19. data/lib/splitclient-rb/engine/models/events_metadata.rb +10 -0
  20. data/lib/splitclient-rb/engine/models/sdk_event.rb +4 -0
  21. data/lib/splitclient-rb/engine/models/sdk_event_type.rb +4 -0
  22. data/lib/splitclient-rb/engine/models/sdk_internal_event.rb +8 -0
  23. data/lib/splitclient-rb/engine/models/sdk_internal_event_notification.rb +16 -0
  24. data/lib/splitclient-rb/engine/models/valid_sdk_event.rb +14 -0
  25. data/lib/splitclient-rb/engine/status_manager.rb +7 -1
  26. data/lib/splitclient-rb/engine/sync_manager.rb +10 -6
  27. data/lib/splitclient-rb/split_factory.rb +20 -5
  28. data/lib/splitclient-rb/sse/event_source/client.rb +14 -15
  29. data/lib/splitclient-rb/sse/event_source/event_parser.rb +2 -2
  30. data/lib/splitclient-rb/sse/notification_manager_keeper.rb +3 -3
  31. data/lib/splitclient-rb/sse/workers/segments_worker.rb +4 -4
  32. data/lib/splitclient-rb/sse/workers/splits_worker.rb +9 -5
  33. data/lib/splitclient-rb/version.rb +1 -1
  34. data/lib/splitclient-rb.rb +12 -0
  35. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dead8f4d82b458d87a231e501465884b27ca84df17eca5937db97c0877f1004
4
- data.tar.gz: b8e7323a27d3b6c6bc84fcfcfced7403eae3e7f808b663499831f2de07c8c150
3
+ metadata.gz: dd598b2e9efb5540f5fb04f365b8f39cca8ded197ba8ff182a4335993f7e6d6e
4
+ data.tar.gz: '09b81db07f63a50e86450914abe2301bef42decfda218f8bce9a9077333040ba'
5
5
  SHA512:
6
- metadata.gz: 69a1975f20a1c45282c61bb9f6238b4274d304d658300ba8c6c69dfb1a0c553afbfdea0710ae1ea4c2bffad89b65ea2096648647d6e95f6ecfb2dc665b658bf8
7
- data.tar.gz: 652b6dea3e7ebe0dba65ff72282f011fe3c31163b88e44cab17afb2d3f41d73a1bc7b5cbe869dcc4e2362dcc523594ebf68809afeaa801c4cb66b1b525dec7ed
6
+ metadata.gz: 26ef8859967e564baf87ac4b045eb49eb2001faea6bc38e331a61c9df8d9ff03ad8f06dd226b677e85dc3e5d3c9b6b951b1f1f6abdc4f01f8b0d44bd8ace7f8c
7
+ data.tar.gz: baeef34eda98aefd67bd494e60f6fe7e866ea43cb17f1fa299b49800373d65e17611b979dd2fc60bd169f3c4659c6aebbc6e2dbe47c374002239e4c13111970e
data/CHANGES.txt CHANGED
@@ -1,7 +1,16 @@
1
1
  CHANGES
2
2
 
3
+ 8.11.0 (Mar, 12, 2026)
4
+ - Added the ability to listen to different events triggered by the SDK. Read more in our docs.
5
+ - SDK_UPDATE notify when a flag or user segment has changed
6
+ - SDK_READY notify when the SDK is ready to evaluate
7
+
8
+ 8.10.1 (Jan 28, 2025)
9
+ - Fixed rule-based segment matcher to exit when a conition is met.
10
+ - Fixed impressions properties format in redis mode.
11
+
3
12
  8.10.0 (Nov 28, 2025)
4
- - Replaced socketry gem used in streaming feature with built-in socket lib.
13
+ - Updated socketry gem used in streaming feature with built-in socket lib.
5
14
 
6
15
  8.9.0 (Oct 8, 2025)
7
16
  - Added new configuration for Fallback Treatments, which allows setting a treatment value and optional config to be returned in place of "control", either globally or by flag. Read more in our docs.
data/LICENSE CHANGED
@@ -1,13 +1,169 @@
1
- Copyright © 2025 Split Software, Inc.
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
5
+ 1. Definitions.
6
+ "License" shall mean the terms and conditions for use, reproduction,
7
+ and distribution as defined by Sections 1 through 9 of this document.
8
+ "Licensor" shall mean the copyright owner or entity authorized by
9
+ the copyright owner that is granting the License.
10
+ "Legal Entity" shall mean the union of the acting entity and all
11
+ other entities that control, are controlled by, or are under common
12
+ control with that entity. For the purposes of this definition,
13
+ "control" means (i) the power, direct or indirect, to cause the
14
+ direction or management of such entity, whether by contract or
15
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
16
+ outstanding shares, or (iii) beneficial ownership of such entity.
17
+ "You" (or "Your") shall mean an individual or Legal Entity
18
+ exercising permissions granted by this License.
19
+ "Source" form shall mean the preferred form for making modifications,
20
+ including but not limited to software source code, documentation
21
+ source, and configuration files.
22
+ "Object" form shall mean any form resulting from mechanical
23
+ transformation or translation of a Source form, including but
24
+ not limited to compiled object code, generated documentation,
25
+ and conversions to other media types.
26
+ "Work" shall mean the work of authorship, whether in Source or
27
+ Object form, made available under the License, as indicated by a
28
+ copyright notice that is included in or attached to the work
29
+ (an example is provided in the Appendix below).
30
+ "Derivative Works" shall mean any work, whether in Source or Object
31
+ form, that is based on (or derived from) the Work and for which the
32
+ editorial revisions, annotations, elaborations, or other modifications
33
+ represent, as a whole, an original work of authorship. For the purposes
34
+ of this License, Derivative Works shall not include works that remain
35
+ separable from, or merely link (or bind by name) to the interfaces of,
36
+ the Work and Derivative Works thereof.
37
+ "Contribution" shall mean any work of authorship, including
38
+ the original version of the Work and any modifications or additions
39
+ to that Work or Derivative Works thereof, that is intentionally
40
+ submitted to Licensor for inclusion in the Work by the copyright owner
41
+ or by an individual or Legal Entity authorized to submit on behalf of
42
+ the copyright owner. For the purposes of this definition, "submitted"
43
+ means any form of electronic, verbal, or written communication sent
44
+ to the Licensor or its representatives, including but not limited to
45
+ communication on electronic mailing lists, source code control systems,
46
+ and issue tracking systems that are managed by, or on behalf of, the
47
+ Licensor for the purpose of discussing and improving the Work, but
48
+ excluding communication that is conspicuously marked or otherwise
49
+ designated in writing by the copyright owner as "Not a Contribution."
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by Licensor and
52
+ subsequently incorporated within the Work.
53
+ 2. Grant of Copyright License. Subject to the terms and conditions of
54
+ this License, each Contributor hereby grants to You a perpetual,
55
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
56
+ copyright license to reproduce, prepare Derivative Works of,
57
+ publicly display, publicly perform, sublicense, and distribute the
58
+ Work and such Derivative Works in Source or Object form.
59
+ 3. Grant of Patent License. Subject to the terms and conditions of
60
+ this License, each Contributor hereby grants to You a perpetual,
61
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
62
+ (except as stated in this section) patent license to make, have made,
63
+ use, offer to sell, sell, import, and otherwise transfer the Work,
64
+ where such license applies only to those patent claims licensable
65
+ by such Contributor that are necessarily infringed by their
66
+ Contribution(s) alone or by combination of their Contribution(s)
67
+ with the Work to which such Contribution(s) was submitted. If You
68
+ institute patent litigation against any entity (including a
69
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
70
+ or a Contribution incorporated within the Work constitutes direct
71
+ or contributory patent infringement, then any patent licenses
72
+ granted to You under this License for that Work shall terminate
73
+ as of the date such litigation is filed.
74
+ 4. Redistribution. You may reproduce and distribute copies of the
75
+ Work or Derivative Works thereof in any medium, with or without
76
+ modifications, and in Source or Object form, provided that You
77
+ meet the following conditions:
78
+ (a) You must give any other recipients of the Work or
79
+ Derivative Works a copy of this License; and
80
+ (b) You must cause any modified files to carry prominent notices
81
+ stating that You changed the files; and
82
+ (c) You must retain, in the Source form of any Derivative Works
83
+ that You distribute, all copyright, patent, trademark, and
84
+ attribution notices from the Source form of the Work,
85
+ excluding those notices that do not pertain to any part of
86
+ the Derivative Works; and
87
+ (d) If the Work includes a "NOTICE" text file as part of its
88
+ distribution, then any Derivative Works that You distribute must
89
+ include a readable copy of the attribution notices contained
90
+ within such NOTICE file, excluding those notices that do not
91
+ pertain to any part of the Derivative Works, in at least one
92
+ of the following places: within a NOTICE text file distributed
93
+ as part of the Derivative Works; within the Source form or
94
+ documentation, if provided along with the Derivative Works; or,
95
+ within a display generated by the Derivative Works, if and
96
+ wherever such third-party notices normally appear. The contents
97
+ of the NOTICE file are for informational purposes only and
98
+ do not modify the License. You may add Your own attribution
99
+ notices within Derivative Works that You distribute, alongside
100
+ or as an addendum to the NOTICE text from the Work, provided
101
+ that such additional attribution notices cannot be construed
102
+ as modifying the License.
103
+ You may add Your own copyright statement to Your modifications and
104
+ may provide additional or different license terms and conditions
105
+ for use, reproduction, or distribution of Your modifications, or
106
+ for any such Derivative Works as a whole, provided Your use,
107
+ reproduction, and distribution of the Work otherwise complies with
108
+ the conditions stated in this License.
109
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
110
+ any Contribution intentionally submitted for inclusion in the Work
111
+ by You to the Licensor shall be under the terms and conditions of
112
+ this License, without any additional terms or conditions.
113
+ Notwithstanding the above, nothing herein shall supersede or modify
114
+ the terms of any separate license agreement you may have executed
115
+ with Licensor regarding such Contributions.
116
+ 6. Trademarks. This License does not grant permission to use the trade
117
+ names, trademarks, service marks, or product names of the Licensor,
118
+ except as required for reasonable and customary use in describing the
119
+ origin of the Work and reproducing the content of the NOTICE file.
120
+ 7. Disclaimer of Warranty. Unless required by applicable law or
121
+ agreed to in writing, Licensor provides the Work (and each
122
+ Contributor provides its Contributions) on an "AS IS" BASIS,
123
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
124
+ implied, including, without limitation, any warranties or conditions
125
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
126
+ PARTICULAR PURPOSE. You are solely responsible for determining the
127
+ appropriateness of using or redistributing the Work and assume any
128
+ risks associated with Your exercise of permissions under this License.
129
+ 8. Limitation of Liability. In no event and under no legal theory,
130
+ whether in tort (including negligence), contract, or otherwise,
131
+ unless required by applicable law (such as deliberate and grossly
132
+ negligent acts) or agreed to in writing, shall any Contributor be
133
+ liable to You for damages, including any direct, indirect, special,
134
+ incidental, or consequential damages of any character arising as a
135
+ result of this License or out of the use or inability to use the
136
+ Work (including but not limited to damages for loss of goodwill,
137
+ work stoppage, computer failure or malfunction, or any and all
138
+ other commercial damages or losses), even if such Contributor
139
+ has been advised of the possibility of such damages.
140
+ 9. Accepting Warranty or Additional Liability. While redistributing
141
+ the Work or Derivative Works thereof, You may choose to offer,
142
+ and charge a fee for, acceptance of support, warranty, indemnity,
143
+ or other liability obligations and/or rights consistent with this
144
+ License. However, in accepting such obligations, You may act only
145
+ on Your own behalf and on Your sole responsibility, not on behalf
146
+ of any other Contributor, and only if You agree to indemnify,
147
+ defend, and hold each Contributor harmless for any liability
148
+ incurred by, or claims asserted against, such Contributor by reason
149
+ of your accepting any such warranty or additional liability.
150
+ END OF TERMS AND CONDITIONS
151
+ APPENDIX: How to apply the Apache License to your work.
152
+ To apply the Apache License to your work, attach the following
153
+ boilerplate notice, with the fields enclosed by brackets "[]"
154
+ replaced with your own identifying information. (Don't include
155
+ the brackets!) The text should be enclosed in the appropriate
156
+ comment syntax for the file format. We also recommend that a
157
+ file or class name and description of purpose be included on the
158
+ same "printed page" as the copyright notice for easier
159
+ identification within third-party archives.
160
+ Copyright 2025 Harness Corporation
161
+ Licensed under the Apache License, Version 2.0 (the "License");
162
+ you may not use this file except in compliance with the License.
163
+ You may obtain a copy of the License at
164
+ http://www.apache.org/licenses/LICENSE-2.0
165
+ Unless required by applicable law or agreed to in writing, software
166
+ distributed under the License is distributed on an "AS IS" BASIS,
167
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
168
+ See the License for the specific language governing permissions and
169
+ limitations under the License.
data/NOTICE.txt ADDED
@@ -0,0 +1,5 @@
1
+ Harness Feature Management JavaScript SDK Copyright 2024-2026 Harness Inc.
2
+
3
+ This product includes software developed at Harness Inc. (https://harness.io/).
4
+
5
+ This product includes software originally developed by Split Software, Inc. (https://www.split.io/). Copyright 2016-2024 Split Software, Inc.
@@ -28,7 +28,7 @@ module SplitIoClient
28
28
  RB_SEGMENTS_PREFIX = '.rbsegment.'
29
29
  REGISTERED_PREFIX = '.segments.registered'
30
30
 
31
- def initialize(config)
31
+ def initialize(config, internal_events_queue)
32
32
  super(config)
33
33
  @adapter = case @config.cache_adapter.class.to_s
34
34
  when 'SplitIoClient::Cache::Adapters::RedisAdapter'
@@ -40,12 +40,25 @@ module SplitIoClient
40
40
  @adapter.set_string(namespace_key(TILL_PREFIX), '-1')
41
41
  @adapter.initialize_map(namespace_key(REGISTERED_PREFIX))
42
42
  end
43
+ @internal_events_queue = internal_events_queue
43
44
  end
44
45
 
45
46
  def update(to_add, to_delete, new_change_number)
46
47
  to_add.each{ |rule_based_segment| add_rule_based_segment(rule_based_segment) }
47
48
  to_delete.each{ |rule_based_segment| remove_rule_based_segment(rule_based_segment) }
48
49
  set_change_number(new_change_number)
50
+
51
+ if to_add.length > 0 || to_delete.length > 0
52
+ @internal_events_queue.push(
53
+ SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
54
+ SplitIoClient::Engine::Models::SdkInternalEvent::RB_SEGMENTS_UPDATED,
55
+ SplitIoClient::Engine::Models::EventsMetadata.new(
56
+ SplitIoClient::Engine::Models::SdkEventType::SEGMENTS_UPDATE,
57
+ []
58
+ )
59
+ )
60
+ )
61
+ end
49
62
  end
50
63
 
51
64
  def get_rule_based_segment(name)
@@ -6,7 +6,7 @@ module SplitIoClient
6
6
 
7
7
  attr_reader :adapter
8
8
 
9
- def initialize(config)
9
+ def initialize(config, internal_events_queue)
10
10
  super(config)
11
11
  @adapter = case @config.cache_adapter.class.to_s
12
12
  when 'SplitIoClient::Cache::Adapters::RedisAdapter'
@@ -15,6 +15,7 @@ module SplitIoClient
15
15
  @config.cache_adapter
16
16
  end
17
17
  @adapter.set_bool(namespace_key('.ready'), false) unless @config.mode.equal?(:consumer)
18
+ @internal_events_queue = internal_events_queue
18
19
  end
19
20
 
20
21
  # Receives segment data, adds and removes segements from the store
@@ -22,9 +23,19 @@ module SplitIoClient
22
23
  name = segment[:name]
23
24
 
24
25
  @adapter.initialize_set(segment_data(name)) unless @adapter.exists?(segment_data(name))
25
-
26
26
  add_keys(name, segment[:added])
27
27
  remove_keys(name, segment[:removed])
28
+ if segment[:added].length > 0 || segment[:removed].length > 0
29
+ @internal_events_queue.push(
30
+ SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
31
+ SplitIoClient::Engine::Models::SdkInternalEvent::SEGMENTS_UPDATED,
32
+ SplitIoClient::Engine::Models::EventsMetadata.new(
33
+ SplitIoClient::Engine::Models::SdkEventType::SEGMENTS_UPDATE,
34
+ []
35
+ )
36
+ )
37
+ )
38
+ end
28
39
  end
29
40
 
30
41
  def get_segment_keys(name)
@@ -35,7 +35,7 @@ module SplitIoClient
35
35
  SPLIT_PREFIX = '.split.'
36
36
  READY_PREFIX = '.splits.ready'
37
37
 
38
- def initialize(config, flag_sets_repository, flag_set_filter)
38
+ def initialize(config, flag_sets_repository, flag_set_filter, internal_events_queue)
39
39
  super(config)
40
40
  @tt_cache = {}
41
41
  @adapter = case @config.cache_adapter.class.to_s
@@ -46,6 +46,7 @@ module SplitIoClient
46
46
  end
47
47
  @flag_sets = flag_sets_repository
48
48
  @flag_set_filter = flag_set_filter
49
+ @internal_events_queue = internal_events_queue
49
50
  initialize_keys
50
51
  end
51
52
 
@@ -53,6 +54,18 @@ module SplitIoClient
53
54
  to_add.each{ |feature_flag| add_feature_flag(feature_flag) }
54
55
  to_delete.each{ |feature_flag| remove_feature_flag(feature_flag) }
55
56
  set_change_number(new_change_number)
57
+
58
+ if to_add.length > 0 || to_delete.length > 0
59
+ @internal_events_queue.push(
60
+ SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
61
+ SplitIoClient::Engine::Models::SdkInternalEvent::FLAGS_UPDATED,
62
+ SplitIoClient::Engine::Models::EventsMetadata.new(
63
+ SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE,
64
+ to_add.map {|flag| flag[:name]} | to_delete.map {|flag| flag[:name]}
65
+ )
66
+ )
67
+ )
68
+ end
56
69
  end
57
70
 
58
71
  def get_split(name)
@@ -140,6 +153,15 @@ module SplitIoClient
140
153
  split[:changeNumber] = change_number
141
154
 
142
155
  @adapter.set_string(namespace_key(".split.#{split_name}"), split.to_json)
156
+ @internal_events_queue.push(
157
+ SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
158
+ SplitIoClient::Engine::Models::SdkInternalEvent::FLAG_KILLED_NOTIFICATION,
159
+ SplitIoClient::Engine::Models::EventsMetadata.new(
160
+ SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE,
161
+ [split_name]
162
+ )
163
+ )
164
+ )
143
165
  end
144
166
 
145
167
  def splits_count
@@ -18,7 +18,7 @@ module SplitIoClient
18
18
  # @param sdk_key [String] the SDK key for your split account
19
19
  #
20
20
  # @return [SplitIoClient] split.io client instance
21
- def initialize(sdk_key, repositories, status_manager, config, impressions_manager, telemetry_evaluation_producer, evaluator, split_validator, fallback_treatment_calculator)
21
+ def initialize(sdk_key, repositories, status_manager, config, impressions_manager, telemetry_evaluation_producer, evaluator, split_validator, fallback_treatment_calculator, events_manager)
22
22
  @api_key = sdk_key
23
23
  @splits_repository = repositories[:splits]
24
24
  @segments_repository = repositories[:segments]
@@ -33,6 +33,7 @@ module SplitIoClient
33
33
  @split_validator = split_validator
34
34
  @evaluator = evaluator
35
35
  @fallback_treatment_calculator = fallback_treatment_calculator
36
+ @events_manager = events_manager
36
37
  end
37
38
 
38
39
  def get_treatment(
@@ -117,11 +118,11 @@ module SplitIoClient
117
118
  @config.logger.info('Split client shutdown started...') if @config.debug_enabled
118
119
  if !@config.cache_adapter.is_a?(SplitIoClient::Cache::Adapters::RedisAdapter) && @config.impressions_mode != :none &&
119
120
  (!@impressions_repository.empty? || !@events_repository.empty?)
120
- @config.logger.debug("Impressions and/or Events cache is not empty")
121
+ @config.logger.debug("Impressions and/or Events cache is not empty") if @config.debug_enabled
121
122
  # Adding small delay to ensure sender threads are fully running
122
123
  sleep(0.1)
123
124
  if !@config.threads.key?(:impressions_sender) || !@config.threads.key?(:events_sender)
124
- @config.logger.debug("Periodic data recording thread has not started yet, waiting for service startup.")
125
+ @config.logger.debug("Periodic data recording thread has not started yet, waiting for service startup.") if @config.debug_enabled
125
126
  @config.threads[:start_sdk].join(5) if @config.threads.key?(:start_sdk)
126
127
  end
127
128
  end
@@ -176,6 +177,14 @@ module SplitIoClient
176
177
  @status_manager.wait_until_ready(time) if @status_manager
177
178
  end
178
179
 
180
+ def register(sdk_event, handler)
181
+ @events_manager.register(sdk_event, handler)
182
+ end
183
+
184
+ def unregister(sdk_event, handler)
185
+ @events_manager.unregister(sdk_event)
186
+ end
187
+
179
188
  private
180
189
 
181
190
  def check_properties_size(properties_size, msg = "Event not queued")
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'stringio'
4
5
 
5
6
  module SplitIoClient
6
7
  module FaradayMiddleware
@@ -24,7 +24,7 @@ module SplitIoClient
24
24
 
25
25
  if check_last_proxy_check_timestamp
26
26
  @spec_version = SplitIoClient::Spec::FeatureFlags::SPEC_VERSION
27
- @config.logger.debug("Switching to new Feature flag spec #{@spec_version} and fetching.")
27
+ @config.logger.debug("Switching to new Feature flag spec #{@spec_version} and fetching.") if @config.debug_enabled
28
28
  @old_spec_since = since
29
29
  since = -1
30
30
  since_rbs = -1
@@ -41,7 +41,7 @@ module SplitIoClient
41
41
 
42
42
  params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
43
43
  params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
44
- @config.logger.debug("Fetching from splitChanges with #{params}: ")
44
+ @config.logger.debug("Fetching from splitChanges with #{params}: ") if @config.debug_enabled
45
45
  response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, fetch_options[:cache_control_headers])
46
46
  if response.status == 414
47
47
  @config.logger.error("Error fetching feature flags; the amount of flag sets provided are too big, causing uri length error.")
@@ -21,10 +21,12 @@ module SplitIoClient
21
21
  return process_error(response) if response.status >= 400 && response.status < 500
22
22
 
23
23
  @telemetry_runtime_producer.record_sync_error(Telemetry::Domain::Constants::TOKEN_SYNC, response.status.to_i)
24
- @config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
24
+ if @config.debug_enabled
25
+ @config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
26
+ end
25
27
  { push_enabled: false, retry: true }
26
28
  rescue StandardError => e
27
- @config.logger.debug("AuthApiClient error: #{e.inspect}.")
29
+ @config.logger.debug("AuthApiClient error: #{e.inspect}.") if @config.debug_enabled
28
30
  { push_enabled: false, retry: false }
29
31
  end
30
32
 
@@ -51,7 +53,9 @@ module SplitIoClient
51
53
  end
52
54
 
53
55
  def process_error(response)
54
- @config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
56
+ if @config.debug_enabled
57
+ @config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
58
+ end
55
59
  @telemetry_runtime_producer.record_auth_rejections if response.status == 401
56
60
 
57
61
  { push_enabled: false, retry: false }
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SplitIoClient
4
+ module Engine
5
+ module Events
6
+ class EventsDelivery
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def deliver(sdk_event, event_metadata, event_handler)
12
+ event_handler.call(event_metadata)
13
+ rescue StandardError => e
14
+ @config.logger.error("Exception when calling handler for Sdk Event #{sdk_event}")
15
+ @config.log_found_exception(__method__.to_s, e)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SplitIoClient
4
+ module Engine
5
+ module Events
6
+ class EventsManager
7
+ def initialize(events_manager_config, events_delivery, config)
8
+ @manager_config = events_manager_config
9
+ @events_delivery = events_delivery
10
+ @active_subscriptions = {}
11
+ @internal_events_status = {}
12
+ @mutex = Mutex.new
13
+ @config = config
14
+ end
15
+
16
+ def register(sdk_event, event_handler)
17
+ return if @active_subscriptions.key?(sdk_event) && !get_event_handler(sdk_event).nil?
18
+
19
+ @mutex.synchronize do
20
+ # SDK ready already fired
21
+ if sdk_event == Engine::Models::SdkEvent::SDK_READY && event_already_triggered(sdk_event)
22
+ @active_subscriptions[sdk_event] = Engine::Models::EventActiveSubscriptions.new(true, event_handler)
23
+ @config.logger.debug('EventsManager: Firing SDK_READY event for new subscription') if @config.debug_enabled
24
+ fire_sdk_event(sdk_event, nil)
25
+ return
26
+ end
27
+
28
+ @config.logger.debug("EventsManager: Register event: #{sdk_event}") if @config.debug_enabled
29
+ @active_subscriptions[sdk_event] = Engine::Models::EventActiveSubscriptions.new(false, event_handler)
30
+ end
31
+ end
32
+
33
+ def unregister(sdk_event)
34
+ return unless @active_subscriptions.key?(sdk_event)
35
+
36
+ @mutex.synchronize do
37
+ @active_subscriptions.delete(sdk_event)
38
+ end
39
+ end
40
+
41
+ def notify_internal_event(sdk_internal_event, event_metadata)
42
+ @mutex.synchronize do
43
+ update_internal_event_status(sdk_internal_event, true)
44
+ @manager_config.evaluation_order.each do |sorted_event|
45
+ if get_sdk_event_if_applicable(sdk_internal_event).include?(sorted_event) &&
46
+ !get_event_handler(sorted_event).nil?
47
+ fire_sdk_event(sorted_event, event_metadata)
48
+ end
49
+
50
+ # if client is not subscribed to SDK_READY
51
+ if check_if_register_needed(sorted_event)
52
+ @config.logger.debug('EventsManager: Registering SDK_READY event as fired') if @config.debug_enabled
53
+ @active_subscriptions[Engine::Models::SdkEvent::SDK_READY] = Engine::Models::EventActiveSubscriptions.new(true, nil)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def destroy
60
+ @mutex.synchronize do
61
+ @active_subscriptions = {}
62
+ @internal_events_status = {}
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def check_if_register_needed(sorted_event)
69
+ sorted_event == Engine::Models::SdkEvent::SDK_READY &&
70
+ get_event_handler(sorted_event).nil? &&
71
+ !@active_subscriptions.include?(sorted_event)
72
+ end
73
+
74
+ def fire_sdk_event(sdk_event, event_metadata)
75
+ @config.logger.debug("EventsManager: Firing Sdk event: #{sdk_event}") if @config.debug_enabled
76
+ @config.threads[:sdk_event_notify] = Thread.new do
77
+ @events_delivery.deliver(sdk_event, event_metadata, get_event_handler(sdk_event))
78
+ end
79
+ sdk_event_triggered(sdk_event)
80
+ end
81
+
82
+ def event_already_triggered(sdk_event)
83
+ return @active_subscriptions[sdk_event].triggered if @active_subscriptions.key?(sdk_event)
84
+
85
+ false
86
+ end
87
+
88
+ def get_internal_event_status(sdk_internal_event)
89
+ return @internal_events_status[sdk_internal_event] if @internal_events_status.key?(sdk_internal_event)
90
+
91
+ false
92
+ end
93
+
94
+ def update_internal_event_status(sdk_internal_event, status)
95
+ @internal_events_status[sdk_internal_event] = status
96
+ end
97
+
98
+ def sdk_event_triggered(sdk_event)
99
+ return unless @active_subscriptions.key?(sdk_event)
100
+
101
+ return if @active_subscriptions[sdk_event].triggered
102
+
103
+ @active_subscriptions[sdk_event].triggered = true
104
+ end
105
+
106
+ def get_event_handler(sdk_event)
107
+ return nil unless @active_subscriptions.key?(sdk_event)
108
+
109
+ @active_subscriptions[sdk_event].handler
110
+ end
111
+
112
+ def get_sdk_event_if_applicable(sdk_internal_event)
113
+ final_sdk_event = Engine::Models::ValidSdkEvent.new(nil, false)
114
+
115
+ events_to_fire = []
116
+ require_any_sdk_event = check_require_any(sdk_internal_event)
117
+ if require_any_sdk_event.valid
118
+ if (!event_already_triggered(require_any_sdk_event.sdk_event) &&
119
+ execution_limit(require_any_sdk_event.sdk_event) == 1) ||
120
+ execution_limit(require_any_sdk_event.sdk_event) == -1
121
+ final_sdk_event = Engine::Models::ValidSdkEvent.new(
122
+ require_any_sdk_event.sdk_event,
123
+ check_prerequisites(require_any_sdk_event.sdk_event) &&
124
+ check_suppressed_by(require_any_sdk_event.sdk_event)
125
+ )
126
+ end
127
+ events_to_fire.push(final_sdk_event.sdk_event) if final_sdk_event.valid
128
+ end
129
+ check_require_all.each { |sdk_event| events_to_fire.push(sdk_event) }
130
+
131
+ events_to_fire
132
+ end
133
+
134
+ def check_require_all
135
+ events = []
136
+ @manager_config.require_all.each do |require_name, require_value|
137
+ final_status = true
138
+ require_value.each { |val| final_status &= get_internal_event_status(val) }
139
+ events.push(require_name) if check_event_eligible_conditions(final_status, require_name, require_value)
140
+ end
141
+
142
+ events
143
+ end
144
+
145
+ def check_event_eligible_conditions(final_status, require_name, require_value)
146
+ final_status &&
147
+ check_prerequisites(require_name) &&
148
+ ((!event_already_triggered(require_name) &&
149
+ execution_limit(require_name) == 1) ||
150
+ execution_limit(require_name) == -1) &&
151
+ require_value.length.positive?
152
+ end
153
+
154
+ def check_prerequisites(sdk_event)
155
+ @manager_config.prerequisites.each do |name, value|
156
+ value.each do |val|
157
+ return false if name == sdk_event && !event_already_triggered(val)
158
+ end
159
+ end
160
+
161
+ true
162
+ end
163
+
164
+ def check_suppressed_by(sdk_event)
165
+ @manager_config.suppressed_by.each do |name, value|
166
+ value.each do |val|
167
+ return false if name == sdk_event && event_already_triggered(val)
168
+ end
169
+ end
170
+
171
+ true
172
+ end
173
+
174
+ def execution_limit(sdk_event)
175
+ return -1 unless @manager_config.execution_limits.key?(sdk_event)
176
+
177
+ @manager_config.execution_limits[sdk_event]
178
+ end
179
+
180
+ def check_require_any(sdk_internal_event)
181
+ valid_sdk_event = Engine::Models::ValidSdkEvent.new(nil, false)
182
+ @manager_config.require_any.each do |name, val|
183
+ if val.include?(sdk_internal_event)
184
+ valid_sdk_event = Engine::Models::ValidSdkEvent.new(name, true)
185
+ return valid_sdk_event
186
+ end
187
+ end
188
+
189
+ valid_sdk_event
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end