splitclient-rb 8.4.0 → 8.11.0

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +9 -2
  3. data/CHANGES.txt +24 -0
  4. data/LICENSE +169 -13
  5. data/NOTICE.txt +5 -0
  6. data/lib/splitclient-rb/cache/fetchers/split_fetcher.rb +9 -7
  7. data/lib/splitclient-rb/cache/filter/bloom_filter.rb +10 -6
  8. data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +1 -0
  9. data/lib/splitclient-rb/cache/repositories/rule_based_segments_repository.rb +136 -0
  10. data/lib/splitclient-rb/cache/repositories/segments_repository.rb +21 -2
  11. data/lib/splitclient-rb/cache/repositories/splits_repository.rb +42 -12
  12. data/lib/splitclient-rb/cache/senders/impressions_formatter.rb +24 -10
  13. data/lib/splitclient-rb/cache/stores/localhost_split_builder.rb +2 -1
  14. data/lib/splitclient-rb/clients/split_client.rb +146 -62
  15. data/lib/splitclient-rb/engine/api/client.rb +8 -0
  16. data/lib/splitclient-rb/engine/api/faraday_middleware/gzip.rb +1 -0
  17. data/lib/splitclient-rb/engine/api/splits.rb +100 -24
  18. data/lib/splitclient-rb/engine/auth_api_client.rb +3 -3
  19. data/lib/splitclient-rb/engine/common/impressions_manager.rb +56 -30
  20. data/lib/splitclient-rb/engine/events/events_delivery.rb +20 -0
  21. data/lib/splitclient-rb/engine/events/events_manager.rb +194 -0
  22. data/lib/splitclient-rb/engine/events/events_manager_config.rb +96 -0
  23. data/lib/splitclient-rb/engine/events/events_task.rb +50 -0
  24. data/lib/splitclient-rb/engine/events/noop_events_queue.rb +13 -0
  25. data/lib/splitclient-rb/engine/fallback_treatment_calculator.rb +48 -0
  26. data/lib/splitclient-rb/engine/impressions/unique_keys_tracker.rb +58 -11
  27. data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +3 -1
  28. data/lib/splitclient-rb/engine/matchers/prerequisites_matcher.rb +31 -0
  29. data/lib/splitclient-rb/engine/matchers/rule_based_segment_matcher.rb +78 -0
  30. data/lib/splitclient-rb/engine/models/evaluation_options.rb +9 -0
  31. data/lib/splitclient-rb/engine/models/event_active_subscriptions.rb +14 -0
  32. data/lib/splitclient-rb/engine/models/events_metadata.rb +10 -0
  33. data/lib/splitclient-rb/engine/models/fallback_treatment.rb +11 -0
  34. data/lib/splitclient-rb/engine/models/fallback_treatments_configuration.rb +36 -0
  35. data/lib/splitclient-rb/engine/models/label.rb +1 -0
  36. data/lib/splitclient-rb/engine/models/sdk_event.rb +4 -0
  37. data/lib/splitclient-rb/engine/models/sdk_event_type.rb +4 -0
  38. data/lib/splitclient-rb/engine/models/sdk_internal_event.rb +8 -0
  39. data/lib/splitclient-rb/engine/models/sdk_internal_event_notification.rb +14 -0
  40. data/lib/splitclient-rb/engine/models/segment_type.rb +4 -0
  41. data/lib/splitclient-rb/engine/models/split_http_response.rb +19 -0
  42. data/lib/splitclient-rb/engine/models/valid_sdk_event.rb +14 -0
  43. data/lib/splitclient-rb/engine/parser/condition.rb +9 -0
  44. data/lib/splitclient-rb/engine/parser/evaluator.rb +24 -30
  45. data/lib/splitclient-rb/engine/status_manager.rb +7 -1
  46. data/lib/splitclient-rb/engine/sync_manager.rb +6 -6
  47. data/lib/splitclient-rb/engine/synchronizer.rb +37 -17
  48. data/lib/splitclient-rb/helpers/evaluator_helper.rb +37 -0
  49. data/lib/splitclient-rb/helpers/repository_helper.rb +39 -1
  50. data/lib/splitclient-rb/helpers/util.rb +12 -3
  51. data/lib/splitclient-rb/managers/split_manager.rb +2 -1
  52. data/lib/splitclient-rb/spec.rb +1 -1
  53. data/lib/splitclient-rb/split_config.rb +45 -5
  54. data/lib/splitclient-rb/split_factory.rb +27 -21
  55. data/lib/splitclient-rb/sse/event_source/client.rb +86 -29
  56. data/lib/splitclient-rb/sse/event_source/event_parser.rb +2 -2
  57. data/lib/splitclient-rb/sse/event_source/event_types.rb +1 -0
  58. data/lib/splitclient-rb/sse/notification_manager_keeper.rb +3 -3
  59. data/lib/splitclient-rb/sse/notification_processor.rb +3 -1
  60. data/lib/splitclient-rb/sse/workers/segments_worker.rb +4 -4
  61. data/lib/splitclient-rb/sse/workers/splits_worker.rb +63 -24
  62. data/lib/splitclient-rb/utilitites.rb +6 -10
  63. data/lib/splitclient-rb/validators.rb +56 -25
  64. data/lib/splitclient-rb/version.rb +1 -1
  65. data/lib/splitclient-rb.rb +22 -0
  66. data/sonar-project.properties +1 -0
  67. data/splitclient-rb.gemspec +3 -4
  68. metadata +32 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4566bc73b33d8770b7727b8c2274355e9b838bdb3b709319b2c4c1d0f5d0d2cd
