Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flagsets merge to dev #501

Merged
merged 39 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2c32af6
Merge pull request #480 from splitio/development
sanzmauro Jul 18, 2023
e9129d2
updated engine.api.splits class
chillaq Oct 20, 2023
fdc88cc
added exception for 409 status code
chillaq Oct 21, 2023
b4b43dc
added flag_set_filter config param and validation
chillaq Oct 23, 2023
70b3436
updated error code
chillaq Oct 24, 2023
3908a97
Merge pull request #483 from splitio/flagsets-engine-api
chillaq Oct 24, 2023
bd9e669
fixed regex
chillaq Oct 24, 2023
b838d78
updated telemetry classes
chillaq Oct 24, 2023
f1b88f0
Merge pull request #484 from splitio/flagset-client-config
chillaq Oct 27, 2023
0ce3a2a
Merge pull request #485 from splitio/flagset-telemetry
chillaq Oct 27, 2023
06db54c
update client class and fixed tests
chillaq Nov 3, 2023
94b350c
added updates from other prs
chillaq Nov 3, 2023
b6f302f
polishing
chillaq Nov 6, 2023
27af19d
Merge pull request #488 from splitio/flagset-client-splitclient
chillaq Nov 10, 2023
d0a03e2
refactor evaluator with splitclient
chillaq Nov 10, 2023
554508e
fixed typo
chillaq Nov 10, 2023
1bc870f
polishing with test
chillaq Nov 13, 2023
eb72e1c
Fixed rubocop offenses
chillaq Nov 14, 2023
5be6722
Merge pull request #493 from splitio/flagset-evaluator-refactor
chillaq Nov 16, 2023
f87ab3d
Updated all specs plus minor fixes
chillaq Nov 17, 2023
1d8864c
Merge pull request #495 from splitio/flagset-specs
chillaq Nov 27, 2023
da38227
Added redis flag set repo and validation cleanup
chillaq Nov 27, 2023
7ac3a85
used redis piplined and updated flag_set repositories to fetch array
chillaq Nov 28, 2023
31b59f6
Merge pull request #497 from splitio/flagset-redis-cache
chillaq Nov 29, 2023
6a228af
Added support for SSE and minor fix in updating split repository
chillaq Nov 29, 2023
5c5be71
Merge pull request #498 from splitio/flagset-sse-splitworker
chillaq Nov 30, 2023
3f753bb
removed SortedSet and inlcude 'set'
chillaq Dec 1, 2023
c04381b
Merge pull request #499 from splitio/flagset-remove-sortedset
chillaq Dec 4, 2023
dd99e35
Added sets to manager split view dict
chillaq Dec 4, 2023
642ae8e
return empty list when nil sets
chillaq Dec 4, 2023
e7c82f5
Merge pull request #500 from splitio/flagsets-manager-splitview
sanzmauro Dec 4, 2023
dc9f3c0
merge flagset build
chillaq Dec 7, 2023
9d9d4fb
Merge branch 'development' into flagsets-merge-to-dev
chillaq Dec 7, 2023
818d219
Update CHANGES.txt
chillaq Dec 7, 2023
b5b549d
fix rubocop offense
chillaq Dec 7, 2023
3c0e2e3
cleanup
chillaq Dec 7, 2023
c468069
fixed engine_spec for ruby 3.x
chillaq Dec 7, 2023
bec1e81
fixed typo in telemetry record latency
chillaq Dec 7, 2023
c8e27a9
fixed typo and cleanup
chillaq Dec 7, 2023
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
Prev Previous commit
Next Next commit
Added support for SSE and minor fix in updating split repository
  • Loading branch information
chillaq committed Nov 29, 2023
commit 6a228af9a0079029adc9ca434bf1e7aa1b52cc6c
8 changes: 6 additions & 2 deletions lib/splitclient-rb/cache/repositories/splits_repository.rb
Original file line number Diff line number Diff line change
@@ -151,6 +151,8 @@ def add_feature_flag(split)
increase_tt_name_count(split[:trafficTypeName])
decrease_tt_name_count(existing_split[:trafficTypeName])
remove_from_flag_sets(existing_split)
elsif(existing_split[:sets] != split[:sets])
remove_from_flag_sets(existing_split)
end

