Skip to content

Commit c5c38c6

Browse files
authored
Merge pull request #435 from splitio/development
[8.0.0] Development into master
2 parents dd2ec2d + 8a6a1f0 commit c5c38c6

85 files changed

Lines changed: 1628 additions & 478 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
on:
2-
push:
3-
branches:
4-
- master
5-
pull_request:
6-
branches:
7-
- master
1+
on: [push, pull_request]
82

93
jobs:
104
test:
@@ -14,16 +8,20 @@ jobs:
148
image: redis
159
ports:
1610
- 6379:6379
11+
strategy:
12+
matrix:
13+
ruby: [ '2.5.0', '3.1.1' ]
14+
1715
steps:
1816
- name: Checkout code
1917
uses: actions/checkout@v2
2018
with:
2119
fetch-depth: 0
2220

23-
- name: Set up Ruby
24-
uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
21+
- name: Set up Ruby ${{ matrix.ruby }}
22+
uses: ruby/setup-ruby@v1
2523
with:
26-
ruby-version: 2.5
24+
ruby-version: ${{ matrix.ruby }}
2725

2826
- name: Install dependencies
2927
run: bundle install

.rubocop.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,7 @@ Metrics/ParameterLists:
2626
- lib/splitclient-rb/engine/sync_manager.rb
2727

2828
Metrics/LineLength:
29-
Max: 130
30-
Exclude:
31-
- spec/sse/**/*
32-
- spec/integrations/**/*
33-
- spec/engine/sync_manager_spec.rb
34-
- spec/engine/auth_api_client_spec.rb
35-
- spec/telemetry/synchronizer_spec.rb
36-
- spec/splitclient/split_config_spec.rb
37-
- spec/engine/push_manager_spec.rb
38-
39-
Style/BracesAroundHashParameters:
40-
Exclude:
41-
- spec/integrations/push_client_spec.rb
42-
- spec/engine/synchronizer_spec.rb
29+
Max: 135
4330

4431
Metrics/BlockLength:
4532
Exclude:
@@ -50,8 +37,24 @@ Naming/FileName:
5037
Exclude:
5138
- splitclient-rb.gemspec
5239

40+
Style/OptionalBooleanParameter:
41+
Exclude:
42+
- lib/splitclient-rb/engine/matchers/between_matcher.rb
43+
- lib/splitclient-rb/engine/matchers/combining_matcher.rb
44+
- lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
45+
- lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
46+
- lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb
47+
48+
Style/HashTransformKeys:
49+
Exclude:
50+
- lib/splitclient-rb/engine/matchers/combining_matcher.rb
51+
52+
Style/RedundantReturn:
53+
Exclude:
54+
- lib/splitclient-rb/engine/common/impressions_manager.rb
55+
5356
AllCops:
54-
TargetRubyVersion: 2.3.6
57+
TargetRubyVersion: 2.5
5558
Exclude:
5659
- gemfiles/* # excluded as appraisal generates them with errors
5760
- lib/*
@@ -69,3 +72,5 @@ AllCops:
6972
- lib/splitclient-rb/engine/synchronizer.rb
7073
- tmp/**/*
7174
- lib/splitclient-rb/sse/event_source/client.rb
75+
- spec/**/*
76+
- .simplecov

Appraisals

Lines changed: 0 additions & 10 deletions
This file was deleted.

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
CHANGES
22