4
- data.tar.gz: cb2f7f391dbc3bdacea7e0837167e06cef4a634c44b6094343a34a96507390d0
3
+ metadata.gz: 41d269b5dc5e38906001aefe42cb60bb4ef8de5376b9d71c613b5c8345cc9451
4
+ data.tar.gz: 6d66df400c0e2279ac23250dc22540135bd4e358467b5ba17ade47f8efdc6be9
5
5
  SHA512:
6
- metadata.gz: 0e5c7b8592942081ad7f324e00facdf5341c632810fc0520ba9a97512795895c06f3d35ef17a14e0d07e60fb9c8b8abb16af5cc0988a5c454a8e447e21e2aaf1
7
- data.tar.gz: 9ddc716be18d0a53b4835795681d6a375188bce1481cd0bcbe0d3be73d485344486c88ac7326f25af6d9290a0c987427ae8abfd087ca1e6832b06c4ee9194784
6
+ metadata.gz: 1fd4c042221d85b902894870073ec8dda740807f59348c83ce470e5571d929b6e4ca88d19e014c597a91841464a89b4f3c558b35993f091b2d5bc142dc0bfb0e
7
+ data.tar.gz: b1bb37265463a9a8023f70cce31dbc880a2a84c0618b3defc4e0bef9075bb62cc558f68f212e9ea1b4310be51d180a1f5538333b6b30a2e079ce704fd4da638d
@@ -35,6 +35,12 @@ jobs:
35
35
  with:
36
36
  fetch-depth: 0
37
37
 
38
+ - name: Set up Java
39
+ uses: actions/setup-java@v2
40
+ with:
41
+ java-version: 17
42
+ distribution: "temurin"
43
+
38
44
  - name: Setup Ruby ${{ matrix.version }}
39
45
  uses: ruby/setup-ruby@v1
40
46
  with:
@@ -57,7 +63,7 @@ jobs:
57
63
 
58
64
  - name: SonarQube Scan (Push)
59
65
  if: matrix.version == '3.2.2' && github.event_name == 'push'
60
- uses: SonarSource/sonarcloud-github-action@v1.9
66
+ uses: SonarSource/sonarcloud-github-action@v5.0.0
61
67
  env:
62
68
  SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
63
69
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -69,13 +75,14 @@ jobs:
69
75
 
70
76
  - name: SonarQube Scan (Pull Request)
71
77
  if: matrix.version == '3.2.2' && github.event_name == 'pull_request'
72
- uses: SonarSource/sonarcloud-github-action@v1.9
78
+ uses: SonarSource/sonarcloud-github-action@v5.0.0
73
79
  env:
74
80
  SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
75
81
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76
82
  with:
77
83
  projectBaseDir: .
78
84
  args: >
85
+ -Dsonar.java.source=17
79
86
  -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
80
87
  -Dsonar.projectVersion=${{ env.VERSION }}
