Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Don't submit the queue when empty (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx authored and Chance Feick committed Mar 20, 2017
1 parent 9ceddf3 commit cdfa53b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/librato/metrics/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def persister
#
# @return Boolean
def submit
return true if self.queued.empty?
return true if self.empty?
options = {per_request: @per_request}
if persister.persist(self.client, self.queued, options)
@last_submit_time = Time.now
Expand Down
2 changes: 1 addition & 1 deletion lib/librato/metrics/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def counters
#
# @return Boolean
def empty?
@queued.empty?
gauges.empty? && counters.empty? && measurements.empty?
end

# Remove all queued metrics
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/metrics/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ module Metrics
subject.add foo: {type: :gauge, value: 121212}
expect(subject.empty?).to be false
end

it "returns true when nothing merged" do
subject.merge!(Librato::Metrics::Aggregator.new)
expect(subject.empty?).to be true
end
end

describe "#gauges" do
Expand All @@ -313,6 +318,14 @@ module Metrics
it "returns [] when no queued gauges" do
expect(subject.gauges).to be_empty
end

context "when there are no metrics" do
it "it does not persist and returns true" do
subject.merge!(Librato::Metrics::Aggregator.new)
subject.persister.return_value(false)
expect(subject.submit).to be true
end
end
end

describe "#last_submit_time" do
Expand Down

0 comments on commit cdfa53b

Please sign in to comment.