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

Commit

Permalink
convert legacy measure_time to time
Browse files Browse the repository at this point in the history
  • Loading branch information
chancefeick committed Oct 20, 2016
1 parent 8d748b3 commit 9c04838
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/librato/metrics/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/metrics/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c04838

Please sign in to comment.