Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7a28587
UniqueKeysTracker implementation and tests
sanzmauro Mar 23, 2022
0eb8e08
added more tests
sanzmauro Mar 23, 2022
5c8b776
Merge pull request #414 from splitio/unique-keys-tracker-imp
sanzmauro Mar 23, 2022
7ceb7fb
Implemented telemetry_api.record_unique_keys
sanzmauro Mar 23, 2022
76bc95e
Merge pull request #415 from splitio/add-mtks-ss-request
sanzmauro Mar 23, 2022
ba7663d
added NONE impression mode.
sanzmauro Mar 23, 2022
9045106
Merge pull request #416 from splitio/add-none-config
sanzmauro Mar 23, 2022
5362a04
updated ImpressionManager to start to tracking unique keys
sanzmauro Mar 23, 2022
5aa541c
fixed rubocop
sanzmauro Mar 30, 2022
fef9a84
Merge pull request #417 from splitio/update-impression-manager
sanzmauro Mar 30, 2022
0baa6a4
Dedupe logic with Redis Adapter
sanzmauro Mar 30, 2022
53c9d2b
Fixed and Added tests
sanzmauro Mar 30, 2022
1416bd7
Implemented component to write the bulk of mtks in redis
sanzmauro Apr 4, 2022
a473a92
polishing
sanzmauro Apr 4, 2022
a11af60
Merge pull request #420 from splitio/redis-write-bulk-mtks
sanzmauro Apr 5, 2022
38b9013
Merge pull request #419 from splitio/redis-deduping-logic-tests
sanzmauro Apr 5, 2022
5cc0fa0
Merge pull request #418 from splitio/redis-deduping-logic
sanzmauro Apr 5, 2022
cfcaa3f
wip
sanzmauro Apr 5, 2022
5939cb7
improvements and set correctly the expire time for keys in redis
sanzmauro Apr 6, 2022
5b5e26d
Merge pull request #421 from splitio/polishing
sanzmauro Apr 6, 2022
d8f179e
custom Bloom filter implementation
sanzmauro Apr 7, 2022
0a4db7b
cleanup code
sanzmauro Apr 7, 2022
fa3664b
Merge pull request #422 from splitio/custom-bloomfilter
sanzmauro Apr 8, 2022
a2014c3
polishing
sanzmauro Apr 18, 2022
0f907cd
using ruby/setup-ruby@v1 setup
sanzmauro Apr 18, 2022
2a55426
undo ci.yml
sanzmauro Apr 19, 2022
60d8d84
debug tests in ci
sanzmauro Apr 19, 2022
fd54c60
debug tests
sanzmauro Apr 19, 2022
200539a
debug ci.yml
sanzmauro Apr 19, 2022
de5a44a
debug
sanzmauro Apr 19, 2022
d1fd8ec
fixed build
sanzmauro Apr 19, 2022
de00641
fixed tests
sanzmauro Apr 19, 2022
ddac87a
using hset instead of rpush
sanzmauro Apr 19, 2022
675b08c
added expire time
sanzmauro Apr 20, 2022
83dc0bc
Revert "added expire time"
sanzmauro Apr 20, 2022
f253f6e
redis: force to debug mode. inMemory: accept only debug or optimized …
sanzmauro Apr 19, 2022
331cbbb
updated ci to run always
sanzmauro Apr 20, 2022
f8d705f
pr feedback
sanzmauro Apr 20, 2022
0db9067
Merge pull request #428 from splitio/block-none-impression-mode
sanzmauro Apr 20, 2022
1406b31
Merge pull request #427 from splitio/move-rpush-to-hset-init
sanzmauro Apr 20, 2022
a1bbd13
renamed mtks to keys
sanzmauro Apr 27, 2022
6056481
Merge pull request #430 from splitio/update-endpoint
sanzmauro May 2, 2022
30b92b9
- set required_ruby_version
sanzmauro May 2, 2022
9e8bfa4
updated version
sanzmauro May 2, 2022
155b6d8
Merge pull request #431 from splitio/deprecate-old-versions
sanzmauro May 4, 2022
59016fd
debugging ci jobs
sanzmauro May 4, 2022
05b6ebf
debug ci.yml
sanzmauro May 4, 2022
f723483
upgrade rubocop and fixed build
sanzmauro May 4, 2022
ef1261f
updated readme
sanzmauro May 9, 2022
095d76c
fixed rubocop
sanzmauro May 9, 2022
2e756bf
rubocop 1.28.2
sanzmauro May 9, 2022
56d48ad
Merge pull request #432 from splitio/ci-job-31
sanzmauro May 9, 2022
8e884c1
updated version and changes.txt
sanzmauro May 10, 2022
b982b6b
pr feedback
sanzmauro May 10, 2022
3c690ca
Merge pull request #433 from splitio/release-8.0.0
sanzmauro May 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
on: [push, pull_request]

