Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
17 changes: 9 additions & 8 deletions lib/splitclient-rb/cache/repositories/segments_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ def add_to_segment(segment)
name = segment[:name]

@adapter.initialize_set(segment_data(name)) unless @adapter.exists?(segment_data(name))

add_keys(name, segment[:added])
remove_keys(name, segment[:removed])
@internal_events_queue.push(
SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
SplitIoClient::Engine::Models::SdkInternalEvent::SEGMENTS_UPDATED,
SplitIoClient::Engine::Models::EventsMetadata.new(
SplitIoClient::Engine::Models::SdkEventType::SEGMENTS_UPDATE,
[]
if segment[:added].length > 0 || segment[:removed].length > 0
@internal_events_queue.push(
SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
SplitIoClient::Engine::Models::SdkInternalEvent::SEGMENTS_UPDATED,
SplitIoClient::Engine::Models::EventsMetadata.new(
SplitIoClient::Engine::Models::SdkEventType::SEGMENTS_UPDATE,
[]
)
)
)
)
end
end

def get_segment_keys(name)
Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/clients/split_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def destroy
@config.logger.info('Split client shutdown started...') if @config.debug_enabled
if !@config.cache_adapter.is_a?(SplitIoClient::Cache::Adapters::RedisAdapter) && @config.impressions_mode != :none &&
(!@impressions_repository.empty? || !@events_repository.empty?)
@config.logger.debug("Impressions and/or Events cache is not empty")
@config.logger.debug("Impressions and/or Events cache is not empty") if @config.debug_enabled
# Adding small delay to ensure sender threads are fully running
sleep(0.1)
if !@config.threads.key?(:impressions_sender) || !@config.threads.key?(:events_sender)
@config.logger.debug("Periodic data recording thread has not started yet, waiting for service startup.")
@config.logger.debug("Periodic data recording thread has not started yet, waiting for service startup.") if @config.debug_enabled
@config.threads[:start_sdk].join(5) if @config.threads.key?(:start_sdk)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/engine/api/splits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def since(since, since_rbs, fetch_options = { cache_control_headers: false, till

if check_last_proxy_check_timestamp
@spec_version = SplitIoClient::Spec::FeatureFlags::SPEC_VERSION
@config.logger.debug("Switching to new Feature flag spec #{@spec_version} and fetching.")
@config.logger.debug("Switching to new Feature flag spec #{@spec_version} and fetching.") if @config.debug_enabled
@old_spec_since = since
since = -1
since_rbs = -1
Expand All @@ -41,7 +41,7 @@ def since(since, since_rbs, fetch_options = { cache_control_headers: false, till

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}: ")
@config.logger.debug("Fetching from splitChanges with #{params}: ") if @config.debug_enabled
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.")
Expand Down
6 changes: 3 additions & 3 deletions lib/splitclient-rb/engine/auth_api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def authenticate(api_key)
return process_error(response) if response.status >= 400 && response.status < 500

@telemetry_runtime_producer.record_sync_error(Telemetry::Domain::Constants::TOKEN_SYNC, response.status.to_i)
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}") if @config.debug_enabled
{ push_enabled: false, retry: true }
rescue StandardError => e
@config.logger.debug("AuthApiClient error: #{e.inspect}.")
@config.logger.debug("AuthApiClient error: #{e.inspect}.") if @config.debug_enabled
{ push_enabled: false, retry: false }
end

Expand All @@ -51,7 +51,7 @@ def decode_token(token)
end

def process_error(response)
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}")
@config.logger.debug("Error connecting to: #{@config.auth_service_url}. Response status: #{response.status}") if @config.debug_enabled
@telemetry_runtime_producer.record_auth_rejections if response.status == 401

{ push_enabled: false, retry: false }
Expand Down
8 changes: 7 additions & 1 deletion lib/splitclient-rb/engine/events/events_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def notify_internal_event(sdk_internal_event, event_metadata)
end

# if client is not subscribed to SDK_READY
if sorted_event == SplitIoClient::Engine::Models::SdkEvent::SDK_READY && get_event_handler(sorted_event).nil?
if check_if_register_needed(sorted_event)
@config.logger.debug('EventsManager: Registering SDK_READY event as fired') if @config.debug_enabled
@active_subscriptions[Engine::Models::SdkEvent::SDK_READY] = Engine::Models::EventActiveSubscriptions.new(true, nil)
end
Expand All @@ -65,6 +65,12 @@ def destroy

private

def check_if_register_needed(sorted_event)
sorted_event == SplitIoClient::Engine::Models::SdkEvent::SDK_READY &&
get_event_handler(sorted_event).nil? &&
!@active_subscriptions.include?(sorted_event)
end

def fire_sdk_event(sdk_event, event_metadata)
@config.logger.debug("EventsManager: Firing Sdk event: #{sdk_event}") if @config.debug_enabled
@config.threads[:sdk_event_notify] = Thread.new do
Expand Down
12 changes: 6 additions & 6 deletions lib/splitclient-rb/engine/sync_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def start_thread
connected = false

if @config.streaming_enabled
@config.logger.debug('Starting Streaming mode ...')
@config.logger.debug('Starting Streaming mode ...') if @config.debug_enabled
start_push_status_monitor
connected = @push_manager.start_sse
end

unless connected
@config.logger.debug('Starting Polling mode ...')
@config.logger.debug('Starting Polling mode ...') if @config.debug_enabled
@synchronizer.start_periodic_fetch
record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
end
Expand Down Expand Up @@ -92,7 +92,7 @@ def process_push_shutdown

def process_connected
if @sse_connected.value
@config.logger.debug('Streaming already connected.')
@config.logger.debug('Streaming already connected.') if @config.debug_enabled
return
end

Expand All @@ -107,7 +107,7 @@ def process_connected

def process_forced_stop
unless @sse_connected.value
@config.logger.debug('Streaming already disconnected.')
@config.logger.debug('Streaming already disconnected.') if @config.debug_enabled
return
end

Expand All @@ -120,7 +120,7 @@ def process_forced_stop

def process_disconnect(reconnect)
unless @sse_connected.value
@config.logger.debug('Streaming already disconnected.')
@config.logger.debug('Streaming already disconnected.') if @config.debug_enabled
return
end

Expand Down Expand Up @@ -169,7 +169,7 @@ def incoming_push_status_handler
when Constants::PUSH_SUBSYSTEM_OFF
process_push_shutdown
else
@config.logger.debug('Incorrect push status type.')
@config.logger.debug('Incorrect push status type.') if @config.debug_enabled
end
end
rescue StandardError => e
Expand Down
27 changes: 13 additions & 14 deletions lib/splitclient-rb/sse/event_source/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ def initialize(config,

def close(status = nil)
unless connected?
@config.logger.debug('SSEClient already disconected.')
@config.logger.debug('SSEClient already disconected.') if @config.debug_enabled
return
end
@config.logger.debug("Closing SSEClient socket")
@config.logger.debug("Closing SSEClient socket") if @config.debug_enabled

push_status(status)
@connected.make_false
@socket.sync_close = true if @socket.is_a? OpenSSL::SSL::SSLSocket
@socket.close
@config.logger.debug("SSEClient socket state #{@socket.state}") if @socket.is_a? OpenSSL::SSL::SSLSocket
@config.logger.debug("SSEClient socket state #{@socket.state}") if @socket.is_a? OpenSSL::SSL::SSLSocket && @config.debug_enabled
rescue StandardError => e
@config.logger.error("SSEClient close Error: #{e.inspect}")
end

def start(url)
if connected?
@config.logger.debug('SSEClient already running.')
@config.logger.debug('SSEClient already running.') if @config.debug_enabled
return true
end

Expand Down Expand Up @@ -96,18 +96,17 @@ def connect_stream(latch)

raise 'eof exception' if partial_data == :eof
rescue IO::WaitReadable => e
@config.logger.debug("SSE client IO::WaitReadable transient error: #{e.inspect}")
@config.logger.debug("SSE client IO::WaitReadable transient error: #{e.inspect}") if @config.debug_enabled
IO.select([@socket], nil, nil, @read_timeout)
retry
rescue Errno::EAGAIN => e
@config.logger.debug("SSE client transient error: #{e.inspect}")
@config.logger.debug("SSE client transient error: #{e.inspect}") if @config.debug_enabled
IO.select([@socket], nil, nil, @read_timeout)
retry
rescue Errno::ETIMEDOUT => e
@config.logger.error("SSE read operation timed out!: #{e.inspect}")
return Constants::PUSH_RETRYABLE_ERROR
rescue EOFError => e
puts "SSE read operation EOF Exception!: #{e.inspect}"
@config.logger.error("SSE read operation EOF Exception!: #{e.inspect}")
raise 'eof exception'
rescue Errno::EBADF, IOError => e
Expand All @@ -125,12 +124,12 @@ def connect_stream(latch)
return Constants::PUSH_RETRYABLE_ERROR
end
rescue Errno::EBADF
@config.logger.debug("SSE socket is not connected (Errno::EBADF)")
@config.logger.debug("SSE socket is not connected (Errno::EBADF)") if @config.debug_enabled
break
rescue RuntimeError
raise 'eof exception'
rescue Exception => e
@config.logger.debug("SSE socket is not connected: #{e.inspect}")
@config.logger.debug("SSE socket is not connected: #{e.inspect}") if @config.debug_enabled
break
end

Expand All @@ -156,7 +155,7 @@ def read_first_event(data, latch)
return unless @first_event.value

response_code = @event_parser.first_event(data)
@config.logger.debug("SSE client first event code: #{response_code}")
@config.logger.debug("SSE client first event code: #{response_code}") if @config.debug_enabled

error_event = false
events = @event_parser.parse(data)
Expand All @@ -165,7 +164,7 @@ def read_first_event(data, latch)

if response_code == OK_CODE && !error_event
@connected.make_true
@config.logger.debug("SSE client first event Connected is true")
@config.logger.debug("SSE client first event Connected is true") if @config.debug_enabled
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::SSE_CONNECTION_ESTABLISHED, nil)
push_status(Constants::PUSH_CONNECTED)
end
Expand Down Expand Up @@ -202,7 +201,7 @@ def socket_connect
end

def process_data(partial_data)
@config.logger.debug("Event partial data: #{partial_data}")
@config.logger.debug("Event partial data: #{partial_data}") if @config.debug_enabled
return if partial_data.nil? || partial_data == KEEP_ALIVE_RESPONSE

events = @event_parser.parse(partial_data)
Expand All @@ -220,7 +219,7 @@ def build_request(uri)
req << "SplitSDKMachineName: #{@config.machine_name}\r\n"
req << "SplitSDKClientKey: #{@api_key.split(//).last(4).join}\r\n" unless @api_key.nil?
req << "Cache-Control: no-cache\r\n\r\n"
@config.logger.debug("Request info: #{req}")
@config.logger.debug("Request info: #{req}") if @config.debug_enabled
req
end

Expand Down Expand Up @@ -255,7 +254,7 @@ def dispatch_event(event)
def push_status(status)
return if status.nil?

@config.logger.debug("Pushing new sse status: #{status}")
@config.logger.debug("Pushing new sse status: #{status}") if @config.debug_enabled
@status_queue.push(status)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/sse/event_source/event_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def parse(raw_event)

events
rescue StandardError => e
@config.logger.debug("Error during parsing a event: #{e.inspect}")
@config.logger.debug("Error during parsing a event: #{e.inspect}") if @config.debug_enabled
[]
end

def first_event(raw_data)
raw_data.split("\n")[0].split(' ')[1].to_i
rescue StandardError => e
@config.logger.debug("Error parsing first event: #{e.inspect}")
@config.logger.error("Error parsing first event: #{e.inspect}")
BAD_REQUEST_CODE
end

Expand Down
6 changes: 3 additions & 3 deletions lib/splitclient-rb/sse/notification_manager_keeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def process_event_control(type)
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, DISABLED)
push_status(Constants::PUSH_SUBSYSTEM_OFF)
else
@config.logger.error("Incorrect event type: #{incoming_notification}")
@config.logger.error("Incorrect event type: #{incoming_notification}") if @config.debug_enabled
end
end

