From 9c048389fce490840bbbbfd67c9accbf238f54ab Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 20 Oct 2016 12:02:06 -0700 Subject: [PATCH] convert legacy measure_time to time --- lib/librato/metrics/queue.rb | 12 ++++++------ spec/unit/metrics/queue_spec.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/librato/metrics/queue.rb b/lib/librato/metrics/queue.rb index 21ee6d2..78c9d54 100644 --- a/lib/librato/metrics/queue.rb +++ b/lib/librato/metrics/queue.rb @@ -41,17 +41,17 @@ def add(measurements) if @prefix metric[:name] = "#{@prefix}.#{metric[:name]}" end - multidimensional = true if metric[:tags] + multidimensional = true if metric[:tags] || metric[:time] type = ("#{type}s").to_sym - time = multidimensional ? :time : :measure_time + time_key = multidimensional ? :time : :measure_time + metric[:time] = metric.delete(:measure_time) if multidimensional && metric[:measure_time] - if metric[time] - metric[time] = metric[time].to_i + if metric[time_key] + metric[time_key] = metric[time_key].to_i check_measure_time(metric) elsif !skip_measurement_times - metric[time] = epoch_time + metric[time_key] = epoch_time end - multidimensional = true if metric[:time] if multidimensional @queued[:measurements] ||= [] @queued[:measurements] << metric diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 6138475..163f34f 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -238,6 +238,20 @@ module Metrics expect(queue.queued[:tags]).to be_nil expect(queue.queued[:measurements].first).to eq(expected) end + + it "converts legacy measure_time to time" do + expected_time = Time.now.to_i + expected_tags = { foo: "bar" } + expected = { + measurements: [{ + name: "test", value: 1, tags: expected_tags, time: expected_time + }] + } + + subject.add test: { value: 1, tags: expected_tags, measure_time: expected_time } + + expect(subject.queued).to equal_unordered(expected) + end end context "when Queue is initialized with tags and when tags are used as arguments" do