jobs:
test:
Expand All @@ -14,16 +8,20 @@ jobs:
image: redis
ports:
- 6379:6379
strategy:
matrix:
ruby: [ '2.5.0', '3.1.1' ]

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Ruby
uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
ruby-version: ${{ matrix.ruby }}

- name: Install dependencies
run: bundle install
Expand Down
35 changes: 20 additions & 15 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,7 @@ Metrics/ParameterLists:
- lib/splitclient-rb/engine/sync_manager.rb

Metrics/LineLength:
Max: 130
Exclude:
- spec/sse/**/*
- spec/integrations/**/*
- spec/engine/sync_manager_spec.rb
- spec/engine/auth_api_client_spec.rb
- spec/telemetry/synchronizer_spec.rb
- spec/splitclient/split_config_spec.rb
- spec/engine/push_manager_spec.rb

Style/BracesAroundHashParameters:
Exclude:
- spec/integrations/push_client_spec.rb
- spec/engine/synchronizer_spec.rb
Max: 135

Metrics/BlockLength:
Exclude:
Expand All @@ -50,8 +37,24 @@ Naming/FileName:
Exclude:
- splitclient-rb.gemspec

Style/OptionalBooleanParameter:
Exclude:
- lib/splitclient-rb/engine/matchers/between_matcher.rb
- lib/splitclient-rb/engine/matchers/combining_matcher.rb
- lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
- lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
- lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb

Style/HashTransformKeys:
Exclude:
- lib/splitclient-rb/engine/matchers/combining_matcher.rb

Style/RedundantReturn:
Exclude:
- lib/splitclient-rb/engine/common/impressions_manager.rb

AllCops:
TargetRubyVersion: 2.3.6
TargetRubyVersion: 2.5
Exclude:
- gemfiles/* # excluded as appraisal generates them with errors
- lib/*
Expand All @@ -69,3 +72,5 @@ AllCops:
- lib/splitclient-rb/engine/synchronizer.rb
- tmp/**/*
- lib/splitclient-rb/sse/event_source/client.rb
- spec/**/*
- .simplecov
10 changes: 0 additions & 10 deletions Appraisals

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
CHANGES

8.0.0 (May 10, 2022)
- BREAKING CHANGE: Deprecated support for ruby 2.3 and 2.4 versions. The minimum ruby version required is 2.5 now.
- Updated redis command for config telemetry, using hset instead of rpush now.
- Updated dependencies:
- rake to ~> 13.0
- faraday to >= 1.1, < 2.0