def process_event_occupancy(channel, publishers)
@config.logger.debug("Processed occupancy event with #{publishers} publishers. Channel: #{channel}")
@config.logger.debug("Processed occupancy event with #{publishers} publishers. Channel: #{channel}") if @config.debug_enabled

update_publishers(channel, publishers)

Expand Down Expand Up @@ -76,7 +76,7 @@ def are_publishers_available?
end

def push_status(status)
@config.logger.debug("Pushing occupancy status: #{status}")
@config.logger.debug("Pushing occupancy status: #{status}") if @config.debug_enabled
@status_queue.push(status)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/splitclient-rb/sse/workers/segments_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def initialize(synchronizer, config, segments_repository)

def add_to_queue(change_number, segment_name)
item = { change_number: change_number, segment_name: segment_name }
@config.logger.debug("SegmentsWorker add to queue #{item}")
@config.logger.debug("SegmentsWorker add to queue #{item}") if @config.debug_enabled
@queue.push(item)
end

def start
if @running.value
@config.logger.debug('segments worker already running.')
@config.logger.debug('segments worker already running.') if @config.debug_enabled
return
end

Expand All @@ -30,7 +30,7 @@ def start

def stop
unless @running.value
@config.logger.debug('segments worker not running.')
@config.logger.debug('segments worker not running.') if @config.debug_enabled
return
end