if !split[:sets].nil?
@@ -193,8 +195,10 @@ def get_splits(names, symbolize_names = true)
end

def remove_from_flag_sets(feature_flag)
if !feature_flag[:sets].nil?
for flag_set in feature_flag[:sets]
name = feature_flag[:name]
flag_sets = get_split(name)[:sets] if exists?(name)
if !flag_sets.nil?
for flag_set in flag_sets
@flag_sets.remove_feature_flag_from_flag_set(flag_set, feature_flag[:name])
if is_flag_set_exist(flag_set) && @flag_sets.get_flag_sets([flag_set]).length == 0 && !@flag_set_filter.should_filter?
@flag_sets.remove_flag_set(flag_set)
3 changes: 2 additions & 1 deletion lib/splitclient-rb/engine/api/splits.rb
Original file line number Diff line number Diff line change
@@ -8,14 +8,15 @@ def initialize(api_key, config, telemetry_runtime_producer)
super(config)
@api_key = api_key
@telemetry_runtime_producer = telemetry_runtime_producer
@flag_sets_filter = @config.flag_sets_filter
end

def since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil })
start = Time.now

params = { since: since }
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
params[:sets] = fetch_options[:sets].join(",") unless fetch_options[:sets].nil?
params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, fetch_options[:cache_control_headers])
if response.status == 414
@config.logger.error("Error fetching feature flags; the amount of flag sets provided are too big, causing uri length error.")
13 changes: 2 additions & 11 deletions lib/splitclient-rb/sse/workers/splits_worker.rb
Original file line number Diff line number Diff line change
@@ -66,17 +66,9 @@ def update_feature_flag(notification)
return false unless !notification.data['d'].nil? && @feature_flags_repository.get_change_number == notification.data['pcn']

new_split = return_split_from_json(notification)
to_add = []
to_delete = []
if Engine::Models::Split.archived?(new_split)
to_delete.push(new_split)
else
to_add.push(new_split)

fetch_segments_if_not_exists(new_split)
end
SplitIoClient::Helpers::RepositoryHelper.update_feature_flag_repository(@feature_flags_repository, [new_split], notification.data['changeNumber'], @config)
fetch_segments_if_not_exists(new_split)

@feature_flags_repository.update(to_add, to_delete, notification.data['changeNumber'])
@telemetry_runtime_producer.record_updates_from_sse(Telemetry::Domain::Constants::SPLITS)

true
@@ -100,7 +92,6 @@ def kill_feature_flag(notification)

def return_split_from_json(notification)
split_json = Helpers::DecryptionHelper.get_encoded_definition(notification.data['c'], notification.data['d'])

JSON.parse(split_json, symbolize_names: true)
end

9 changes: 7 additions & 2 deletions spec/cache/fetchers/split_fetch_spec.rb
Original file line number Diff line number Diff line change
@@ -80,6 +80,11 @@
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }
let(:store) { described_class.new(splits_repository, '', config, telemetry_runtime_producer) }

before do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_2&since=-1')
.to_return(status: 200, body: active_splits_json)
end

it 'returns splits since' do
splits = store.send(:splits_since, -1)

@@ -98,14 +103,14 @@
expect(store.splits_repository.get_split('sample_feature')[:name]).to eq('sample_feature')
expect(store.splits_repository.get_split('test_1_ruby')).to eq(nil)

stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=1473413807667')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_2&since=1473413807667')
.to_return(status: 200, body: archived_splits_json)

store.send(:fetch_splits)
expect(store.splits_repository.get_split('sample_feature')).to eq(nil)

store.splits_repository.set_change_number(-1)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_2&since=-1')
.to_return(status: 200, body: active_splits_json)

store.send(:fetch_splits)
67 changes: 34 additions & 33 deletions spec/engine/api/splits_spec.rb
Original file line number Diff line number Diff line change
@@ -3,20 +3,20 @@
require 'spec_helper'

