Skip to content

Commit 455e84d

Browse files
committed
polishing
1 parent 4dd9686 commit 455e84d

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

lib/splitclient-rb/engine/auth_api_client.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def authenticate(api_key)
2121
return process_error(response) if response.status >= 400 && response.status < 500
2222

2323
@telemetry_runtime_producer.record_sync_error(Telemetry::Domain::Constants::TOKEN_SYNC, response.status.to_i)
24-
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}") if @config.debug_enabled
24+
if @config.debug_enabled
25+
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
26+
end
2527
{ push_enabled: false, retry: true }
2628
rescue StandardError => e
2729
@config.logger.debug("AuthApiClient error: #{e.inspect}.") if @config.debug_enabled
@@ -51,7 +53,9 @@ def decode_token(token)
5153
end
5254

5355
def process_error(response)
54-
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}") if @config.debug_enabled
56+
if @config.debug_enabled
57+
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
58+
end
5559
@telemetry_runtime_producer.record_auth_rejections if response.status == 401
5660

5761
{ push_enabled: false, retry: false }

lib/splitclient-rb/engine/sync_manager.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def start_thread
4747
connected = false
4848

4949
if @config.streaming_enabled
50-
@config.logger.debug('Starting Streaming mode ...') if @config.debug_enabled
50+
log_if_debug('Starting Streaming mode ...')
5151
start_push_status_monitor
5252
connected = @push_manager.start_sse
5353
end
5454

5555
unless connected
56-
@config.logger.debug('Starting Polling mode ...') if @config.debug_enabled
56+
log_if_debug('Starting Polling mode ...')
5757
@synchronizer.start_periodic_fetch
5858
record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
5959
end
@@ -92,7 +92,7 @@ def process_push_shutdown
9292

9393
def process_connected
9494
if @sse_connected.value
95-
@config.logger.debug('Streaming already connected.') if @config.debug_enabled
95+
log_if_debug('Streaming already connected.')
9696
return
9797
end
9898

@@ -107,7 +107,7 @@ def process_connected
107107

108108
def process_forced_stop
109109
unless @sse_connected.value
110-
@config.logger.debug('Streaming already disconnected.') if @config.debug_enabled
110+
log_if_debug('Streaming already disconnected.')
111111
return
112112
end
113113

@@ -120,7 +120,7 @@ def process_forced_stop
120120

121121
def process_disconnect(reconnect)
122122
unless @sse_connected.value
123-
@config.logger.debug('Streaming already disconnected.') if @config.debug_enabled
123+
log_if_debug('Streaming already disconnected.')
124124
return
125125
end
126126

@@ -144,14 +144,14 @@ def record_telemetry(type, data)
144144

145145
def start_push_status_monitor
146146
@config.threads[:push_status_handler] = Thread.new do
147-
@config.logger.debug('Starting push status handler ...') if @config.debug_enabled
147+
log_if_debug('Starting push status handler ...')
148148
incoming_push_status_handler
149149
end
150150
end
151151

152152
def incoming_push_status_handler
153153
while (status = @status_queue.pop)
154-
@config.logger.debug("Push status handler dequeue #{status}") if @config.debug_enabled
154+
log_if_debug("Push status handler dequeue #{status}")
155155

156156
case status
157157
when Constants::PUSH_CONNECTED
@@ -169,12 +169,16 @@ def incoming_push_status_handler
169169
when Constants::PUSH_SUBSYSTEM_OFF
170170
process_push_shutdown
171171
else
172-
@config.logger.debug('Incorrect push status type.') if @config.debug_enabled
172+
log_if_debug('Incorrect push status type.')
173173
end
174174
end
175175
rescue StandardError => e
176176
@config.logger.error("Push status handler error: #{e.inspect}")
177177
end
178178
end
179+
180+
def log_if_debug(msg)
181+
@config.logger.debug(msg) if @config.debug_enabled
182+
end
179183
end
180184
end

lib/splitclient-rb/sse/workers/splits_worker.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def perform_thread
5252

5353
def perform
5454
while (notification = @queue.pop)
55-
@config.logger.debug("feature_flags_worker change_number dequeue #{notification.data['changeNumber']}") if @config.debug_enabled
55+
if @config.debug_enabled
56+
@config.logger.debug("feature_flags_worker change_number dequeue #{notification.data['changeNumber']}")
57+
end
5658
case notification.data['type']
5759
when SSE::EventSource::EventTypes::SPLIT_UPDATE
5860
success = update_feature_flag(notification)
@@ -117,7 +119,9 @@ def update_rule_based_segment(notification)
117119
def kill_feature_flag(notification)
118120
return if @feature_flags_repository.get_change_number.to_i > notification.data['changeNumber']
119121

120-
@config.logger.debug("feature_flags_worker kill #{notification.data['splitName']}, #{notification.data['changeNumber']}") if @config.debug_enabled
122+
if @config.debug_enabled
123+
@config.logger.debug("feature_flags_worker kill #{notification.data['splitName']}, #{notification.data['changeNumber']}")
124+
end
121125
@feature_flags_repository.kill(notification.data['changeNumber'],
122126
notification.data['splitName'],
123127
notification.data['defaultTreatment'])

0 commit comments

Comments
 (0)