3+
8.0.0 (May 10, 2022)
4+
- BREAKING CHANGE: Deprecated support for ruby 2.3 and 2.4 versions. The minimum ruby version required is 2.5 now.
5+
- Updated redis command for config telemetry, using hset instead of rpush now.
6+
- Updated dependencies:
7+
- rake to ~> 13.0
8+
- faraday to >= 1.1, < 2.0
9+
310
7.3.4 (Feb 21, 2022)
411
- Updated streaming events architecture with a new queue logic.
512
- Fixed redis integration Pipelining command deprecation warning.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Split SDK for Ruby
2-
[![Build Status](https://travis-ci.com/splitio/ruby-client.svg?branch=master)](https://travis-ci.com/splitio/ruby-client)
2+
![Build Status](https://github.com/splitio/ruby-client/actions/workflows/ci.yml/badge.svg?branch=master)
33

44
## Overview
55
This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via a Split feature flag to manage your complete customer experience.
66

77
[![Twitter Follow](https://img.shields.io/twitter/follow/splitsoftware.svg?style=social&label=Follow&maxAge=1529000)](https://twitter.com/intent/follow?screen_name=splitsoftware)
88

99
## Compatibility
10-
The Ruby SDK support Ruby version 2.3.0 or later and JRuby or 9.1.17 o later.
10+
The Ruby SDK support Ruby version 2.5.0 or later and JRuby or 9.1.17 o later.
1111

1212
Also the Ruby SDK has been tested as a standalone app as well as using the following web servers:
1313
- Puma

Rakefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'bundler/gem_tasks'
44
require 'rspec/core/rake_task'
55
require 'rubocop/rake_task'
6-
require 'appraisal'
76

87
Dir['tasks/**/*.rake'].each { |rake| load rake }
98

@@ -26,10 +25,4 @@ else
2625
end
2726
end
2827

29-
if !ENV['APPRAISAL_INITIALIZED']
30-
task :default do
31-
sh 'appraisal install && rake appraisal && rake rubocop'
32-
end
33-
else
34-
task default: %i[spec rubocop]
35-
end
28+
task default: %i[spec rubocop]

lib/splitclient-rb.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
require 'splitclient-rb/cache/adapters/redis_adapter'
1313
require 'splitclient-rb/cache/fetchers/segment_fetcher'
1414
require 'splitclient-rb/cache/fetchers/split_fetcher'
15+
require 'splitclient-rb/cache/filter/bloom_filter'
16+
require 'splitclient-rb/cache/filter/filter_adapter'
1517
require 'splitclient-rb/cache/hashers/impression_hasher'
1618
require 'splitclient-rb/cache/observers/impression_observer'
19+
require 'splitclient-rb/cache/observers/noop_impression_observer'
1720
require 'splitclient-rb/cache/repositories/repository'
1821
require 'splitclient-rb/cache/repositories/segments_repository'
1922
require 'splitclient-rb/cache/repositories/splits_repository'
@@ -28,6 +31,9 @@
2831
require 'splitclient-rb/cache/senders/events_sender'
2932
require 'splitclient-rb/cache/senders/impressions_count_sender'
3033
require 'splitclient-rb/cache/senders/localhost_repo_cleaner'
34+
require 'splitclient-rb/cache/senders/impressions_sender_adapter'
35+
require 'splitclient-rb/cache/senders/impressions_adapter/memory_sender'
36+
require 'splitclient-rb/cache/senders/impressions_adapter/redis_sender'
3137
require 'splitclient-rb/cache/stores/localhost_split_builder'
3238
require 'splitclient-rb/cache/stores/localhost_split_store'
3339
require 'splitclient-rb/cache/stores/store_utils'
@@ -43,7 +49,6 @@
4349
require 'splitclient-rb/split_factory_registry'
4450

4551
require 'splitclient-rb/engine/api/faraday_middleware/gzip'
46-
require 'splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent'
4752
require 'splitclient-rb/engine/api/client'
4853
require 'splitclient-rb/engine/api/impressions'
4954
require 'splitclient-rb/engine/api/segments'
@@ -52,6 +57,7 @@
5257
require 'splitclient-rb/engine/api/telemetry_api'
5358
require 'splitclient-rb/engine/common/impressions_counter'
5459
require 'splitclient-rb/engine/common/impressions_manager'
60+
require 'splitclient-rb/engine/common/noop_impressions_counter'
5561
require 'splitclient-rb/engine/parser/condition'
5662
require 'splitclient-rb/engine/parser/partition'
5763
require 'splitclient-rb/engine/parser/evaluator'
@@ -79,6 +85,8 @@
7985
require 'splitclient-rb/engine/matchers/equal_to_matcher'
8086
require 'splitclient-rb/engine/matchers/matches_string_matcher'
8187
require 'splitclient-rb/engine/evaluator/splitter'
88+
require 'splitclient-rb/engine/impressions/noop_unique_keys_tracker'
89+
require 'splitclient-rb/engine/impressions/unique_keys_tracker'
8290
require 'splitclient-rb/engine/metrics/binary_search_latency_tracker'
8391
require 'splitclient-rb/engine/models/split'
8492
require 'splitclient-rb/engine/models/label'

lib/splitclient-rb/cache/fetchers/segment_fetcher.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ def fetch_segments_if_not_exists(names, cache_control_headers = false)
3030
fetch_segment(name, fetch_options) if change_number == -1
3131
end
3232
end
33-
rescue StandardError => error
34-
@config.log_found_exception(__method__.to_s, error)
33+
rescue StandardError => e
34+
@config.log_found_exception(__method__.to_s, e)
3535
end
3636

3737
def fetch_segment(name, fetch_options = { cache_control_headers: false, till: nil })
3838
@semaphore.synchronize do
3939
segments_api.fetch_segments_by_names([name], fetch_options)
4040
end
41-
rescue StandardError => error
42-
@config.log_found_exception(__method__.to_s, error)
41+
rescue StandardError => e
42+
@config.log_found_exception(__method__.to_s, e)
4343
end
4444

4545
def fetch_segments
@@ -48,8 +48,8 @@ def fetch_segments
4848

4949
true
5050
end
51-
rescue StandardError => error
52-
@config.log_found_exception(__method__.to_s, error)
51+
rescue StandardError => e
52+
@config.log_found_exception(__method__.to_s, e)
5353
false
5454
end
5555

lib/splitclient-rb/cache/fetchers/split_fetcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def fetch_splits(fetch_options = { cache_control_headers: false, till: nil })
3636

3737
{ segment_names: data[:segment_names], success: true }
3838
end
39-
rescue StandardError => error
40-
@config.log_found_exception(__method__.to_s, error)
39+
rescue StandardError => e
40+
@config.log_found_exception(__method__.to_s, e)
4141
{ segment_names: [], success: false }
4242
end
4343

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
require 'bitarray'
4+
5+
module SplitIoClient
6+
module Cache
7+
module Filter
8+
class BloomFilter
9+
def initialize(capacity, false_positive_probability = 0.001)
10+
@capacity = capacity.round
11+
m = best_m(capacity, false_positive_probability)
12+
@ba = BitArray.new(m.round)
13+
@k = best_k(capacity)
14+
end
15+
16+
def add(string)
17+
return false if contains?(string)
18+
19+
positions = hashes(string)
20+
21+
positions.each { |position| @ba[position] = 1 }
22+
23+
true
24+
end
25+
26+
def contains?(string)
27+
!hashes(string).any? { |ea| @ba[ea] == 0 }
28+
end
29+
30+
def clear
31+
@ba.size.times { |i| @ba[i] = 0 }
32+
end
33+
34+
private
35+
36+
# m is the required number of bits in the array
37+
def best_m(capacity, false_positive_probability)
38+
-(capacity * Math.log(false_positive_probability)) / (Math.log(2) ** 2)
39+
end
40+
41+
# k is the number of hash functions that minimizes the probability of false positives
42+
def best_k(capacity)
43+
(Math.log(2) * (@ba.size / capacity)).round
44+
end
45+
46+
def hashes(data)
47+
m = @ba.size
48+
h = Digest::MD5.hexdigest(data.to_s).to_i(16)
49+
x = h % m
50+
h /= m
51+
y = h % m
52+
h /= m
53+
z = h % m
54+
[x] + 1.upto(@k - 1).collect do |i|
55+
x = (x + y) % m
56+
y = (y + z) % m
57+
x
58+
end
59+
end
60+
end
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)