describe SplitIoClient::Api::Splits do
let(:config) do
SplitIoClient::SplitConfig.new(
logger: Logger.new(log),
debug_enabled: true,
transport_debug_enabled: true
)
end

let(:log) { StringIO.new }
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }
let(:splits) { File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../test_data/splits/splits.json'))) }

context '#splits_with_segment_names' do
let(:config) do
SplitIoClient::SplitConfig.new(
logger: Logger.new(log),
debug_enabled: true,
transport_debug_enabled: true
)
end
let(:log) { StringIO.new }
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }

it 'returns splits with segment names' do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
.to_return(status: 200, body: splits)
@@ -28,28 +28,20 @@
end

context '#sets' do
it 'returns the splits - with sets param' do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1&sets=set_1')
.with(headers: {
'Accept' => '*/*',
'Accept-Encoding' => 'gzip',
'Authorization' => 'Bearer',
'Connection' => 'keep-alive',
'Keep-Alive' => '30',
'Splitsdkversion' => "#{config.language}-#{config.version}"
})
.to_return(status: 200, body: splits)

fetch_options = { cache_control_headers: false, till: nil, sets: ['set_1'] }
returned_splits = splits_api.since(-1, fetch_options)
expect(returned_splits[:segment_names]).to eq(Set.new(%w[demo employees]))

expect(log.string).to include '2 feature flags retrieved. since=-1'
expect(log.string).to include returned_splits.to_s
let(:config) do
SplitIoClient::SplitConfig.new(
logger: Logger.new(log),
debug_enabled: true,
transport_debug_enabled: true,
flag_sets_filter: ['set_1', 'set_2']
)
end
let(:log) { StringIO.new }
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }

