@@ -43,7 +43,6 @@ def since(since, since_rbs, fetch_options = { cache_control_headers: false, till
43
43
params [ :till ] = fetch_options [ :till ] unless fetch_options [ :till ] . nil?
44
44
@config . logger . debug ( "Fetching from splitChanges with #{ params } : " )
45
45
response = get_api ( "#{ @config . base_uri } /splitChanges" , @api_key , params , fetch_options [ :cache_control_headers ] )
46
-
47
46
if response . status == 414
48
47
@config . logger . error ( "Error fetching feature flags; the amount of flag sets provided are too big, causing uri length error." )
49
48
raise ApiException . new response . body , 414
@@ -56,44 +55,17 @@ def since(since, since_rbs, fetch_options = { cache_control_headers: false, till
56
55
return since ( since , 0 , fetch_options = { cache_control_headers : fetch_options [ :cache_control_headers ] , till : fetch_options [ :till ] ,
57
56
sets : fetch_options [ :sets ] } )
58
57
end
59
-
60
58
if response . success?
61
59
result = JSON . parse ( response . body , symbolize_names : true )
62
- if @spec_version == Splits ::SPEC_1_1
63
- result = convert_to_new_spec ( result )
64
- end
65
-
66
- result [ :rbs ] [ :d ] = check_rbs_data ( result [ :rbs ] [ :d ] )
67
- result = objects_with_segment_names ( result )
68
-
69
- if @spec_version == SplitIoClient ::Spec ::FeatureFlags ::SPEC_VERSION
70
- @clear_storage = @last_proxy_check_timestamp != 0
71
- @last_proxy_check_timestamp = 0
72
- end
73
-
74
- unless result [ :ff ] [ :d ] . empty?
75
- @config . split_logger . log_if_debug ( "#{ result [ :ff ] [ :d ] . length } feature flags retrieved. since=#{ since } " )
76
- end
77
- @config . split_logger . log_if_transport ( "Feature flag changes response: #{ result [ :ff ] . to_s } " )
78
-
79
- unless result [ :rbs ] [ :d ] . empty?
80
- @config . split_logger . log_if_debug ( "#{ result [ :rbs ] [ :d ] . length } rule based segments retrieved. since=#{ since_rbs } " )
81
- end
82
- @config . split_logger . log_if_transport ( "rule based segments changes response: #{ result [ :rbs ] . to_s } " )
83
-
84
- bucket = BinarySearchLatencyTracker . get_bucket ( ( Time . now - start ) * 1000.0 )
85
- @telemetry_runtime_producer . record_sync_latency ( Telemetry ::Domain ::Constants ::SPLIT_SYNC , bucket )
86
- @telemetry_runtime_producer . record_successful_sync ( Telemetry ::Domain ::Constants ::SPLIT_SYNC , ( Time . now . to_f * 1000.0 ) . to_i )
87
-
88
- result
89
- else
90
- @telemetry_runtime_producer . record_sync_error ( Telemetry ::Domain ::Constants ::SPLIT_SYNC , response . status )
91
60
92
- @config . logger . error ( "Unexpected status code while fetching feature flags: #{ response . status } . " \
93
- 'Check your API key and base URI' )
94
-
95
- raise 'Split SDK failed to connect to backend to fetch feature flags definitions'
61
+ return process_result ( result , since , since_rbs , start )
96
62
end
63
+ @telemetry_runtime_producer . record_sync_error ( Telemetry ::Domain ::Constants ::SPLIT_SYNC , response . status )
64
+
65
+ @config . logger . error ( "Unexpected status code while fetching feature flags: #{ response . status } . " \
66
+ 'Check your API key and base URI' )
67
+
68
+ raise 'Split SDK failed to connect to backend to fetch feature flags definitions'
97
69
end
98
70
99
71
def clear_storage
@@ -102,6 +74,36 @@ def clear_storage
102
74
103
75
private
104
76
77
+ def process_result ( result , since , since_rbs , start )
78
+ if @spec_version == Splits ::SPEC_1_1
79
+ result = convert_to_new_spec ( result )
80
+ end
81
+
82
+ result [ :rbs ] [ :d ] = check_rbs_data ( result [ :rbs ] [ :d ] )
83
+ result = objects_with_segment_names ( result )
84
+
85
+ if @spec_version == SplitIoClient ::Spec ::FeatureFlags ::SPEC_VERSION
86
+ @clear_storage = @last_proxy_check_timestamp != 0
87
+ @last_proxy_check_timestamp = 0
88
+ end
89
+
90
+ unless result [ :ff ] [ :d ] . empty?
91
+ @config . split_logger . log_if_debug ( "#{ result [ :ff ] [ :d ] . length } feature flags retrieved. since=#{ since } " )
92
+ end
93
+ @config . split_logger . log_if_transport ( "Feature flag changes response: #{ result [ :ff ] . to_s } " )
94
+
95
+ unless result [ :rbs ] [ :d ] . empty?
96
+ @config . split_logger . log_if_debug ( "#{ result [ :rbs ] [ :d ] . length } rule based segments retrieved. since=#{ since_rbs } " )
97
+ end
98
+ @config . split_logger . log_if_transport ( "rule based segments changes response: #{ result [ :rbs ] . to_s } " )
99
+
100
+ bucket = BinarySearchLatencyTracker . get_bucket ( ( Time . now - start ) * 1000.0 )
101
+ @telemetry_runtime_producer . record_sync_latency ( Telemetry ::Domain ::Constants ::SPLIT_SYNC , bucket )
102
+ @telemetry_runtime_producer . record_successful_sync ( Telemetry ::Domain ::Constants ::SPLIT_SYNC , ( Time . now . to_f * 1000.0 ) . to_i )
103
+
104
+ result
105
+ end
106
+
105
107
def check_rbs_data ( rbs_data )
106
108
rbs_data . each do |rb_segment |
107
109
rb_segment [ :excluded ] = { :keys => [ ] , :segments => [ ] } if rb_segment [ :excluded ] . nil?
0 commit comments