7.3.4 (Feb 21, 2022)
- Updated streaming events architecture with a new queue logic.
- Fixed redis integration Pipelining command deprecation warning.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Split SDK for Ruby
[![Build Status](https://travis-ci.com/splitio/ruby-client.svg?branch=master)](https://travis-ci.com/splitio/ruby-client)
![Build Status](https://github.com/splitio/ruby-client/actions/workflows/ci.yml/badge.svg?branch=master)

## Overview
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.

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

## Compatibility
The Ruby SDK support Ruby version 2.3.0 or later and JRuby or 9.1.17 o later.
The Ruby SDK support Ruby version 2.5.0 or later and JRuby or 9.1.17 o later.

Also the Ruby SDK has been tested as a standalone app as well as using the following web servers:
- Puma
Expand Down
9 changes: 1 addition & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'appraisal'

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

Expand All @@ -26,10 +25,4 @@ else
end
end

if !ENV['APPRAISAL_INITIALIZED']
task :default do
sh 'appraisal install && rake appraisal && rake rubocop'
end
else
task default: %i[spec rubocop]
end
task default: %i[spec rubocop]
10 changes: 9 additions & 1 deletion lib/splitclient-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
require 'splitclient-rb/cache/adapters/redis_adapter'
require 'splitclient-rb/cache/fetchers/segment_fetcher'
require 'splitclient-rb/cache/fetchers/split_fetcher'
require 'splitclient-rb/cache/filter/bloom_filter'
require 'splitclient-rb/cache/filter/filter_adapter'
require 'splitclient-rb/cache/hashers/impression_hasher'
require 'splitclient-rb/cache/observers/impression_observer'
require 'splitclient-rb/cache/observers/noop_impression_observer'
require 'splitclient-rb/cache/repositories/repository'
require 'splitclient-rb/cache/repositories/segments_repository'
require 'splitclient-rb/cache/repositories/splits_repository'
Expand All @@ -28,6 +31,9 @@
require 'splitclient-rb/cache/senders/events_sender'
require 'splitclient-rb/cache/senders/impressions_count_sender'
require 'splitclient-rb/cache/senders/localhost_repo_cleaner'
require 'splitclient-rb/cache/senders/impressions_sender_adapter'
require 'splitclient-rb/cache/senders/impressions_adapter/memory_sender'
require 'splitclient-rb/cache/senders/impressions_adapter/redis_sender'
require 'splitclient-rb/cache/stores/localhost_split_builder'
require 'splitclient-rb/cache/stores/localhost_split_store'
require 'splitclient-rb/cache/stores/store_utils'
Expand All @@ -43,7 +49,6 @@
require 'splitclient-rb/split_factory_registry'

require 'splitclient-rb/engine/api/faraday_middleware/gzip'
require 'splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent'
require 'splitclient-rb/engine/api/client'
require 'splitclient-rb/engine/api/impressions'
require 'splitclient-rb/engine/api/segments'
Expand All @@ -52,6 +57,7 @@
require 'splitclient-rb/engine/api/telemetry_api'
require 'splitclient-rb/engine/common/impressions_counter'
require 'splitclient-rb/engine/common/impressions_manager'
require 'splitclient-rb/engine/common/noop_impressions_counter'
require 'splitclient-rb/engine/parser/condition'
require 'splitclient-rb/engine/parser/partition'
require 'splitclient-rb/engine/parser/evaluator'
Expand Down Expand Up @@ -79,6 +85,8 @@
require 'splitclient-rb/engine/matchers/equal_to_matcher'
require 'splitclient-rb/engine/matchers/matches_string_matcher'
require 'splitclient-rb/engine/evaluator/splitter'
require 'splitclient-rb/engine/impressions/noop_unique_keys_tracker'
require 'splitclient-rb/engine/impressions/unique_keys_tracker'
require 'splitclient-rb/engine/metrics/binary_search_latency_tracker'
require 'splitclient-rb/engine/models/split'
require 'splitclient-rb/engine/models/label'
Expand Down
12 changes: 6 additions & 6 deletions lib/splitclient-rb/cache/fetchers/segment_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def fetch_segments_if_not_exists(names, cache_control_headers = false)
fetch_segment(name, fetch_options) if change_number == -1
end
end
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end

def fetch_segment(name, fetch_options = { cache_control_headers: false, till: nil })
@semaphore.synchronize do
segments_api.fetch_segments_by_names([name], fetch_options)
end
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end

def fetch_segments
Expand All @@ -48,8 +48,8 @@ def fetch_segments

true
end
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
false
end

Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/cache/fetchers/split_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def fetch_splits(fetch_options = { cache_control_headers: false, till: nil })

{ segment_names: data[:segment_names], success: true }
end
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
{ segment_names: [], success: false }
end

Expand Down
63 changes: 63 additions & 0 deletions lib/splitclient-rb/cache/filter/bloom_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require 'bitarray'

module SplitIoClient
module Cache
module Filter
class BloomFilter
def initialize(capacity, false_positive_probability = 0.001)
@capacity = capacity.round
m = best_m(capacity, false_positive_probability)
@ba = BitArray.new(m.round)
@k = best_k(capacity)
end

def add(string)
return false if contains?(string)

positions = hashes(string)

positions.each { |position| @ba[position] = 1 }

true
end

def contains?(string)
!hashes(string).any? { |ea| @ba[ea] == 0 }
end

def clear
@ba.size.times { |i| @ba[i] = 0 }
end

private

# m is the required number of bits in the array
def best_m(capacity, false_positive_probability)
-(capacity * Math.log(false_positive_probability)) / (Math.log(2) ** 2)
end

# k is the number of hash functions that minimizes the probability of false positives
def best_k(capacity)
(Math.log(2) * (@ba.size / capacity)).round
end

def hashes(data)
m = @ba.size
h = Digest::MD5.hexdigest(data.to_s).to_i(16)
x = h % m
h /= m
y = h % m
h /= m
z = h % m
[x] + 1.upto(@k - 1).collect do |i|
x = (x + y) % m
y = (y + z) % m
x
end
end
end
end
end
end
32 changes: 32 additions & 0 deletions lib/splitclient-rb/cache/filter/filter_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module SplitIoClient
module Cache
module Filter
class FilterAdapter
def initialize(config, filter)
@config = config
@filter = filter
end

def add(feature_name, key)
@filter.add("#{feature_name}#{key}")
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end

def contains?(feature_name, key)
@filter.contains?("#{feature_name}#{key}")
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end

def clear
@filter.clear
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end
end
end
end
end
10 changes: 10 additions & 0 deletions lib/splitclient-rb/cache/observers/noop_impression_observer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module SplitIoClient
module Observers
class NoopImpressionObserver
def test_and_set(impression)
# no-op
end
end
end
end

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def add(key, traffic_type, event_type, time, value, properties, event_size)
post_events if @size >= EVENTS_MAX_SIZE_BYTES || @adapter.length == @config.events_queue_size

@telemetry_runtime_producer.record_events_stats(Telemetry::Domain::Constants::EVENTS_QUEUED, 1)
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
@telemetry_runtime_producer.record_events_stats(Telemetry::Domain::Constants::EVENTS_DROPPED, 1)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/cache/repositories/events_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def initialize(config, api_key, telemetry_runtime_producer)

def post_events
events_api.post(self.clear)
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end

protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def segment_keys_count
end

keys
rescue StandardError => error
@config.log_found_exception(__method__.to_s, error)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
0
end

Expand Down
Loading