Expand All @@ -44,7 +44,7 @@ def perform
while (item = @queue.pop)
segment_name = item[:segment_name]
cn = item[:change_number]
@config.logger.debug("SegmentsWorker change_number dequeue #{segment_name}, #{cn}")
@config.logger.debug("SegmentsWorker change_number dequeue #{segment_name}, #{cn}") if @config.debug_enabled

@synchronizer.fetch_segment(segment_name, cn)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/splitclient-rb/sse/workers/splits_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(synchronizer, config, feature_flags_repository, telemetry_runtime

def start
if @running.value
@config.logger.debug('feature_flags_worker already running.')
@config.logger.debug('feature_flags_worker already running.') if @config.debug_enabled
return
end

Expand All @@ -28,7 +28,7 @@ def start

def stop
unless @running.value
@config.logger.debug('feature_flags_worker not running.')
@config.logger.debug('feature_flags_worker not running.') if @config.debug_enabled
return
end

Expand All @@ -37,7 +37,7 @@ def stop
end

def add_to_queue(notification)
@config.logger.debug("feature_flags_worker add to queue #{notification.data['changeNumber']}")
@config.logger.debug("feature_flags_worker add to queue #{notification.data['changeNumber']}") if @config.debug_enabled
@queue.push(notification)
end

Expand All @@ -52,7 +52,7 @@ def perform_thread

def perform
while (notification = @queue.pop)
@config.logger.debug("feature_flags_worker change_number dequeue #{notification.data['changeNumber']}")
@config.logger.debug("feature_flags_worker change_number dequeue #{notification.data['changeNumber']}") if @config.debug_enabled
case notification.data['type']
when SSE::EventSource::EventTypes::SPLIT_UPDATE
success = update_feature_flag(notification)
Expand Down Expand Up @@ -117,7 +117,7 @@ def update_rule_based_segment(notification)
def kill_feature_flag(notification)
return if @feature_flags_repository.get_change_number.to_i > notification.data['changeNumber']

@config.logger.debug("feature_flags_worker kill #{notification.data['splitName']}, #{notification.data['changeNumber']}")
@config.logger.debug("feature_flags_worker kill #{notification.data['splitName']}, #{notification.data['changeNumber']}") if @config.debug_enabled
@feature_flags_repository.kill(notification.data['changeNumber'],
notification.data['splitName'],
notification.data['defaultTreatment'])
Expand Down
2 changes: 1 addition & 1 deletion lib/splitclient-rb/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SplitIoClient
VERSION = '8.11.0'
VERSION = '8.11.0-rc2'
end
3 changes: 0 additions & 3 deletions spec/splitclient/split_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@
expect(factory.instance_variable_get(:@config).valid_mode).to be false
expect(factory.manager.split('test_split'))
.to be nil

puts '###### log'
puts log.string
end
end

Expand Down