From cdfa53ba8ad5a1a4f073422917c73a2c5be4e9bc Mon Sep 17 00:00:00 2001 From: Cyril David Date: Mon, 20 Mar 2017 15:13:42 -0700 Subject: [PATCH] Don't submit the queue when empty (#137) --- lib/librato/metrics/processor.rb | 2 +- lib/librato/metrics/queue.rb | 2 +- spec/unit/metrics/queue_spec.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/librato/metrics/processor.rb b/lib/librato/metrics/processor.rb index 5524b7a..c960a05 100644 --- a/lib/librato/metrics/processor.rb +++ b/lib/librato/metrics/processor.rb @@ -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 diff --git a/lib/librato/metrics/queue.rb b/lib/librato/metrics/queue.rb index 78c9d54..93732da 100644 --- a/lib/librato/metrics/queue.rb +++ b/lib/librato/metrics/queue.rb @@ -75,7 +75,7 @@ def counters # # @return Boolean def empty? - @queued.empty? + gauges.empty? && counters.empty? && measurements.empty? end # Remove all queued metrics diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 163f34f..97bd238 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -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 @@ -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