81
88
  -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
data/CHANGES.txt CHANGED
@@ -1,5 +1,29 @@
1
1
  CHANGES
2
2
 
3
+ 8.10.1 (Jan 28, 2025)
4
+ - Fixed rule-based segment matcher to exit when a conition is met.
5
+ - Fixed impressions properties format in redis mode.
6
+
7
+ 8.10.0 (Nov 28, 2025)
8
+ - Updated socketry gem used in streaming feature with built-in socket lib.
9
+
10
+ 8.9.0 (Oct 8, 2025)
11
+ - 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.
12
+
13
+ 8.8.0 (Sep 26, 2025)
14
+ - Added a maximum size payload when posting unique keys telemetry in batches
15
+
16
+ 8.7.0 (Aug 1, 2025)
17
+ - Added a new optional argument to the client `getTreatment` methods to allow passing additional evaluation options, such as a map of properties to append to the generated impressions sent to Split backend. Read more in our docs.
18
+
19
+ 8.6.0 (Jun 17, 2025)
20
+ - Added support for rule-based segments. These segments determine membership at runtime by evaluating their configured rules against the user attributes provided to the SDK.
21
+ - Added support for feature flag prerequisites. This allows customers to define dependency conditions between flags, which are evaluated before any allowlists or targeting rules.
22
+
23
+ 8.5.0 (Jan 17, 2025)
24
+ - Fixed high cpu usage when unique keys are cleared every 24 hours.
25
+ - Added support for the new impressions tracking toggle available on feature flags, both respecting the setting and including the new field being returned on SplitView type objects. Read more in our docs.
26
+
3
27
  8.4.0 (May 3, 2024)
4
28
  - Fixed issue preventing Impressopns and Events posting if client.destroy is called before the post threads started
