Skip to content

Commit

Permalink
Merge pull request #778 from flippercloud/statsd-cleanup
Browse files Browse the repository at this point in the history
statsd cleanup
  • Loading branch information
jnunemaker authored Dec 2, 2023
2 parents acab7e4 + 9efd316 commit 134b111
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/flipper/instrumentation/statsd_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class << self
end

def update_timer(metric)
if self.class.client
self.class.client.timing metric, (@duration * 1_000).round
end
self.class.client&.timing metric, (@duration * 1_000).round
end

def update_counter(metric)
self.class.client.increment metric if self.class.client
self.class.client&.increment metric
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/flipper/instrumentation/statsd_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,19 @@ def assert_counter(metric)
flipper[:stats].disable(user)
assert_timer 'flipper.adapter.memory.disable'
end

context 'when client is nil' do
before do
described_class.client = nil
end

it 'does not raise error' do
expect { flipper[:stats].enable(user) }.not_to raise_error
end

it 'does not update metrics' do
flipper[:stats].enable(user)
expect(socket.buffer).to be_empty
end
end
end

0 comments on commit 134b111

Please sign in to comment.