From db9311aa39a290ed26c14586fc5adf2265a4a465 Mon Sep 17 00:00:00 2001 From: Bilal Al Date: Wed, 1 May 2024 10:05:47 -0700 Subject: [PATCH] updated query api order, fixed spec and added error to split logger --- lib/splitclient-rb/engine/api/splits.rb | 2 +- .../engine/matchers/between_semver_matcher.rb | 4 +-- .../matchers/equal_to_semver_matcher.rb | 4 +-- ...greater_than_or_equal_to_semver_matcher.rb | 4 +-- .../engine/matchers/in_list_semver_matcher.rb | 4 +-- .../less_than_or_equal_to_semver_matcher.rb | 4 +-- lib/splitclient-rb/split_logger.rb | 4 +++ .../semver_matchers_integration_spec.rb | 28 +++++++++++-------- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/splitclient-rb/engine/api/splits.rb b/lib/splitclient-rb/engine/api/splits.rb index b4d24a5e..b4d17bda 100644 --- a/lib/splitclient-rb/engine/api/splits.rb +++ b/lib/splitclient-rb/engine/api/splits.rb @@ -16,8 +16,8 @@ def since(since, fetch_options = { cache_control_headers: false, till: nil, sets start = Time.now params = { s: SplitIoClient::Spec::FeatureFlags::SPEC_VERSION, since: since } - params[:till] = fetch_options[:till] unless fetch_options[:till].nil? params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty? + params[:till] = fetch_options[:till] unless fetch_options[:till].nil? @config.logger.debug("Fetching from splitChanges with #{params}: ") response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, fetch_options[:cache_control_headers]) if response.status == 414 diff --git a/lib/splitclient-rb/engine/matchers/between_semver_matcher.rb b/lib/splitclient-rb/engine/matchers/between_semver_matcher.rb index e175c541..e5c2865e 100644 --- a/lib/splitclient-rb/engine/matchers/between_semver_matcher.rb +++ b/lib/splitclient-rb/engine/matchers/between_semver_matcher.rb @@ -16,7 +16,7 @@ def initialize(attribute, start_value, end_value, logger, validator) end def match?(args) - @logger.debug('[BetweenSemverMatcher] evaluating value and attributes.') + @logger.log_if_debug('[BetweenSemverMatcher] evaluating value and attributes.') return false unless @validator.valid_matcher_arguments(args) value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger) @@ -26,7 +26,7 @@ def match?(args) end matches = ([0, -1].include?(@semver_start.compare(value_to_match)) && [0, 1].include?(@semver_end.compare(value_to_match))) - @logger.debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}") + @logger.log_if_debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}") matches end end diff --git a/lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb b/lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb index c77f78a1..49151599 100644 --- a/lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb +++ b/lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb @@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator) end def match?(args) - @logger.debug('[EqualsToSemverMatcher] evaluating value and attributes.') + @logger.log_if_debug('[EqualsToSemverMatcher] evaluating value and attributes.') return false unless @validator.valid_matcher_arguments(args) value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger) @@ -24,7 +24,7 @@ def match?(args) return false end matches = (@semver.version == value_to_match.version) - @logger.debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}") + @logger.log_if_debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}") matches end end diff --git a/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher.rb b/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher.rb index ffe46aef..6eef18ff 100644 --- a/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher.rb +++ b/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher.rb @@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator) end def match?(args) - @logger.debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.') + @logger.log_if_debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.') return false unless @validator.valid_matcher_arguments(args) value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger) @@ -24,7 +24,7 @@ def match?(args) return false end matches = [0, 1].include?(value_to_match.compare(@semver)) - @logger.debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}") + @logger.log_if_debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}") matches end end diff --git a/lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb b/lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb index 298bc0b0..45db3052 100644 --- a/lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb +++ b/lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb @@ -15,7 +15,7 @@ def initialize(attribute, list_value, logger, validator) end def match?(args) - @logger.debug('[InListSemverMatcher] evaluating value and attributes.') + @logger.log_if_debug('[InListSemverMatcher] evaluating value and attributes.') return false unless @validator.valid_matcher_arguments(args) && args[:attributes][@attribute.to_sym].is_a?(String) value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger) @@ -24,7 +24,7 @@ def match?(args) return false end matches = (@semver_list.map { |item| item.version == value_to_match.version }).any? { |item| item == true } - @logger.debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}") + @logger.log_if_debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}") matches end end diff --git a/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher.rb b/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher.rb index 081a7317..2dd8ff36 100644 --- a/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher.rb +++ b/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher.rb @@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator) end def match?(args) - @logger.debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.') + @logger.log_if_debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.') return false unless @validator.valid_matcher_arguments(args) value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger) @@ -24,7 +24,7 @@ def match?(args) return false end matches = [0, -1].include?(value_to_match.compare(@semver)) - @logger.debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}") + @logger.log_if_debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}") matches end end diff --git a/lib/splitclient-rb/split_logger.rb b/lib/splitclient-rb/split_logger.rb index 5a82b0ce..bf7a899e 100644 --- a/lib/splitclient-rb/split_logger.rb +++ b/lib/splitclient-rb/split_logger.rb @@ -11,5 +11,9 @@ def log_if_debug(message) def log_if_transport(message) @config.logger.debug(message) if @config.transport_debug_enabled end + + def error(message) + @config.logger.error(message) + end end end diff --git a/spec/engine/matchers/semver_matchers_integration_spec.rb b/spec/engine/matchers/semver_matchers_integration_spec.rb index bedb07aa..9b5a7858 100644 --- a/spec/engine/matchers/semver_matchers_integration_spec.rb +++ b/spec/engine/matchers/semver_matchers_integration_spec.rb @@ -43,15 +43,19 @@ let(:user) { 'fake_user_id_1' } before do - stub_request(:any, /https:\/\/telemetry.*/).to_return(status: 200, body: 'ok') - stub_request(:any, /https:\/\/events.*/).to_return(status: 200, body: "", headers: {}) + stub_request(:any, /https:\/\/telemetry\.*/).to_return(status: 200, body: 'ok') + stub_request(:any, /https:\/\/events\.*/).to_return(status: 200, body: "", headers: {}) + stub_request(:any, /https:\/\/metrics\.*/).to_return(status: 200, body: "", headers: {}) + stub_request(:post, "https://telemetry.split.io/api/v1/metrics/config").to_return(status: 200, body: "", headers: {}) end context 'equal to matcher' do before do - stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/) + stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since\.*/) .to_return(status: 200, body: semver_equalto_matcher_splits) - stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1') + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') + .to_return(status: 200, body: semver_equalto_matcher_splits) + stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.1&since=1675259356568") .to_return(status: 200, body: semver_equalto_matcher_splits) sleep 1 subject.block_until_ready @@ -70,9 +74,9 @@ context 'greater than or equal to matcher' do before do - stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/) + stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/) .to_return(status: 200, body: semver_greater_or_equalto_matcher_splits) - stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1') + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') .to_return(status: 200, body: semver_greater_or_equalto_matcher_splits) sleep 1 subject.block_until_ready @@ -92,9 +96,9 @@ context 'less than or equal to matcher' do before do - stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/) + stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/) .to_return(status: 200, body: semver_less_or_equalto_matcher_splits) - stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1') + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') .to_return(status: 200, body: semver_less_or_equalto_matcher_splits) sleep 1 subject.block_until_ready @@ -114,9 +118,9 @@ context 'in list matcher' do before do - stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/) + stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/) .to_return(status: 200, body: semver_inlist_matcher_splits) - stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1') + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') .to_return(status: 200, body: semver_inlist_matcher_splits) sleep 1 subject.block_until_ready @@ -136,9 +140,9 @@ context 'between matcher' do before do - stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/) + stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/) .to_return(status: 200, body: semver_between_matcher_splits) - stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1') + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') .to_return(status: 200, body: semver_between_matcher_splits) sleep 1 subject.block_until_ready