5
29
  - Added support for targeting rules based on semantic versions (https://semver.org/).
data/LICENSE CHANGED
@@ -1,13 +1,169 @@
1
- Copyright © 2024 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 [yyyy] [name of copyright owner]
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.
@@ -2,10 +2,11 @@ module SplitIoClient
2
2
  module Cache
3
3
  module Fetchers
4
4
  class SplitFetcher
5
- attr_reader :splits_repository
5
+ attr_reader :splits_repository, :rule_based_segments_repository
6
6
 
7
- def initialize(splits_repository, api_key, config, telemetry_runtime_producer)
7
+ def initialize(splits_repository, rule_based_segments_repository, api_key, config, telemetry_runtime_producer)
8
8
  @splits_repository = splits_repository
9
+ @rule_based_segments_repository = rule_based_segments_repository
9
10
  @api_key = api_key
10
11
  @config = config
11
12
  @semaphore = Mutex.new
@@ -23,10 +24,11 @@ module SplitIoClient
23
24
 
24
25
  def fetch_splits(fetch_options = { cache_control_headers: false, till: nil })
25
26
  @semaphore.synchronize do
26
- data = splits_since(@splits_repository.get_change_number, fetch_options)
27
-
28
- SplitIoClient::Helpers::RepositoryHelper.update_feature_flag_repository(@splits_repository, data[:splits], data[:till], @config)
27
+ data = splits_since(@splits_repository.get_change_number, @rule_based_segments_repository.get_change_number, fetch_options)
28
+ SplitIoClient::Helpers::RepositoryHelper.update_feature_flag_repository(@splits_repository, data[:ff][:d], data[:ff][:t], @config, @splits_api.clear_storage)
29
+ SplitIoClient::Helpers::RepositoryHelper.update_rule_based_segment_repository(@rule_based_segments_repository, data[:rbs][:d], data[:rbs][:t], @config)
29
30
  @splits_repository.set_segment_names(data[:segment_names])
31
+ @rule_based_segments_repository.set_segment_names(data[:segment_names])
30
32
  @config.logger.debug("segments seen(#{data[:segment_names].length}): #{data[:segment_names].to_a}") if @config.debug_enabled
31
33
 
32
34
  { segment_names: data[:segment_names], success: true }
@@ -55,8 +57,8 @@ module SplitIoClient
55
57
  end
56
58
  end
57
59
 
58
- def splits_since(since, fetch_options = { cache_control_headers: false, till: nil })
59
- splits_api.since(since, fetch_options)
60
+ def splits_since(since, since_rbs, fetch_options = { cache_control_headers: false, till: nil })
61
+ splits_api.since(since, since_rbs, fetch_options)
60
62
  end
61
63
 
62
64
  def splits_api
@@ -8,8 +8,8 @@ module SplitIoClient
8
8
  class BloomFilter
9
9
  def initialize(capacity, false_positive_probability = 0.001)
10
10
  @capacity = capacity.round
11
- m = best_m(capacity, false_positive_probability)
12
- @ba = BitArray.new(m.round)
11
+ @m = best_m(capacity, false_positive_probability)
12
+ reset_filter
13
13
  @k = best_k(capacity)
14
14
  end
15
15
 
@@ -17,22 +17,26 @@ module SplitIoClient
17
17
  return false if contains?(string)
18
18
 
19
19
  positions = hashes(string)
20
-
21
20
  positions.each { |position| @ba[position] = 1 }
22
21
 
23
22
  true
24
23
  end
25
-
24
+
26
25
  def contains?(string)
27
26
  !hashes(string).any? { |ea| @ba[ea] == 0 }
28
27
  end
29
28
 
30
29
  def clear
31
- @ba.size.times { |i| @ba[i] = 0 }
30
+ @ba = nil
31
+ reset_filter
32
32
  end
33
-
33
+
34
34
  private
35
35
 
36
+ def reset_filter
37
+ @ba = BitArray.new(@m.round)
38
+ end
39
+
36
40
  # m is the required number of bits in the array
37
41
  def best_m(capacity, false_positive_probability)
38
42
  -(capacity * Math.log(false_positive_probability)) / (Math.log(2) ** 2)
@@ -14,6 +14,7 @@ module SplitIoClient
14
14
 
15
15
  def add_bulk(impressions)
16
16
  impressions_json = impressions.map do |impression|
17
+ impression[:i][:properties] = impression[:i][:properties].to_json.to_s unless impression[:i][:properties].nil?
17
18
  impression.to_json
18
19
  end
19
20
 
@@ -0,0 +1,136 @@
1
+ require 'concurrent'
2
+
3
+ module SplitIoClient
4
+ module Cache
5
+ module Repositories
6
+ class RuleBasedSegmentsRepository < Repository
7
+ attr_reader :adapter
8
+ DEFAULT_CONDITIONS_TEMPLATE = [{
9
+ conditionType: "ROLLOUT",
10
+ matcherGroup: {
11
+ combiner: "AND",
12
+ matchers: [
13
+ {
14
+ keySelector: nil,
15
+ matcherType: "ALL_KEYS",
16
+ negate: false,
17
+ userDefinedSegmentMatcherData: nil,
18
+ whitelistMatcherData: nil,
19
+ unaryNumericMatcherData: nil,
20
+ betweenMatcherData: nil,
21
+ dependencyMatcherData: nil,
22
+ booleanMatcherData: nil,
23
+ stringMatcherData: nil
24
+ }]
25
+ }
26
+ }]
27
+ TILL_PREFIX = '.rbsegments.till'
28
+ RB_SEGMENTS_PREFIX = '.rbsegment.'
29
+ REGISTERED_PREFIX = '.segments.registered'
30
+
31
+ def initialize(config, internal_events_queue)
32
+ super(config)
33
+ @adapter = case @config.cache_adapter.class.to_s
34
+ when 'SplitIoClient::Cache::Adapters::RedisAdapter'
35
+ SplitIoClient::Cache::Adapters::CacheAdapter.new(@config)
36
+ else
37
+ @config.cache_adapter
38
+ end
39
+ unless @config.mode.equal?(:consumer)
40
+ @adapter.set_string(namespace_key(TILL_PREFIX), '-1')
41
+ @adapter.initialize_map(namespace_key(REGISTERED_PREFIX))
42
+ end
43
+ @internal_events_queue = internal_events_queue
44
+ end
45
+
46
+ def update(to_add, to_delete, new_change_number)
47
+ to_add.each{ |rule_based_segment| add_rule_based_segment(rule_based_segment) }
48
+ to_delete.each{ |rule_based_segment| remove_rule_based_segment(rule_based_segment) }
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
62
+ end
63
+
64
+ def get_rule_based_segment(name)
65
+ rule_based_segment = @adapter.string(namespace_key("#{RB_SEGMENTS_PREFIX}#{name}"))
66
+
67
+ JSON.parse(rule_based_segment, symbolize_names: true) if rule_based_segment
68
+ end
69
+
70
+ def rule_based_segment_names
71
+ @adapter.find_strings_by_prefix(namespace_key(RB_SEGMENTS_PREFIX))
72
+ .map { |rule_based_segment_names| rule_based_segment_names.gsub(namespace_key(RB_SEGMENTS_PREFIX), '') }
73
+ end
74
+
75
+ def set_change_number(since)
76
+ @adapter.set_string(namespace_key(TILL_PREFIX), since)
77
+ end
78
+
79
+ def get_change_number
80
+ @adapter.string(namespace_key(TILL_PREFIX))
81
+ end
82
+
83
+ def set_segment_names(names)
84
+ return if names.nil? || names.empty?
85
+
86
+ names.each do |name|
87
+ @adapter.add_to_set(namespace_key(REGISTERED_PREFIX), name)
88
+ end
89
+ end
90
+
91
+ def exists?(name)
92
+ @adapter.exists?(namespace_key("#{RB_SEGMENTS_PREFIX}#{name}"))
93
+ end
94
+
95
+ def clear
96
+ @adapter.clear(namespace_key)
97
+ end
98
+
99
+ def contains?(segment_names)
100
+ return false if rule_based_segment_names.empty?
101
+
102
+ return segment_names.to_set.subset?(rule_based_segment_names.to_set)
103
+ end
104
+
105
+ private
106
+
107
+ def add_rule_based_segment(rule_based_segment)
108
+ return unless rule_based_segment[:name]
109
+
110
+ if check_undefined_matcher(rule_based_segment)
111
+ @config.logger.warn("Rule based segment #{rule_based_segment[:name]} has undefined matcher, setting conditions to default template.")
112
+ rule_based_segment[:conditions] = RuleBasedSegmentsRepository::DEFAULT_CONDITIONS_TEMPLATE
113
+ end
114
+
115
+ @adapter.set_string(namespace_key("#{RB_SEGMENTS_PREFIX}#{rule_based_segment[:name]}"), rule_based_segment.to_json)
116
+ end
117
+
118
+ def check_undefined_matcher(rule_based_segment)
119
+ for condition in rule_based_segment[:conditions]
120
+ for matcher in condition[:matcherGroup][:matchers]
121
+ if !SplitIoClient::Condition.instance_methods(false).map(&:to_s).include?("matcher_#{matcher[:matcherType].downcase}")
122
+ @config.logger.error("Detected undefined matcher #{matcher[:matcherType].downcase} in feature flag #{rule_based_segment[:name]}")
123
+ return true
124
+ end
125
+ end
126
+ end
127
+ return false
128
+ end
129
+
130
+ def remove_rule_based_segment(rule_based_segment)
131
+ @adapter.delete(namespace_key("#{RB_SEGMENTS_PREFIX}#{rule_based_segment[:name]}"))
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -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,20 @@ 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
+ @config.logger.debug(segment)
26
27
  add_keys(name, segment[:added])
27
28
  remove_keys(name, segment[:removed])
29
+ if segment[:added].length > 0 || segment[:removed].length > 0
30
+ @internal_events_queue.push(
31
+ SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
32
+ SplitIoClient::Engine::Models::SdkInternalEvent::SEGMENTS_UPDATED,
33
+ SplitIoClient::Engine::Models::EventsMetadata.new(
34
+ SplitIoClient::Engine::Models::SdkEventType::SEGMENTS_UPDATE,
35
+ []
36
+ )
37
+ )
38
+ )
39
+ end
28
40
  end
29
41
 
30
42
  def get_segment_keys(name)
@@ -83,6 +95,13 @@ module SplitIoClient
83
95
  0
84
96
  end
85
97
 
98
+ def contains?(segment_names)
99
+ if segment_names.empty?
100
+ return false
101
+ end
102
+ return segment_names.to_set.subset?(used_segment_names.to_set)
103
+ end
104
+
86
105
  private
87
106
 
88
107
  def segment_data(name)