Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ runs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ inputs.version }}
bundler: 2

- name: Install dependencies
if: ${{ inputs.install-dependencies == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class EventDispatcher
def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
@sdk_key = sdk_key
@config = config
@diagnostic_accumulator = config.diagnostic_opt_out? ? nil : diagnostic_accumulator
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client is responsible for determining if we pass the diagnostic accumulator to the rest of the system based on the opt_out value. This makes the check here redundant and unnecessary.

@diagnostic_accumulator = diagnostic_accumulator
@event_sender = event_sender
@sampler = LaunchDarkly::Impl::Sampler.new(Random.new)

Expand Down
1 change: 1 addition & 0 deletions lib/ldclient-rb/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class StreamProcessor
def initialize(sdk_key, config, diagnostic_accumulator = nil)
@sdk_key = sdk_key
@config = config
@diagnostic_accumulator = diagnostic_accumulator
@data_source_update_sink = config.data_source_update_sink
@feature_store = config.feature_store
@initialized = Concurrent::AtomicBoolean.new(false)
Expand Down
66 changes: 66 additions & 0 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,71 @@ module LaunchDarkly
expect(listener.statuses[1].last_error.kind).to eq(Interfaces::DataSource::ErrorInfo::INVALID_DATA)
end
end

describe '#log_connection_result' do
it "logs successful connection when diagnostic_accumulator is provided" do
diagnostic_accumulator = double("DiagnosticAccumulator")
expect(diagnostic_accumulator).to receive(:record_stream_init).with(
kind_of(Integer),
false,
kind_of(Integer)
)

processor = subject.new("sdk_key", config, diagnostic_accumulator)
processor.send(:log_connection_started)
processor.send(:log_connection_result, true)
end

it "logs failed connection when diagnostic_accumulator is provided" do
diagnostic_accumulator = double("DiagnosticAccumulator")
expect(diagnostic_accumulator).to receive(:record_stream_init).with(
kind_of(Integer),
true,
kind_of(Integer)
)

processor = subject.new("sdk_key", config, diagnostic_accumulator)
processor.send(:log_connection_started)
processor.send(:log_connection_result, false)
end

it "logs connection metrics with correct timestamp and duration" do
diagnostic_accumulator = double("DiagnosticAccumulator")

processor = subject.new("sdk_key", config, diagnostic_accumulator)

expect(diagnostic_accumulator).to receive(:record_stream_init) do |timestamp, failed, duration|
expect(timestamp).to be_a(Integer)
expect(timestamp).to be > 0
expect(failed).to eq(false)
expect(duration).to be_a(Integer)
expect(duration).to be >= 0
end

processor.send(:log_connection_started)
sleep(0.01) # Small delay to ensure measurable duration
processor.send(:log_connection_result, true)
end

it "only logs once per connection attempt" do
diagnostic_accumulator = double("DiagnosticAccumulator")
expect(diagnostic_accumulator).to receive(:record_stream_init).once

processor = subject.new("sdk_key", config, diagnostic_accumulator)
processor.send(:log_connection_started)
processor.send(:log_connection_result, true)
# Second call should not trigger another log
processor.send(:log_connection_result, true)
end

it "works gracefully when no diagnostic_accumulator is provided" do
processor = subject.new("sdk_key", config, nil)

expect {
processor.send(:log_connection_started)
processor.send(:log_connection_result, true)
}.not_to raise_error
end
end
end
end