it 'returns the splits - with 2 sets param' do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1&sets=set_1,set_2')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_1,set_2&since=-1')
.with(headers: {
'Accept' => '*/*',
'Accept-Encoding' => 'gzip',
@@ -69,7 +61,7 @@
end

it 'raise api exception when status 414' do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1&sets=set_1,set_2')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_1,set_2&since=-1')
.with(headers: {
'Accept' => '*/*',
'Accept-Encoding' => 'gzip',
@@ -89,11 +81,20 @@
end
expect(captured).to eq(414)
end


end

context '#since' do
let(:config) do
SplitIoClient::SplitConfig.new(
logger: Logger.new(log),
debug_enabled: true,
transport_debug_enabled: true
)
end
let(:log) { StringIO.new }
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }

it 'returns the splits - checking headers when cache_control_headers is false' do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
.with(headers: {
2 changes: 1 addition & 1 deletion spec/integrations/in_memory_client_spec.rb
Original file line number Diff line number Diff line change
@@ -1141,7 +1141,7 @@
flag_sets_filter: ['set_3', '@3we'])
end
before do
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_3&since=-1')
.to_return(status: 200, body: splits)
mock_segment_changes('segment1', segment1, '-1')
mock_segment_changes('segment1', segment1, '1470947453877')
72 changes: 36 additions & 36 deletions spec/integrations/redis_client_spec.rb
Original file line number Diff line number Diff line change
@@ -606,17 +606,17 @@
expect(impressions[0][:treatment][:label]).to eq('whitelisted')
expect(impressions[0][:treatment][:change_number]).to eq(1_506_703_262_916)

expect(impressions[2][:matching_key]).to eq('nico_test')
expect(impressions[2][:split_name]).to eq(:testing)
expect(impressions[2][:treatment][:treatment]).to eq('off')
expect(impressions[2][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[2][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[1][:matching_key]).to eq('nico_test')
expect(impressions[1][:split_name]).to eq(:testing222)
expect(impressions[1][:split_name]).to eq(:testing)
expect(impressions[1][:treatment][:treatment]).to eq('off')
expect(impressions[1][:treatment][:label]).to eq('in segment all')
expect(impressions[1][:treatment][:change_number]).to eq(1_505_162_627_437)
expect(impressions[1][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[1][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[2][:matching_key]).to eq('nico_test')
expect(impressions[2][:split_name]).to eq(:testing222)
expect(impressions[2][:treatment][:treatment]).to eq('off')
expect(impressions[2][:treatment][:label]).to eq('in segment all')
expect(impressions[2][:treatment][:change_number]).to eq(1_505_162_627_437)
end

it 'returns treatments with input validation' do
@@ -700,17 +700,17 @@
expect(impressions[2][:treatment][:label]).to eq('whitelisted')
expect(impressions[2][:treatment][:change_number]).to eq(1_506_703_262_916)

expect(impressions[1][:matching_key]).to eq('nico_test')
expect(impressions[1][:split_name]).to eq(:testing)
expect(impressions[1][:treatment][:treatment]).to eq('off')
expect(impressions[1][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[1][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[0][:matching_key]).to eq('nico_test')
expect(impressions[0][:split_name]).to eq(:testing222)
expect(impressions[0][:split_name]).to eq(:testing)
expect(impressions[0][:treatment][:treatment]).to eq('off')
expect(impressions[0][:treatment][:label]).to eq('in segment all')
expect(impressions[0][:treatment][:change_number]).to eq(1_505_162_627_437)
expect(impressions[0][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[0][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[1][:matching_key]).to eq('nico_test')
expect(impressions[1][:split_name]).to eq(:testing222)
expect(impressions[1][:treatment][:treatment]).to eq('off')
expect(impressions[1][:treatment][:label]).to eq('in segment all')
expect(impressions[1][:treatment][:change_number]).to eq(1_505_162_627_437)
end

it 'returns treatments with input validation' do
@@ -792,17 +792,17 @@
expect(impressions[0][:treatment][:label]).to eq('whitelisted')
expect(impressions[0][:treatment][:change_number]).to eq(1_506_703_262_916)

expect(impressions[2][:matching_key]).to eq('nico_test')
expect(impressions[2][:split_name]).to eq(:testing)
expect(impressions[2][:treatment][:treatment]).to eq('off')
expect(impressions[2][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[2][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[1][:matching_key]).to eq('nico_test')
expect(impressions[1][:split_name]).to eq(:testing222)
expect(impressions[1][:split_name]).to eq(:testing)
expect(impressions[1][:treatment][:treatment]).to eq('off')
expect(impressions[1][:treatment][:label]).to eq('in segment all')
expect(impressions[1][:treatment][:change_number]).to eq(1_505_162_627_437)
expect(impressions[1][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[1][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[2][:matching_key]).to eq('nico_test')
expect(impressions[2][:split_name]).to eq(:testing222)
expect(impressions[2][:treatment][:treatment]).to eq('off')
expect(impressions[2][:treatment][:label]).to eq('in segment all')
expect(impressions[2][:treatment][:change_number]).to eq(1_505_162_627_437)
end

it 'returns treatments with input validation' do
@@ -886,17 +886,17 @@
expect(impressions[2][:treatment][:label]).to eq('whitelisted')
expect(impressions[2][:treatment][:change_number]).to eq(1_506_703_262_916)

expect(impressions[1][:matching_key]).to eq('nico_test')
expect(impressions[1][:split_name]).to eq(:testing)
expect(impressions[1][:treatment][:treatment]).to eq('off')
expect(impressions[1][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[1][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[0][:matching_key]).to eq('nico_test')
expect(impressions[0][:split_name]).to eq(:testing222)
expect(impressions[0][:split_name]).to eq(:testing)
expect(impressions[0][:treatment][:treatment]).to eq('off')
expect(impressions[0][:treatment][:label]).to eq('in segment all')
expect(impressions[0][:treatment][:change_number]).to eq(1_505_162_627_437)
expect(impressions[0][:treatment][:label]).to eq('in split test_definition_as_of treatment [off]')
expect(impressions[0][:treatment][:change_number]).to eq(1_506_440_189_077)

expect(impressions[1][:matching_key]).to eq('nico_test')
expect(impressions[1][:split_name]).to eq(:testing222)
expect(impressions[1][:treatment][:treatment]).to eq('off')
expect(impressions[1][:treatment][:label]).to eq('in segment all')
expect(impressions[1][:treatment][:change_number]).to eq(1_505_162_627_437)
end

it 'returns treatments with input validation' do
Loading