From ab88daf6c4e0d01f42bafc38c014e79bbb697c43 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 12:20:24 -0700 Subject: [PATCH 01/22] upgrade rspec. only allow expect syntax. update existing unit tests --- .rspec | 3 +- Gemfile | 2 +- spec/spec_helper.rb | 14 +-- spec/unit/metrics/aggregator_spec.rb | 48 ++++----- spec/unit/metrics/client_spec.rb | 42 ++++---- spec/unit/metrics/connection_spec.rb | 34 +++--- .../unit/metrics/queue/autosubmission_spec.rb | 14 +-- spec/unit/metrics/queue_spec.rb | 101 +++++++++--------- spec/unit/metrics_spec.rb | 28 ++--- 9 files changed, 141 insertions(+), 145 deletions(-) diff --git a/.rspec b/.rspec index cf6add7..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ ---colour \ No newline at end of file +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index 495af1d..000d2e4 100644 --- a/Gemfile +++ b/Gemfile @@ -29,7 +29,7 @@ gem 'pry' gem 'quixote' group :test do - gem 'rspec', '~> 2.6.0' + gem 'rspec', '~> 3.5.0' gem 'sinatra' gem 'popen4' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f3fe4a4..bd3690e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,6 +11,11 @@ RSpec.configure do |config| + # only accept expect syntax instead of should + config.expect_with :rspec do |c| + c.syntax = :expect + end + # purge all metrics from test account def delete_all_metrics connection = Librato::Metrics.client.connection @@ -65,15 +70,6 @@ def with_rackup(name) end -# Ex: 'foobar'.should start_with('foo') #=> true -# -RSpec::Matchers.define :start_with do |start_string| - match do |string| - start_length = start_string.length - string[0..start_length-1] == start_string - end -end - # Compares hashes of arrays by converting the arrays to # sets before comparision # diff --git a/spec/unit/metrics/aggregator_spec.rb b/spec/unit/metrics/aggregator_spec.rb index f67c28c..2ba4229 100644 --- a/spec/unit/metrics/aggregator_spec.rb +++ b/spec/unit/metrics/aggregator_spec.rb @@ -14,35 +14,35 @@ module Metrics it "should set to client" do barney = Client.new a = Aggregator.new(:client => barney) - a.client.should be barney + expect(a.client).to eq(barney) end end context "without specified client" do it "should use Librato::Metrics client" do a = Aggregator.new - a.client.should be Librato::Metrics.client + expect(a.client).to eq(Librato::Metrics.client) end end context "with specified source" do it "should set to source" do a = Aggregator.new(:source => 'rubble') - a.source.should == 'rubble' + expect(a.source).to eq('rubble') end end context "without specified source" do it "should not have a source" do a = Aggregator.new - a.source.should be_nil + expect(a.source).to be_nil end end end describe "#add" do it "should allow chaining" do - subject.add(:foo => 1234).should == subject + expect(subject.add(:foo => 1234)).to eq(subject) end context "with single hash argument" do @@ -57,7 +57,7 @@ module Metrics :max => 3000.0} ] } - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end it "should aggregate multiple measurements" do @@ -74,7 +74,7 @@ module Metrics :max => 5.0} ] } - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end it "should respect source argument" do @@ -88,7 +88,7 @@ module Metrics { :name => 'foo', :count => 2, :sum => 15.0, :min => 5.0, :max => 10.0 } ]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end context "with a prefix set" do @@ -105,7 +105,7 @@ module Metrics } ] } - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end end @@ -129,7 +129,7 @@ module Metrics :max => 30.0}, ] } - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end it "should aggregate multiple measurements" do @@ -157,7 +157,7 @@ module Metrics :max => 10.0} ] } - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end end @@ -166,14 +166,14 @@ module Metrics it "should include global source if set" do a = Aggregator.new(:source => 'blah') a.add :foo => 12 - a.queued[:source].should == 'blah' + expect(a.queued[:source]).to eq('blah') end it "should include global measure_time if set" do measure_time = (Time.now-1000).to_i a = Aggregator.new(:measure_time => measure_time) a.add :foo => 12 - a.queued[:measure_time].should == measure_time + expect(a.queued[:measure_time]).to eq(measure_time) end end @@ -186,8 +186,8 @@ module Metrics context "when successful" do it "should flush queued metrics and return true" do subject.add :steps => 2042, :distance => 1234 - subject.submit.should be_true - subject.empty?.should be_true + expect(subject.submit).to be true + expect(subject.empty?).to be true end end @@ -195,8 +195,8 @@ module Metrics it "should preserve queue and return false" do subject.add :steps => 2042, :distance => 1234 subject.persister.return_value(false) - subject.submit.should be_false - subject.empty?.should be_false + expect(subject.submit).to be false + expect(subject.empty?).to be false end end end @@ -210,10 +210,10 @@ module Metrics end end queued = subject.queued[:gauges][0] - queued[:name].should == 'sleeping' - queued[:count].should be 5 - queued[:sum].should be >= 500.0 - queued[:sum].should be_within(150).of(500) + expect(queued[:name]).to eq('sleeping') + expect(queued[:count]).to eq(5) + expect(queued[:sum]).to be >= 500.0 + expect(queued[:sum]).to be_within(150).of(500) end it "should return the result of the block" do @@ -221,7 +221,7 @@ module Metrics :hi_there end - result.should == :hi_there + expect(result).to eq(:hi_there) end end end @@ -236,7 +236,7 @@ module Metrics it "should not submit immediately" do timed_agg = Aggregator.new(:client => client, :autosubmit_interval => 1) timed_agg.add :foo => 1 - timed_agg.persister.persisted.should be_nil # nothing sent + expect(timed_agg.persister.persisted).to be_nil # nothing sent end it "should submit after interval" do @@ -244,7 +244,7 @@ module Metrics timed_agg.add :foo => 1 sleep 1 timed_agg.add :foo => 2 - timed_agg.persister.persisted.should_not be_nil # sent + expect(timed_agg.persister.persisted).to_not be_nil # sent end end diff --git a/spec/unit/metrics/client_spec.rb b/spec/unit/metrics/client_spec.rb index 6052825..5ccb91b 100644 --- a/spec/unit/metrics/client_spec.rb +++ b/spec/unit/metrics/client_spec.rb @@ -9,41 +9,41 @@ module Metrics context "when given a single string argument" do it "should set agent_identifier" do subject.agent_identifier 'mycollector/0.1 (dev_id:foo)' - subject.agent_identifier.should == 'mycollector/0.1 (dev_id:foo)' + expect(subject.agent_identifier).to eq('mycollector/0.1 (dev_id:foo)') end end context "when given three arguments" do it "should compose an agent string" do subject.agent_identifier('test_app', '0.5', 'foobar') - subject.agent_identifier.should == 'test_app/0.5 (dev_id:foobar)' + expect(subject.agent_identifier).to eq('test_app/0.5 (dev_id:foobar)') end context "when given an empty string" do it "should set to empty" do subject.agent_identifier '' - subject.agent_identifier.should == '' + expect(subject.agent_identifier).to be_empty end end end context "when given two arguments" do it "should raise error" do - lambda { subject.agent_identifier('test_app', '0.5') }.should raise_error(ArgumentError) + expect{ subject.agent_identifier('test_app', '0.5') }.to raise_error(ArgumentError) end end end describe "#api_endpoint" do it "should default to metrics" do - subject.api_endpoint.should == 'https://metrics-api.librato.com' + expect(subject.api_endpoint).to eq('https://metrics-api.librato.com') end end describe "#api_endpoint=" do it "should set api_endpoint" do subject.api_endpoint = 'http://test.com/' - subject.api_endpoint.should == 'http://test.com/' + expect(subject.api_endpoint).to eq('http://test.com/') end # TODO: @@ -55,8 +55,8 @@ module Metrics context "when given two arguments" do it "should store them as email and api_key" do subject.authenticate 'test@librato.com', 'api_key' - subject.email.should == 'test@librato.com' - subject.api_key.should == 'api_key' + expect(subject.email).to eq('test@librato.com') + expect(subject.api_key).to eq('api_key') end end end @@ -64,43 +64,43 @@ module Metrics describe "#connection" do it "should raise exception without authentication" do subject.flush_authentication - lambda{ subject.connection }.should raise_error(Librato::Metrics::CredentialsMissing) + expect{ subject.connection }.to raise_error(Librato::Metrics::CredentialsMissing) end end - + describe "#faraday_adapter" do it "should default to Metrics default adapter" do Metrics.faraday_adapter = :typhoeus - Client.new.faraday_adapter.should == Metrics.faraday_adapter + expect(Client.new.faraday_adapter).to eq(Metrics.faraday_adapter) Metrics.faraday_adapter = nil end end - + describe "#faraday_adapter=" do it "should allow setting of faraday adapter" do subject.faraday_adapter = :excon - subject.faraday_adapter.should == :excon + expect(subject.faraday_adapter).to eq(:excon) subject.faraday_adapter = :patron - subject.faraday_adapter.should == :patron + expect(subject.faraday_adapter).to eq(:patron) end end describe "#new_queue" do it "should return a new queue with client set" do queue = subject.new_queue - queue.client.should be subject + expect(queue.client).to eq(subject) end end describe "#persistence" do it "should default to direct" do subject.send(:flush_persistence) - subject.persistence.should == :direct + expect(subject.persistence).to eq(:direct) end it "should allow configuration of persistence method" do subject.persistence = :fake - subject.persistence.should == :fake + expect(subject.persistence).to eq(:fake) end end @@ -108,16 +108,16 @@ module Metrics it "should persist metrics immediately" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test - subject.submit(:foo => 123).should eql true - subject.persister.persisted.should == {:gauges => [{:name => 'foo', :value => 123}]} + expect(subject.submit(:foo => 123)).to be true + expect(subject.persister.persisted).to eq({:gauges => [{:name => 'foo', :value => 123}]}) end it "should tolerate muliple metrics" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test - lambda{ subject.submit :foo => 123, :bar => 456 }.should_not raise_error + expect{ subject.submit :foo => 123, :bar => 456 }.to_not raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} - subject.persister.persisted.should equal_unordered(expected) + expect(subject.persister.persisted).to equal_unordered(expected) end end diff --git a/spec/unit/metrics/connection_spec.rb b/spec/unit/metrics/connection_spec.rb index 8ce035e..4b6281c 100644 --- a/spec/unit/metrics/connection_spec.rb +++ b/spec/unit/metrics/connection_spec.rb @@ -8,14 +8,14 @@ module Metrics describe "#api_endpoint" do context "when not provided" do it "should be default" do - subject.api_endpoint.should == 'https://metrics-api.librato.com' + expect(subject.api_endpoint).to eq('https://metrics-api.librato.com') end end context "when provided" do it "should be respected" do connection = Connection.new(:api_endpoint => 'http://test.com/') - connection.api_endpoint.should == 'http://test.com/' + expect(connection.api_endpoint).to eq('http://test.com/') end end end @@ -24,7 +24,7 @@ module Metrics context "without an agent_identifier" do it "should render standard string" do connection = Connection.new(:client => Client.new) - connection.user_agent.should start_with('librato-metrics') + expect(connection.user_agent).to start_with('librato-metrics') end end @@ -33,7 +33,7 @@ module Metrics client = Client.new client.agent_identifier('foo', '0.5', 'bar') connection = Connection.new(:client => client) - connection.user_agent.should start_with('foo/0.5') + expect(connection.user_agent).to start_with('foo/0.5') end end @@ -42,7 +42,7 @@ module Metrics client = Client.new client.custom_user_agent = 'foo agent' connection = Connection.new(:client => client) - connection.user_agent.should == 'foo agent' + expect(connection.user_agent).to eq('foo agent') end end @@ -52,7 +52,7 @@ module Metrics describe "network operations" do context "when missing client" do it "should raise exception" do - lambda { subject.get 'metrics' }.should raise_error(NoClientProvided) + expect{ subject.get 'metrics' }.to raise_error(NoClientProvided) end end @@ -67,14 +67,14 @@ module Metrics it "should not retry" do Middleware::CountRequests.reset with_rackup('status.ru') do - lambda { + expect{ client.connection.transport.post 'not_found' - }.should raise_error(NotFound) - lambda { + }.to raise_error(NotFound) + expect{ client.connection.transport.post 'forbidden' - }.should raise_error(ClientError) + }.to raise_error(ClientError) end - Middleware::CountRequests.total_requests.should == 2 # no retries + expect(Middleware::CountRequests.total_requests).to eq(2) # no retries end end @@ -82,11 +82,11 @@ module Metrics it "should retry" do Middleware::CountRequests.reset with_rackup('status.ru') do - lambda { + expect{ client.connection.transport.post 'service_unavailable' - }.should raise_error(ServerError) + }.to raise_error(ServerError) end - Middleware::CountRequests.total_requests.should == 4 # did retries + expect(Middleware::CountRequests.total_requests).to eq(4) # did retries end it "should send consistent body with retries" do @@ -102,12 +102,12 @@ module Metrics rescue Exception => error status = error.response[:status].to_i end - Middleware::CountRequests.total_requests.should == 4 # did retries - status.should be(502)#, 'body should be sent for retries' + expect(Middleware::CountRequests.total_requests).to eq(4) # did retries + expect(status).to eq(502) #, 'body should be sent for retries' end end end end end -end \ No newline at end of file +end diff --git a/spec/unit/metrics/queue/autosubmission_spec.rb b/spec/unit/metrics/queue/autosubmission_spec.rb index e1e8cd2..95c55cf 100644 --- a/spec/unit/metrics/queue/autosubmission_spec.rb +++ b/spec/unit/metrics/queue/autosubmission_spec.rb @@ -12,14 +12,14 @@ module Metrics vol_queue = Queue.new(:client => client, :autosubmit_count => 2) vol_queue.add :foo => 1 vol_queue.add :bar => 2 - vol_queue.persister.persisted.should_not be_nil # sent + expect(vol_queue.persister.persisted).to_not be_nil # sent end it "should not submit if the max has not been reached" do vol_queue = Queue.new(:client => client, :autosubmit_count => 5) vol_queue.add :foo => 1 vol_queue.add :bar => 2 - vol_queue.persister.persisted.should be_nil # nothing sent + expect(vol_queue.persister.persisted).to be_nil # nothing sent end it 'should submit when merging' do @@ -31,8 +31,8 @@ module Metrics queue.merge!(to_merge) - queue.persister.persisted[:gauges].length.should == 8 - queue.queued.should be_empty + expect(queue.persister.persisted[:gauges].length).to eq(8) + expect(queue.queued).to be_empty end end @@ -40,7 +40,7 @@ module Metrics it "should not submit immediately" do vol_queue = Queue.new(:client => client, :autosubmit_interval => 1) vol_queue.add :foo => 1 - vol_queue.persister.persisted.should be_nil # nothing sent + expect(vol_queue.persister.persisted).to be_nil # nothing sent end it "should submit after interval" do @@ -48,10 +48,10 @@ module Metrics vol_queue.add :foo => 1 sleep 1 vol_queue.add :foo => 2 - vol_queue.persister.persisted.should_not be_nil # sent + expect(vol_queue.persister.persisted).to_not be_nil # sent end end end end -end \ No newline at end of file +end diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 544cab6..f1a5b41 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -15,28 +15,28 @@ module Metrics it "should set to client" do barney = Client queue = Queue.new(:client => barney) - queue.client.should be barney + expect(queue.client).to eq(barney) end end context "without specified client" do it "should use Librato::Metrics client" do queue = Queue.new - queue.client.should be Librato::Metrics.client + expect(queue.client).to eq(Librato::Metrics.client) end end end describe "#add" do it "should allow chaining" do - subject.add(:foo => 123).should == subject + expect(subject.add(:foo => 123)).to eq(subject) end context "with single hash argument" do it "should record a key-value gauge" do expected = {:gauges => [{:name => 'foo', :value => 3000, :measure_time => @time}]} subject.add :foo => 3000 - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end @@ -44,19 +44,19 @@ module Metrics it "should record counters" do subject.add :total_visits => {:type => :counter, :value => 4000} expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end it "should record gauges" do subject.add :temperature => {:type => :gauge, :value => 34} expected = {:gauges => [{:name => 'temperature', :value => 34, :measure_time => @time}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end it "should accept type key as string or a symbol" do subject.add :total_visits => {"type" => "counter", :value => 4000} expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end @@ -69,7 +69,7 @@ module Metrics expected = {:gauges => [{:value => 35.4, :name => 'disk_use', :period => 2, :description => 'current disk utilization', :measure_time => measure_time.to_i, :source => 'db2'}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end context "with a prefix set" do @@ -79,7 +79,7 @@ module Metrics subject.add :baz => {:value => 23} expected = {:gauges => [{:name =>'foo.bar', :value => 1, :measure_time => @time}, {:name => 'foo.baz', :value => 23, :measure_time => @time}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end @@ -97,7 +97,7 @@ module Metrics {:name => 'foo.bar', :value => 23, :measure_time => @time}, {:name => 'foo.bar', :value => 34, :measure_time => @time}, {:name => 'bar', :value => 45, :measure_time => @time}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end end @@ -108,7 +108,7 @@ module Metrics expected = {:gauges=>[{:name=>"foo", :value=>123, :measure_time => @time}, {:name=>"bar", :value=>345, :measure_time => @time}, {:name=>"baz", :value=>567, :measure_time => @time}]} - subject.queued.should equal_unordered(expected) + expect(subject.queued).to equal_unordered(expected) end end @@ -116,25 +116,25 @@ module Metrics it "should accept time objects" do time = Time.now-5 subject.add :foo => {:measure_time => time, :value => 123} - subject.queued[:gauges][0][:measure_time].should == time.to_i + expect(subject.queued[:gauges][0][:measure_time]).to eq(time.to_i) end it "should accept integers" do time = @time.to_i subject.add :foo => {:measure_time => time, :value => 123} - subject.queued[:gauges][0][:measure_time].should == time + expect(subject.queued[:gauges][0][:measure_time]).to eq(time) end it "should accept strings" do time = @time.to_s subject.add :foo => {:measure_time => time, :value => 123} - subject.queued[:gauges][0][:measure_time].should == time.to_i + expect(subject.queued[:gauges][0][:measure_time]).to eq(time.to_i) end it "should raise exception in invalid time" do - lambda { + expect{ subject.add :foo => {:measure_time => '12', :value => 123} - }.should raise_error(InvalidMeasureTime) + }.to raise_error(InvalidMeasureTime) end end end @@ -143,22 +143,22 @@ module Metrics it "should return currently queued counters" do subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} - subject.counters.should eql [{:name => 'transactions', :value => 12345, :measure_time => @time}] + expect(subject.counters).to eq([{:name => 'transactions', :value => 12345, :measure_time => @time}]) end it "should return [] when no queued counters" do - subject.counters.should eql [] + expect(subject.counters).to be_empty end end describe "#empty?" do it "should return true when nothing queued" do - subject.empty?.should be_true + expect(subject.empty?).to be true end it "should return false with queued items" do subject.add :foo => {:type => :gauge, :value => 121212} - subject.empty?.should be_false + expect(subject.empty?).to be false end end @@ -166,11 +166,11 @@ module Metrics it "should return currently queued gauges" do subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} - subject.gauges.should eql [{:name => 'register_cents', :value => 211101, :measure_time => @time}] + expect(subject.gauges).to eq([{:name => 'register_cents', :value => 211101, :measure_time => @time}]) end it "should return [] when no queued gauges" do - subject.gauges.should eql [] + expect(subject.gauges).to be_empty end end @@ -181,14 +181,14 @@ module Metrics end it "should default to nil" do - subject.last_submit_time.should be_nil + expect(subject.last_submit_time).to be_nil end it "should store last submission time" do prior = Time.now subject.add :foo => 123 subject.submit - subject.last_submit_time.should >= prior + expect(subject.last_submit_time).to be >= prior end end @@ -203,7 +203,7 @@ module Metrics expected = {:gauges=>[{:name=>"foo", :value=>123, :measure_time => @time}, {:name=>"bar", :value=>456, :measure_time => @time}, {:name=>"baz", :value=>678, :measure_time => @time}]} - q2.queued.should equal_unordered(expected) + expect(q2.queued).to equal_unordered(expected) end it "should merge counters" do @@ -216,7 +216,7 @@ module Metrics expected = {:counters=>[{:name=>"users", :value=>1000, :measure_time => @time}, {:name=>"sales", :value=>250, :measure_time => @time}, {:name=>"signups", :value=>500, :measure_time => @time}]} - q2.queued.should equal_unordered(expected) + expect(q2.queued).to equal_unordered(expected) end it "should maintain specified sources" do @@ -224,7 +224,7 @@ module Metrics q1.add :neo => {:source => 'matrix', :value => 123} q2 = Queue.new(:source => 'red_pill') q2.merge!(q1) - q2.queued[:gauges][0][:source].should == 'matrix' + expect(q2.queued[:gauges][0][:source]).to eq('matrix') end it "should not change default source" do @@ -232,7 +232,7 @@ module Metrics q1.add :neo => 456 q2 = Queue.new(:source => 'red_pill') q2.merge!(q1) - q2.queued[:source].should == 'red_pill' + expect(q2.queued[:source]).to eq('red_pill') end it "should track previous default source" do @@ -243,7 +243,7 @@ module Metrics q2.merge!(q1) q2.queued[:gauges].each do |gauge| if gauge[:name] == 'neo' - gauge[:source].should == 'matrix' + expect(gauge[:source]).to eq('matrix') end end end @@ -255,7 +255,7 @@ module Metrics q2.merge!(q1) expected = {:counters => [{:name=>"users", :value=>1000, :measure_time => @time}], :gauges => [{:name=>"foo", :value=>123, :measure_time => @time}]} - q2.queued.should == expected + expect(q2.queued).to eq(expected) end end @@ -270,8 +270,7 @@ module Metrics expected = {:gauges=>[{:name=>"gauge", :value=>42, :measure_time=>@time}, {:name=>"timing", :count=>2, :sum=>305.0, :min=>102.0, :max=>203.0, :source=>"aggregator"}], :source=>'queue'} - queue.queued.should equal_unordered(expected) - + expect(queue.queued).to equal_unordered(expected) end end @@ -281,15 +280,15 @@ module Metrics :counters=>[{:name => 'bar', :value => 456}]} q = Queue.new q.merge!(to_merge) - q.gauges.length.should == 1 - q.counters.length.should == 1 + expect(q.gauges.length).to eq(1) + expect(q.counters.length).to eq(1) end end end describe "#per_request" do it "should default to 500" do - subject.per_request.should == 500 + expect(subject.per_request).to eq(500) end end @@ -297,27 +296,27 @@ module Metrics it "should include global source if set" do q = Queue.new(:source => 'blah') q.add :foo => 12 - q.queued[:source].should == 'blah' + expect(q.queued[:source]).to eq('blah') end it "should include global measure_time if set" do measure_time = (Time.now-1000).to_i q = Queue.new(:measure_time => measure_time) q.add :foo => 12 - q.queued[:measure_time].should == measure_time + expect(q.queued[:measure_time]).to eq(measure_time) end end describe "#size" do it "should return empty if gauges and counters are emtpy" do - subject.size.should eq 0 + expect(subject.size).to eq(0) end it "should return count of gauges and counters if added" do subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} - subject.size.should eql 4 + expect(subject.size).to eq(4) end end @@ -330,8 +329,8 @@ module Metrics context "when successful" do it "should flush queued metrics and return true" do subject.add :steps => 2042, :distance => 1234 - subject.submit.should be_true - subject.queued.should be_empty + expect(subject.submit).to be true + expect(subject.queued).to be_empty end end @@ -339,8 +338,8 @@ module Metrics it "should preserve queue and return false" do subject.add :steps => 2042, :distance => 1234 subject.persister.return_value(false) - subject.submit.should be_false - subject.queued.should_not be_empty + expect(subject.submit).to be false + expect(subject.queued).to_not be_empty end end end @@ -352,9 +351,9 @@ module Metrics sleep 0.1 end queued = subject.queued[:gauges][0] - queued[:name].should == 'sleeping' - queued[:value].should be >= 100 - queued[:value].should be_within(30).of(100) + expect(queued[:name]).to eq('sleeping') + expect(queued[:value]).to be >= 100 + expect(queued[:value]).to be_within(30).of(100) end end @@ -364,11 +363,11 @@ module Metrics sleep 0.05 end queued = subject.queued[:gauges][0] - queued[:name].should == 'sleep_two' - queued[:period].should == 2 - queued[:source].should == 'app1' - queued[:value].should be >= 50 - queued[:value].should be_within(30).of(50) + expect(queued[:name]).to eq('sleep_two') + expect(queued[:period]).to eq(2) + expect(queued[:source]).to eq('app1') + expect(queued[:value]).to be >= 50 + expect(queued[:value]).to be_within(30).of(50) end end end diff --git a/spec/unit/metrics_spec.rb b/spec/unit/metrics_spec.rb index 4ae9725..b5e3cd5 100644 --- a/spec/unit/metrics_spec.rb +++ b/spec/unit/metrics_spec.rb @@ -8,34 +8,34 @@ module Librato context "when given two arguments" do it "should store them on simple" do Metrics.authenticate 'tester@librato.com', 'api_key' - Metrics.client.email.should == 'tester@librato.com' - Metrics.client.api_key.should == 'api_key' + expect(Metrics.client.email).to eq('tester@librato.com') + expect(Metrics.client.api_key).to eq('api_key') end end end - + describe "#faraday_adapter" do it "should return current default adapter" do - Metrics.faraday_adapter.should_not be nil + expect(Metrics.faraday_adapter).to_not be_nil end end - + describe "#faraday_adapter=" do before(:all) { @current_adapter = Metrics.faraday_adapter } after(:all) { Metrics.faraday_adapter = @current_adapter } - + it "should allow setting of faraday adapter" do Metrics.faraday_adapter = :excon - Metrics.faraday_adapter.should == :excon + expect(Metrics.faraday_adapter).to eq(:excon) Metrics.faraday_adapter = :patron - Metrics.faraday_adapter.should == :patron + expect(Metrics.faraday_adapter).to eq(:patron) end end describe "#persistence" do it "should allow configuration of persistence method" do Metrics.persistence = :test - Metrics.persistence.should == :test + expect(Metrics.persistence).to eq(:test) end end @@ -48,17 +48,17 @@ module Librato it "should persist metrics immediately" do Metrics.persistence = :test - Metrics.submit(:foo => 123).should eql true - Metrics.persister.persisted.should == {:gauges => [{:name => 'foo', :value => 123}]} + expect(Metrics.submit(:foo => 123)).to be true + expect(Metrics.persister.persisted).to eq({:gauges => [{:name => 'foo', :value => 123}]}) end it "should tolerate multiple metrics" do - lambda{ Librato::Metrics.submit :foo => 123, :bar => 456 }.should_not raise_error + expect{ Librato::Metrics.submit :foo => 123, :bar => 456 }.to_not raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} - Librato::Metrics.persister.persisted.should equal_unordered(expected) + expect(Librato::Metrics.persister.persisted).to equal_unordered(expected) end end end -end \ No newline at end of file +end From 3fc5235a58e56e473c6fc6330d002c8fe2bfdd2f Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 12:30:41 -0700 Subject: [PATCH 02/22] use allow mock syntax --- spec/unit/metrics/aggregator_spec.rb | 2 +- spec/unit/metrics/queue_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/metrics/aggregator_spec.rb b/spec/unit/metrics/aggregator_spec.rb index 2ba4229..bce9910 100644 --- a/spec/unit/metrics/aggregator_spec.rb +++ b/spec/unit/metrics/aggregator_spec.rb @@ -6,7 +6,7 @@ module Metrics before(:all) do @time = 1354720160 #Time.now.to_i - Aggregator.any_instance.stub(:epoch_time).and_return(@time) + allow_any_instance_of(Aggregator).to receive(:epoch_time).and_return(@time) end describe "initialization" do diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index f1a5b41..36b8af0 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -7,7 +7,7 @@ module Metrics before(:each) do @time = (Time.now.to_i - 1*60) - Queue.any_instance.stub(:epoch_time).and_return(@time) + allow_any_instance_of(Queue).to receive(:epoch_time).and_return(@time) end describe "initialization" do From 006b5d92da94a3d5c5837846040cedc12209aeab Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 13:25:48 -0700 Subject: [PATCH 03/22] use predicate matcher --- spec/unit/metrics/queue_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 36b8af0..389199b 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -309,7 +309,7 @@ module Metrics describe "#size" do it "should return empty if gauges and counters are emtpy" do - expect(subject.size).to eq(0) + expect(subject.size).to be_zero end it "should return count of gauges and counters if added" do subject.add :transactions => {:type => :counter, :value => 12345}, From d258cec797c9f091dadc9f6643e7967896c8f1b0 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 13:37:45 -0700 Subject: [PATCH 04/22] use not_to --- spec/unit/metrics/aggregator_spec.rb | 2 +- spec/unit/metrics/client_spec.rb | 2 +- spec/unit/metrics/queue/autosubmission_spec.rb | 4 ++-- spec/unit/metrics/queue_spec.rb | 2 +- spec/unit/metrics_spec.rb | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/unit/metrics/aggregator_spec.rb b/spec/unit/metrics/aggregator_spec.rb index bce9910..64cd52f 100644 --- a/spec/unit/metrics/aggregator_spec.rb +++ b/spec/unit/metrics/aggregator_spec.rb @@ -244,7 +244,7 @@ module Metrics timed_agg.add :foo => 1 sleep 1 timed_agg.add :foo => 2 - expect(timed_agg.persister.persisted).to_not be_nil # sent + expect(timed_agg.persister.persisted).not_to be_nil # sent end end diff --git a/spec/unit/metrics/client_spec.rb b/spec/unit/metrics/client_spec.rb index 5ccb91b..978e684 100644 --- a/spec/unit/metrics/client_spec.rb +++ b/spec/unit/metrics/client_spec.rb @@ -115,7 +115,7 @@ module Metrics it "should tolerate muliple metrics" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test - expect{ subject.submit :foo => 123, :bar => 456 }.to_not raise_error + expect{ subject.submit :foo => 123, :bar => 456 }.not_to raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} expect(subject.persister.persisted).to equal_unordered(expected) end diff --git a/spec/unit/metrics/queue/autosubmission_spec.rb b/spec/unit/metrics/queue/autosubmission_spec.rb index 95c55cf..8dd426f 100644 --- a/spec/unit/metrics/queue/autosubmission_spec.rb +++ b/spec/unit/metrics/queue/autosubmission_spec.rb @@ -12,7 +12,7 @@ module Metrics vol_queue = Queue.new(:client => client, :autosubmit_count => 2) vol_queue.add :foo => 1 vol_queue.add :bar => 2 - expect(vol_queue.persister.persisted).to_not be_nil # sent + expect(vol_queue.persister.persisted).not_to be_nil # sent end it "should not submit if the max has not been reached" do @@ -48,7 +48,7 @@ module Metrics vol_queue.add :foo => 1 sleep 1 vol_queue.add :foo => 2 - expect(vol_queue.persister.persisted).to_not be_nil # sent + expect(vol_queue.persister.persisted).not_to be_nil # sent end end diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 389199b..3b412ee 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -339,7 +339,7 @@ module Metrics subject.add :steps => 2042, :distance => 1234 subject.persister.return_value(false) expect(subject.submit).to be false - expect(subject.queued).to_not be_empty + expect(subject.queued).not_to be_empty end end end diff --git a/spec/unit/metrics_spec.rb b/spec/unit/metrics_spec.rb index b5e3cd5..8069190 100644 --- a/spec/unit/metrics_spec.rb +++ b/spec/unit/metrics_spec.rb @@ -16,7 +16,7 @@ module Librato describe "#faraday_adapter" do it "should return current default adapter" do - expect(Metrics.faraday_adapter).to_not be_nil + expect(Metrics.faraday_adapter).not_to be_nil end end @@ -53,7 +53,7 @@ module Librato end it "should tolerate multiple metrics" do - expect{ Librato::Metrics.submit :foo => 123, :bar => 456 }.to_not raise_error + expect{ Librato::Metrics.submit :foo => 123, :bar => 456 }.not_to raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} expect(Librato::Metrics.persister.persisted).to equal_unordered(expected) end From 81504cf6d237b64664c30a1adf3070f08d012e3b Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 14:32:56 -0700 Subject: [PATCH 05/22] update integration tests --- spec/integration/deprecated_methods_spec.rb | 30 ++--- spec/integration/metrics/annotator_spec.rb | 72 +++++------ .../metrics/middleware/count_requests_spec.rb | 6 +- spec/integration/metrics/queue_spec.rb | 16 +-- spec/integration/metrics_spec.rb | 120 +++++++++--------- 5 files changed, 122 insertions(+), 122 deletions(-) diff --git a/spec/integration/deprecated_methods_spec.rb b/spec/integration/deprecated_methods_spec.rb index 0ee8732..b93beb3 100644 --- a/spec/integration/deprecated_methods_spec.rb +++ b/spec/integration/deprecated_methods_spec.rb @@ -4,7 +4,7 @@ describe Librato::Metrics do DEPRECATED_METHODS.each do |deprecated_method| - it { should respond_to(deprecated_method) } + it { is_expected.to respond_to(deprecated_method) } end describe "Client" do @@ -18,7 +18,7 @@ end DEPRECATED_METHODS.each do |deprecated_method| - it { should respond_to(deprecated_method) } + it { is_expected.to respond_to(deprecated_method) } end describe "#fetch" do @@ -26,10 +26,10 @@ let(:metric) { client.fetch(:test_metric) } subject { metric } - it { should_not be_nil } + it { is_expected.not_to be_nil } it "should return a metric" do - metric["name"].should == "test_metric" + expect(metric["name"]).to eq("test_metric") end end @@ -37,13 +37,13 @@ let(:measurements) { client.fetch(:test_metric, :count => 1) } subject { measurements } - it { should_not be_nil } - it { should_not be_empty } + it { is_expected.not_to be_nil } + it { is_expected.not_to be_empty } it "should return the measurements" do - measurements.should have_key("unassigned") - measurements["unassigned"].should be_an(Array) - measurements["unassigned"].first["value"].should == 123.0 + expect(measurements).to have_key("unassigned") + expect(measurements["unassigned"]).to be_an(Array) + expect(measurements["unassigned"].first["value"]).to eq(123.0) end end end @@ -52,12 +52,12 @@ let(:metrics) { client.list } subject { metrics } - it { should_not be_nil } - it { should_not be_empty } + it { is_expected.not_to be_nil } + it { is_expected.not_to be_empty } it "should return the list of metrics" do metric = metrics.find { |m| m["name"] == "test_metric" } - metric.should_not be_nil + expect(metric).not_to be_nil end end @@ -69,15 +69,15 @@ let(:updated_metric) { client.get_metric("test_metric") } it "should update the metric" do - updated_metric["display_name"].should == "Test Deprecated Update" + expect(updated_metric["display_name"]).to eq("Test Deprecated Update") end end describe "#delete" do it "should delete the metric" do - client.metrics(:name => "test_metric").should_not be_empty + expect(client.metrics(:name => "test_metric")).not_to be_empty client.delete("test_metric") - client.metrics(:name => "test_metric").should be_empty + expect(client.metrics(:name => "test_metric")).to be_empty end end diff --git a/spec/integration/metrics/annotator_spec.rb b/spec/integration/metrics/annotator_spec.rb index 3d4f71c..3686afd 100644 --- a/spec/integration/metrics/annotator_spec.rb +++ b/spec/integration/metrics/annotator_spec.rb @@ -11,15 +11,15 @@ module Metrics it "should create new annotation" do subject.add :deployment, "deployed v68" annos = subject.fetch(:deployment, :start_time => Time.now.to_i-60) - annos["events"]["unassigned"].length.should == 1 - annos["events"]["unassigned"][0]["title"].should == 'deployed v68' + expect(annos["events"]["unassigned"].length).to eq(1) + expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68') end it "should support sources" do subject.add :deployment, 'deployed v69', :source => 'box1' annos = subject.fetch(:deployment, :start_time => Time.now.to_i-60) - annos["events"]["box1"].length.should == 1 + expect(annos["events"]["box1"].length).to eq(1) first = annos["events"]["box1"][0] - first['title'].should == 'deployed v69' + expect(first['title']).to eq('deployed v69') end it "should support start and end times" do start_time = Time.now.to_i-120 @@ -27,23 +27,23 @@ module Metrics subject.add :deployment, 'deployed v70', :start_time => start_time, :end_time => end_time annos = subject.fetch(:deployment, :start_time => Time.now.to_i-180) - annos["events"]["unassigned"].length.should == 1 + expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] - first['title'].should == 'deployed v70' - first['start_time'].should == start_time - first['end_time'].should == end_time + expect(first['title']).to eq('deployed v70') + expect(first['start_time']).to eq(start_time) + expect(first['end_time']).to eq(end_time) end it "should support description" do subject.add :deployment, 'deployed v71', :description => 'deployed foobar!' annos = subject.fetch(:deployment, :start_time => Time.now.to_i-180) - annos["events"]["unassigned"].length.should == 1 + expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] - first['title'].should == 'deployed v71' - first['description'].should == 'deployed foobar!' + expect(first['title']).to eq('deployed v71') + expect(first['description']).to eq('deployed foobar!') end it "should have an id for further use" do annotation = subject.add :deployment, "deployed v23" - annotation['id'].should_not be_nil + expect(annotation['id']).not_to be_nil end context "with a block" do @@ -52,8 +52,8 @@ module Metrics sleep 1.0 end data = subject.fetch_event 'deploys', annotation['id'] - data['start_time'].should_not be_nil - data['end_time'].should_not be_nil + expect(data['start_time']).not_to be_nil + expect(data['end_time']).not_to be_nil end end end @@ -63,9 +63,9 @@ module Metrics subject.add :deployment, "deployed v45" subject.fetch :deployment # should exist subject.delete :deployment - lambda { + expect { subject.fetch(:deployment) - }.should raise_error(Metrics::NotFound) + }.to raise_error(Metrics::NotFound) end end @@ -82,8 +82,8 @@ module Metrics subject.delete_event :deployment, ids['deployed v47'] events = subject.fetch(:deployment, :start_time => Time.now.to_i-60) events = events['events']['unassigned'] - events.length.should == 1 - events[0]['title'].should == 'deployed v46' + expect(events.length).to eq(1) + expect(events[0]['title']).to eq('deployed v46') end end @@ -92,7 +92,7 @@ module Metrics it "should return stream properties" do subject.add :backups, "backup 21" properties = subject.fetch :backups - properties['name'].should == 'backups' + expect(properties['name']).to eq('backups') end end @@ -102,8 +102,8 @@ module Metrics subject.add :backups, "backup 23" annos = subject.fetch :backups, :start_time => Time.now.to_i-60 events = annos['events']['unassigned'] - events[0]['title'].should == 'backup 22' - events[1]['title'].should == 'backup 23' + expect(events[0]['title']).to eq('backup 22') + expect(events[1]['title']).to eq('backup 23') end it "should respect source limits" do subject.add :backups, "backup 24", :source => 'server_1' @@ -111,16 +111,16 @@ module Metrics subject.add :backups, "backup 26", :source => 'server_3' annos = subject.fetch :backups, :start_time => Time.now.to_i-60, :sources => %w{server_1 server_3} - annos['events']['server_1'].should_not be_nil - annos['events']['server_2'].should be_nil - annos['events']['server_3'].should_not be_nil + expect(annos['events']['server_1']).not_to be_nil + expect(annos['events']['server_2']).to be_nil + expect(annos['events']['server_3']).not_to be_nil end end it "should return exception if annotation is missing" do - lambda { + expect { subject.fetch :backups - }.should raise_error(Metrics::NotFound) + }.to raise_error(Metrics::NotFound) end end @@ -129,14 +129,14 @@ module Metrics it "should return event properties" do annotation = subject.add 'deploys', 'v69' data = subject.fetch_event 'deploys', annotation['id'] - data['title'].should == 'v69' + expect(data['title']).to eq('v69') end end context "when event doesn't exist" do it "should raise NotFound" do - lambda { + expect { data = subject.fetch_event 'deploys', 324 - }.should raise_error(Metrics::NotFound) + }.to raise_error(Metrics::NotFound) end end end @@ -150,18 +150,18 @@ module Metrics context "without arguments" do it "should list annotation streams" do streams = subject.list - streams['annotations'].length.should == 2 + expect(streams['annotations'].length).to eq(2) streams = streams['annotations'].map{|i| i['name']} - streams.should include('backups') - streams.should include('deployment') + expect(streams).to include('backups') + expect(streams).to include('deployment') end end context "with an argument" do it "should list annotation streams which match" do streams = subject.list :name => 'back' - streams['annotations'].length.should == 1 + expect(streams['annotations'].length).to eq(1) streams = streams['annotations'].map{|i| i['name']} - streams.should include('backups') + expect(streams).to include('backups') end end end @@ -175,8 +175,8 @@ module Metrics :end_time => end_time, :title => 'v28' data = subject.fetch_event 'deploys', annotation['id'] - data['title'].should == 'v28' - data['end_time'].should == end_time + expect(data['title']).to eq('v28') + expect(data['end_time']).to eq(end_time) end end context "when event does not exist" do diff --git a/spec/integration/metrics/middleware/count_requests_spec.rb b/spec/integration/metrics/middleware/count_requests_spec.rb index 97d9245..440a709 100644 --- a/spec/integration/metrics/middleware/count_requests_spec.rb +++ b/spec/integration/metrics/middleware/count_requests_spec.rb @@ -11,14 +11,14 @@ module Middleware CountRequests.reset Metrics.submit :foo => 123 Metrics.submit :foo => 135 - CountRequests.total_requests.should == 2 + expect(CountRequests.total_requests).to eq(2) end it "should be resettable" do Metrics.submit :foo => 123 - CountRequests.total_requests.should > 0 + expect(CountRequests.total_requests).to be > 0 CountRequests.reset - CountRequests.total_requests.should == 0 + expect(CountRequests.total_requests).to eq(0) end end diff --git a/spec/integration/metrics/queue_spec.rb b/spec/integration/metrics/queue_spec.rb index 3af388d..cfa73e0 100644 --- a/spec/integration/metrics/queue_spec.rb +++ b/spec/integration/metrics/queue_spec.rb @@ -15,7 +15,7 @@ module Metrics queue.add "gauge_#{i}" => 1 end queue.submit - Middleware::CountRequests.total_requests.should == 4 + expect(Middleware::CountRequests.total_requests).to eq(4) end it "should persist all metrics" do @@ -29,11 +29,11 @@ module Metrics queue.submit metrics = Metrics.list - metrics.length.should == 8 + expect(metrics.length).to eq(8) counter = Metrics.get_measurements :counter_3, :count => 1 - counter['unassigned'][0]['value'].should == 3 + expect(counter['unassigned'][0]['value']).to eq(3) gauge = Metrics.get_measurements :gauge_5, :count => 1 - gauge['unassigned'][0]['value'].should == 5 + expect(gauge['unassigned'][0]['value']).to eq(5) end it "should apply globals to each request" do @@ -52,8 +52,8 @@ module Metrics # verify globals have persisted for all requests gauge = Metrics.get_measurements :gauge_5, :count => 1 - gauge[source][0]["value"].should eq(1.0) - gauge[source][0]["measure_time"].should eq(measure_time) + expect(gauge[source][0]["value"]).to eq(1.0) + expect(gauge[source][0]["measure_time"]).to eq(measure_time) end end @@ -64,10 +64,10 @@ module Metrics queue.submit foo = Metrics.get_measurements :foo, :count => 2 - foo['default'][0]['value'].should == 123 + expect(foo['default'][0]['value']).to eq(123) bar = Metrics.get_measurements :bar, :count => 2 - bar['barsource'][0]['value'].should == 456 + expect(bar['barsource'][0]['value']).to eq(456) end end diff --git a/spec/integration/metrics_spec.rb b/spec/integration/metrics_spec.rb index b6eecfa..09f0130 100644 --- a/spec/integration/metrics_spec.rb +++ b/spec/integration/metrics_spec.rb @@ -11,15 +11,15 @@ module Librato it "should create new annotation" do Metrics.annotate :deployment, "deployed v68" annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-60) - annos["events"]["unassigned"].length.should == 1 - annos["events"]["unassigned"][0]["title"].should == 'deployed v68' + expect(annos["events"]["unassigned"].length).to eq(1) + expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68') end it "should support sources" do Metrics.annotate :deployment, 'deployed v69', :source => 'box1' annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-60) - annos["events"]["box1"].length.should == 1 + expect(annos["events"]["box1"].length).to eq(1) first = annos["events"]["box1"][0] - first['title'].should == 'deployed v69' + expect(first['title']).to eq('deployed v69') end it "should support start and end times" do start_time = Time.now.to_i-120 @@ -27,19 +27,19 @@ module Librato Metrics.annotate :deployment, 'deployed v70', :start_time => start_time, :end_time => end_time annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-180) - annos["events"]["unassigned"].length.should == 1 + expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] - first['title'].should == 'deployed v70' - first['start_time'].should == start_time - first['end_time'].should == end_time + expect(first['title']).to eq('deployed v70') + expect(first['start_time']).to eq(start_time) + expect(first['end_time']).to eq(end_time) end it "should support description" do Metrics.annotate :deployment, 'deployed v71', :description => 'deployed foobar!' annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-180) - annos["events"]["unassigned"].length.should == 1 + expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] - first['title'].should == 'deployed v71' - first['description'].should == 'deployed foobar!' + expect(first['title']).to eq('deployed v71') + expect(first['description']).to eq('deployed foobar!') end end @@ -51,9 +51,9 @@ module Librato context "with a single argument" do it "should delete named metric" do Metrics.submit :foo => 123 - Metrics.metrics(:name => :foo).should_not be_empty + expect(Metrics.metrics(:name => :foo)).not_to be_empty Metrics.delete_metrics :foo - Metrics.metrics(:name => :foo).should be_empty + expect(Metrics.metrics(:name => :foo)).to be_empty end end @@ -61,9 +61,9 @@ module Librato it "should delete named metrics" do Metrics.submit :foo => 123, :bar => 345, :baz => 567 Metrics.delete_metrics :foo, :bar - Metrics.metrics(:name => :foo).should be_empty - Metrics.metrics(:name => :bar).should be_empty - Metrics.metrics(:name => :baz).should_not be_empty + expect(Metrics.metrics(:name => :foo)).to be_empty + expect(Metrics.metrics(:name => :bar)).to be_empty + expect(Metrics.metrics(:name => :baz)).not_to be_empty end end @@ -77,9 +77,9 @@ module Librato context "with no arguments" do it "should not make request" do - lambda { + expect { Metrics.delete_metrics - }.should raise_error(Metrics::NoMetricsProvided) + }.to raise_error(Metrics::NoMetricsProvided) end end @@ -91,9 +91,9 @@ module Librato Metrics.delete_metrics :names => 'fo*', :exclude => ['foobar'] %w{foo foobaz}.each do |name| - lambda { + expect { Metrics.get_metric name - }.should raise_error(Librato::Metrics::NotFound) + }.to raise_error(Librato::Metrics::NotFound) end %w{foobar bar}.each do |name| @@ -118,8 +118,8 @@ module Librato context "without arguments" do it "should get metric attributes" do metric = Metrics.get_metric :my_counter - metric['name'].should == 'my_counter' - metric['type'].should == 'counter' + expect(metric['name']).to eq('my_counter') + expect(metric['type']).to eq('counter') end end @@ -128,8 +128,8 @@ module Librato # 1 hr ago metric = Metrics.get_metric :my_counter, :start_time => Time.now-3600 data = metric['measurements'] - data['unassigned'].length.should == 3 - data['baz'].length.should == 2 + expect(data['unassigned'].length).to eq(3) + expect(data['baz'].length).to eq(2) end end @@ -137,8 +137,8 @@ module Librato it "should return that number of entries per source" do metric = Metrics.get_metric :my_counter, :count => 2 data = metric['measurements'] - data['unassigned'].length.should == 2 - data['baz'].length.should == 2 + expect(data['unassigned'].length).to eq(2) + expect(data['baz'].length).to eq(2) end end @@ -146,8 +146,8 @@ module Librato it "should only return that source" do metric = Metrics.get_metric :my_counter, :source => 'baz', :start_time => Time.now-3600 data = metric['measurements'] - data['baz'].length.should == 2 - data['unassigned'].should be_nil + expect(data['baz'].length).to eq(2) + expect(data['unassigned']).to be_nil end end @@ -162,14 +162,14 @@ module Librato context "without arguments" do it "should list all metrics" do metric_names = Metrics.metrics.map { |metric| metric['name'] } - metric_names.sort.should == %w{foo bar baz foo_2}.sort + expect(metric_names.sort).to eq(%w{foo bar baz foo_2}.sort) end end context "with a name argument" do it "should list metrics that match" do metric_names = Metrics.metrics(:name => 'foo').map { |metric| metric['name'] } - metric_names.sort.should == %w{foo foo_2}.sort + expect(metric_names.sort).to eq(%w{foo foo_2}.sort) end end @@ -185,13 +185,13 @@ module Librato it "should create the metrics" do metric = Metrics.metrics[0] - metric['name'].should == 'foo' - metric['type'].should == 'gauge' + expect(metric['name']).to eq('foo') + expect(metric['type']).to eq('gauge') end it "should store their data" do data = Metrics.get_measurements :foo, :count => 1 - data.should_not be_empty + expect(data).not_to be_empty data['unassigned'][0]['value'] == 123.0 end end @@ -204,13 +204,13 @@ module Librato it "should create the metrics" do metric = Metrics.metrics[0] - metric['name'].should == 'bar' - metric['type'].should == 'counter' + expect(metric['name']).to eq('bar') + expect(metric['type']).to eq('counter') end it "should store their data" do data = Metrics.get_measurements :bar, :count => 1 - data.should_not be_empty + expect(data).not_to be_empty data['baz'][0]['value'] == 456.0 end end @@ -218,12 +218,12 @@ module Librato it "should not retain errors" do delete_all_metrics Metrics.submit :foo => {:type => :counter, :value => 12} - lambda { + expect { Metrics.submit :foo => 15 # submitting as gauge - }.should raise_error - lambda { + }.to raise_error + expect { Metrics.submit :foo => {:type => :counter, :value => 17} - }.should_not raise_error + }.not_to raise_error end end @@ -244,9 +244,9 @@ module Librato :display_max => 1000 } foo = Metrics.get_metric :foo - foo['display_name'].should == 'Foo Metric' - foo['period'].should == 15 - foo['attributes']['display_max'].should == 1000 + expect(foo['display_name']).to eq('Foo Metric') + expect(foo['period']).to eq(15) + expect(foo['attributes']['display_max']).to eq(1000) end end @@ -260,20 +260,20 @@ module Librato :display_max => 1000 } foo = Metrics.get_metric :foo - foo['display_name'].should == 'Foo Metric' - foo['period'].should == 15 - foo['attributes']['display_max'].should == 1000 + expect(foo['display_name']).to eq('Foo Metric') + expect(foo['period']).to eq(15) + expect(foo['attributes']['display_max']).to eq(1000) end it "should raise error if no type specified" do delete_all_metrics - lambda { + expect { Metrics.update_metric :foo, :display_name => "Foo Metric", :period => 15, :attributes => { :display_max => 1000 } - }.should raise_error + }.to raise_error end end @@ -291,7 +291,7 @@ module Librato names.each do |name| metric = Metrics.get_metric name - metric['period'].should == 60 + expect(metric['period']).to eq(60) end end @@ -301,11 +301,11 @@ module Librato %w{my.1 my.2 my.4}.each do |name| metric = Metrics.get_metric name - metric['attributes']['display_max'].should == 100 + expect(metric['attributes']['display_max']).to eq(100) end excluded = Metrics.get_metric 'my.3' - excluded['attributes']['display_max'].should_not == 100 + expect(excluded['attributes']['display_max']).not_to eq(100) end end end @@ -318,21 +318,21 @@ module Librato describe "#sources" do it "should work" do sources = Metrics.sources - sources.should be_an(Array) + expect(sources).to be_an(Array) test_source = sources.detect { |s| s["name"] == "sources_api_test" } - test_source["display_name"].should == "Sources Api Test" + expect(test_source["display_name"]).to eq("Sources Api Test") end it "should allow filtering by name" do sources = Metrics.sources name: 'sources_api_test' - sources.all? {|s| s['name'] =~ /sources_api_test/}.should be_true + expect(sources.all? {|s| s['name'] =~ /sources_api_test/}).to be_truthy end end describe "#get_source" do it "should work" do test_source = Metrics.get_source("sources_api_test") - test_source["display_name"].should == "Sources Api Test" + expect(test_source["display_name"]).to eq("Sources Api Test") end end @@ -341,20 +341,20 @@ module Librato Metrics.update_source("sources_api_test", display_name: "Updated Source Name") test_source = Metrics.get_source("sources_api_test") - test_source["display_name"].should == "Updated Source Name" + expect(test_source["display_name"]).to eq("Updated Source Name") end it "should create new sources" do source_name = "sources_api_test_#{Time.now.to_f}" - lambda { + expect { no_source = Metrics.get_source(source_name) - }.should raise_error(Librato::Metrics::NotFound) + }.to raise_error(Librato::Metrics::NotFound) Metrics.update_source(source_name, display_name: "New Source") test_source = Metrics.get_source(source_name) - test_source.should_not be_nil - test_source["display_name"].should == "New Source" + expect(test_source).not_to be_nil + expect(test_source["display_name"]).to eq("New Source") end end From 4d8e7e128c57ac0ecb94e7df0310e2716bd6d55d Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 14:43:14 -0700 Subject: [PATCH 06/22] minor style changes --- spec/unit/metrics/client_spec.rb | 6 +++--- spec/unit/metrics/connection_spec.rb | 8 ++++---- spec/unit/metrics/queue_spec.rb | 2 +- spec/unit/metrics_spec.rb | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/unit/metrics/client_spec.rb b/spec/unit/metrics/client_spec.rb index 978e684..1c86ec6 100644 --- a/spec/unit/metrics/client_spec.rb +++ b/spec/unit/metrics/client_spec.rb @@ -29,7 +29,7 @@ module Metrics context "when given two arguments" do it "should raise error" do - expect{ subject.agent_identifier('test_app', '0.5') }.to raise_error(ArgumentError) + expect { subject.agent_identifier('test_app', '0.5') }.to raise_error(ArgumentError) end end end @@ -64,7 +64,7 @@ module Metrics describe "#connection" do it "should raise exception without authentication" do subject.flush_authentication - expect{ subject.connection }.to raise_error(Librato::Metrics::CredentialsMissing) + expect { subject.connection }.to raise_error(Librato::Metrics::CredentialsMissing) end end @@ -115,7 +115,7 @@ module Metrics it "should tolerate muliple metrics" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test - expect{ subject.submit :foo => 123, :bar => 456 }.not_to raise_error + expect { subject.submit :foo => 123, :bar => 456 }.not_to raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} expect(subject.persister.persisted).to equal_unordered(expected) end diff --git a/spec/unit/metrics/connection_spec.rb b/spec/unit/metrics/connection_spec.rb index 4b6281c..dcc29aa 100644 --- a/spec/unit/metrics/connection_spec.rb +++ b/spec/unit/metrics/connection_spec.rb @@ -52,7 +52,7 @@ module Metrics describe "network operations" do context "when missing client" do it "should raise exception" do - expect{ subject.get 'metrics' }.to raise_error(NoClientProvided) + expect { subject.get 'metrics' }.to raise_error(NoClientProvided) end end @@ -67,10 +67,10 @@ module Metrics it "should not retry" do Middleware::CountRequests.reset with_rackup('status.ru') do - expect{ + expect { client.connection.transport.post 'not_found' }.to raise_error(NotFound) - expect{ + expect { client.connection.transport.post 'forbidden' }.to raise_error(ClientError) end @@ -82,7 +82,7 @@ module Metrics it "should retry" do Middleware::CountRequests.reset with_rackup('status.ru') do - expect{ + expect { client.connection.transport.post 'service_unavailable' }.to raise_error(ServerError) end diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 3b412ee..991b355 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -132,7 +132,7 @@ module Metrics end it "should raise exception in invalid time" do - expect{ + expect { subject.add :foo => {:measure_time => '12', :value => 123} }.to raise_error(InvalidMeasureTime) end diff --git a/spec/unit/metrics_spec.rb b/spec/unit/metrics_spec.rb index 8069190..d2b7ec1 100644 --- a/spec/unit/metrics_spec.rb +++ b/spec/unit/metrics_spec.rb @@ -53,7 +53,7 @@ module Librato end it "should tolerate multiple metrics" do - expect{ Librato::Metrics.submit :foo => 123, :bar => 456 }.not_to raise_error + expect { Librato::Metrics.submit :foo => 123, :bar => 456 }.not_to raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} expect(Librato::Metrics.persister.persisted).to equal_unordered(expected) end From f2286f7cf30309379be185c5769a6e22dfe568e3 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 15:02:43 -0700 Subject: [PATCH 07/22] add some confidence to descriptions --- spec/integration/deprecated_methods_spec.rb | 10 +-- spec/integration/metrics/annotator_spec.rb | 34 ++++---- .../metrics/middleware/count_requests_spec.rb | 4 +- spec/integration/metrics/queue_spec.rb | 8 +- spec/integration/metrics_spec.rb | 60 +++++++------- spec/unit/metrics/aggregator_spec.rb | 38 ++++----- spec/unit/metrics/client_spec.rb | 30 +++---- spec/unit/metrics/connection_spec.rb | 20 ++--- .../unit/metrics/queue/autosubmission_spec.rb | 10 +-- spec/unit/metrics/queue_spec.rb | 80 +++++++++---------- spec/unit/metrics_spec.rb | 12 +-- 11 files changed, 153 insertions(+), 153 deletions(-) diff --git a/spec/integration/deprecated_methods_spec.rb b/spec/integration/deprecated_methods_spec.rb index b93beb3..9791553 100644 --- a/spec/integration/deprecated_methods_spec.rb +++ b/spec/integration/deprecated_methods_spec.rb @@ -28,7 +28,7 @@ it { is_expected.not_to be_nil } - it "should return a metric" do + it "returns a metric" do expect(metric["name"]).to eq("test_metric") end end @@ -40,7 +40,7 @@ it { is_expected.not_to be_nil } it { is_expected.not_to be_empty } - it "should return the measurements" do + it "returns the measurements" do expect(measurements).to have_key("unassigned") expect(measurements["unassigned"]).to be_an(Array) expect(measurements["unassigned"].first["value"]).to eq(123.0) @@ -55,7 +55,7 @@ it { is_expected.not_to be_nil } it { is_expected.not_to be_empty } - it "should return the list of metrics" do + it "returns the list of metrics" do metric = metrics.find { |m| m["name"] == "test_metric" } expect(metric).not_to be_nil end @@ -68,13 +68,13 @@ let(:updated_metric) { client.get_metric("test_metric") } - it "should update the metric" do + it "updates the metric" do expect(updated_metric["display_name"]).to eq("Test Deprecated Update") end end describe "#delete" do - it "should delete the metric" do + it "deletes the metric" do expect(client.metrics(:name => "test_metric")).not_to be_empty client.delete("test_metric") expect(client.metrics(:name => "test_metric")).to be_empty diff --git a/spec/integration/metrics/annotator_spec.rb b/spec/integration/metrics/annotator_spec.rb index 3686afd..fbaec8d 100644 --- a/spec/integration/metrics/annotator_spec.rb +++ b/spec/integration/metrics/annotator_spec.rb @@ -8,20 +8,20 @@ module Metrics before(:each) { delete_all_annotations } describe "#add" do - it "should create new annotation" do + it "creates new annotation" do subject.add :deployment, "deployed v68" annos = subject.fetch(:deployment, :start_time => Time.now.to_i-60) expect(annos["events"]["unassigned"].length).to eq(1) expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68') end - it "should support sources" do + it "supports sources" do subject.add :deployment, 'deployed v69', :source => 'box1' annos = subject.fetch(:deployment, :start_time => Time.now.to_i-60) expect(annos["events"]["box1"].length).to eq(1) first = annos["events"]["box1"][0] expect(first['title']).to eq('deployed v69') end - it "should support start and end times" do + it "supports start and end times" do start_time = Time.now.to_i-120 end_time = Time.now.to_i-30 subject.add :deployment, 'deployed v70', :start_time => start_time, @@ -33,7 +33,7 @@ module Metrics expect(first['start_time']).to eq(start_time) expect(first['end_time']).to eq(end_time) end - it "should support description" do + it "supports description" do subject.add :deployment, 'deployed v71', :description => 'deployed foobar!' annos = subject.fetch(:deployment, :start_time => Time.now.to_i-180) expect(annos["events"]["unassigned"].length).to eq(1) @@ -41,13 +41,13 @@ module Metrics expect(first['title']).to eq('deployed v71') expect(first['description']).to eq('deployed foobar!') end - it "should have an id for further use" do + it "has an id for further use" do annotation = subject.add :deployment, "deployed v23" expect(annotation['id']).not_to be_nil end context "with a block" do - it "should set both start and end times" do + it "sets both start and end times" do annotation = subject.add 'deploys', 'v345' do sleep 1.0 end @@ -59,7 +59,7 @@ module Metrics end describe "#delete" do - it "should remove annotation streams" do + it "removes annotation streams" do subject.add :deployment, "deployed v45" subject.fetch :deployment # should exist subject.delete :deployment @@ -70,7 +70,7 @@ module Metrics end describe "#delete_event" do - it "should remove an annotation event" do + it "removes an annotation event" do subject.add :deployment, 'deployed v46' subject.add :deployment, 'deployed v47' events = subject.fetch(:deployment, :start_time => Time.now.to_i-60) @@ -89,7 +89,7 @@ module Metrics describe "#fetch" do context "without a time frame" do - it "should return stream properties" do + it "returns stream properties" do subject.add :backups, "backup 21" properties = subject.fetch :backups expect(properties['name']).to eq('backups') @@ -97,7 +97,7 @@ module Metrics end context "with a time frame" do - it "should return set of annotations" do + it "returns set of annotations" do subject.add :backups, "backup 22" subject.add :backups, "backup 23" annos = subject.fetch :backups, :start_time => Time.now.to_i-60 @@ -105,7 +105,7 @@ module Metrics expect(events[0]['title']).to eq('backup 22') expect(events[1]['title']).to eq('backup 23') end - it "should respect source limits" do + it "respects source limits" do subject.add :backups, "backup 24", :source => 'server_1' subject.add :backups, "backup 25", :source => 'server_2' subject.add :backups, "backup 26", :source => 'server_3' @@ -117,7 +117,7 @@ module Metrics end end - it "should return exception if annotation is missing" do + it "returns exception if annotation is missing" do expect { subject.fetch :backups }.to raise_error(Metrics::NotFound) @@ -126,14 +126,14 @@ module Metrics describe "#fetch_event" do context "with existing event" do - it "should return event properties" do + it "returns event properties" do annotation = subject.add 'deploys', 'v69' data = subject.fetch_event 'deploys', annotation['id'] expect(data['title']).to eq('v69') end end context "when event doesn't exist" do - it "should raise NotFound" do + it "raises NotFound" do expect { data = subject.fetch_event 'deploys', 324 }.to raise_error(Metrics::NotFound) @@ -148,7 +148,7 @@ module Metrics end context "without arguments" do - it "should list annotation streams" do + it "lists annotation streams" do streams = subject.list expect(streams['annotations'].length).to eq(2) streams = streams['annotations'].map{|i| i['name']} @@ -157,7 +157,7 @@ module Metrics end end context "with an argument" do - it "should list annotation streams which match" do + it "lists annotation streams which match" do streams = subject.list :name => 'back' expect(streams['annotations'].length).to eq(1) streams = streams['annotations'].map{|i| i['name']} @@ -168,7 +168,7 @@ module Metrics describe "#update_event" do context "when event exists" do - it "should update event" do + it "updates event" do end_time = (Time.now + 60).to_i annotation = subject.add 'deploys', 'v24' subject.update_event 'deploys', annotation['id'], diff --git a/spec/integration/metrics/middleware/count_requests_spec.rb b/spec/integration/metrics/middleware/count_requests_spec.rb index 440a709..6479440 100644 --- a/spec/integration/metrics/middleware/count_requests_spec.rb +++ b/spec/integration/metrics/middleware/count_requests_spec.rb @@ -7,14 +7,14 @@ module Middleware describe CountRequests do before(:all) { prep_integration_tests } - it "should count requests" do + it "counts requests" do CountRequests.reset Metrics.submit :foo => 123 Metrics.submit :foo => 135 expect(CountRequests.total_requests).to eq(2) end - it "should be resettable" do + it "is resettable" do Metrics.submit :foo => 123 expect(CountRequests.total_requests).to be > 0 CountRequests.reset diff --git a/spec/integration/metrics/queue_spec.rb b/spec/integration/metrics/queue_spec.rb index cfa73e0..a776960 100644 --- a/spec/integration/metrics/queue_spec.rb +++ b/spec/integration/metrics/queue_spec.rb @@ -8,7 +8,7 @@ module Metrics before(:each) { delete_all_metrics } context "with a large number of metrics" do - it "should submit them in multiple requests" do + it "submits them in multiple requests" do Middleware::CountRequests.reset queue = Queue.new(:per_request => 3) (1..10).each do |i| @@ -18,7 +18,7 @@ module Metrics expect(Middleware::CountRequests.total_requests).to eq(4) end - it "should persist all metrics" do + it "persists all metrics" do queue = Queue.new(:per_request => 2) (1..5).each do |i| queue.add "gauge_#{i}" => i @@ -36,7 +36,7 @@ module Metrics expect(gauge['unassigned'][0]['value']).to eq(5) end - it "should apply globals to each request" do + it "applies globals to each request" do source = 'yogi' measure_time = Time.now.to_i-3 queue = Queue.new( @@ -57,7 +57,7 @@ module Metrics end end - it "should respect default and individual sources" do + it "respects default and individual sources" do queue = Queue.new(:source => 'default') queue.add :foo => 123 queue.add :bar => {:value => 456, :source => 'barsource'} diff --git a/spec/integration/metrics_spec.rb b/spec/integration/metrics_spec.rb index 09f0130..d9af584 100644 --- a/spec/integration/metrics_spec.rb +++ b/spec/integration/metrics_spec.rb @@ -8,20 +8,20 @@ module Librato before(:all) { @annotator = Metrics::Annotator.new } before(:each) { delete_all_annotations } - it "should create new annotation" do + it "creates new annotation" do Metrics.annotate :deployment, "deployed v68" annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-60) expect(annos["events"]["unassigned"].length).to eq(1) expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68') end - it "should support sources" do + it "supports sources" do Metrics.annotate :deployment, 'deployed v69', :source => 'box1' annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-60) expect(annos["events"]["box1"].length).to eq(1) first = annos["events"]["box1"][0] expect(first['title']).to eq('deployed v69') end - it "should support start and end times" do + it "supports start and end times" do start_time = Time.now.to_i-120 end_time = Time.now.to_i-30 Metrics.annotate :deployment, 'deployed v70', :start_time => start_time, @@ -33,7 +33,7 @@ module Librato expect(first['start_time']).to eq(start_time) expect(first['end_time']).to eq(end_time) end - it "should support description" do + it "supports description" do Metrics.annotate :deployment, 'deployed v71', :description => 'deployed foobar!' annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-180) expect(annos["events"]["unassigned"].length).to eq(1) @@ -49,7 +49,7 @@ module Librato context 'by names' do context "with a single argument" do - it "should delete named metric" do + it "deletes named metric" do Metrics.submit :foo => 123 expect(Metrics.metrics(:name => :foo)).not_to be_empty Metrics.delete_metrics :foo @@ -58,7 +58,7 @@ module Librato end context "with multiple arguments" do - it "should delete named metrics" do + it "deletes named metrics" do Metrics.submit :foo => 123, :bar => 345, :baz => 567 Metrics.delete_metrics :foo, :bar expect(Metrics.metrics(:name => :foo)).to be_empty @@ -68,7 +68,7 @@ module Librato end context "with missing metric" do - it "should run cleanly" do + it "runs cleanly" do # the API currently returns success even if # the metric has already been deleted or is absent. Metrics.delete_metrics :missing @@ -76,7 +76,7 @@ module Librato end context "with no arguments" do - it "should not make request" do + it "does not make request" do expect { Metrics.delete_metrics }.to raise_error(Metrics::NoMetricsProvided) @@ -86,7 +86,7 @@ module Librato end context 'by pattern' do - it "should filter properly" do + it "filters properly" do Metrics.submit :foo => 1, :foobar => 2, :foobaz => 3, :bar => 4 Metrics.delete_metrics :names => 'fo*', :exclude => ['foobar'] @@ -116,7 +116,7 @@ module Librato end context "without arguments" do - it "should get metric attributes" do + it "gets metric attributes" do metric = Metrics.get_metric :my_counter expect(metric['name']).to eq('my_counter') expect(metric['type']).to eq('counter') @@ -124,7 +124,7 @@ module Librato end context "with a start_time" do - it "should return entries since that time" do + it "returns entries since that time" do # 1 hr ago metric = Metrics.get_metric :my_counter, :start_time => Time.now-3600 data = metric['measurements'] @@ -134,7 +134,7 @@ module Librato end context "with a count limit" do - it "should return that number of entries per source" do + it "returns that number of entries per source" do metric = Metrics.get_metric :my_counter, :count => 2 data = metric['measurements'] expect(data['unassigned'].length).to eq(2) @@ -143,7 +143,7 @@ module Librato end context "with a source limit" do - it "should only return that source" do + it "only returns that source" do metric = Metrics.get_metric :my_counter, :source => 'baz', :start_time => Time.now-3600 data = metric['measurements'] expect(data['baz'].length).to eq(2) @@ -160,14 +160,14 @@ module Librato end context "without arguments" do - it "should list all metrics" do + it "lists all metrics" do metric_names = Metrics.metrics.map { |metric| metric['name'] } expect(metric_names.sort).to eq(%w{foo bar baz foo_2}.sort) end end context "with a name argument" do - it "should list metrics that match" do + it "lists metrics that match" do metric_names = Metrics.metrics(:name => 'foo').map { |metric| metric['name'] } expect(metric_names.sort).to eq(%w{foo foo_2}.sort) end @@ -183,13 +183,13 @@ module Librato Metrics.submit :foo => 123 end - it "should create the metrics" do + it "creates the metrics" do metric = Metrics.metrics[0] expect(metric['name']).to eq('foo') expect(metric['type']).to eq('gauge') end - it "should store their data" do + it "stores their data" do data = Metrics.get_measurements :foo, :count => 1 expect(data).not_to be_empty data['unassigned'][0]['value'] == 123.0 @@ -202,20 +202,20 @@ module Librato Metrics.submit :bar => {:type => :counter, :source => 'baz', :value => 456} end - it "should create the metrics" do + it "creates the metrics" do metric = Metrics.metrics[0] expect(metric['name']).to eq('bar') expect(metric['type']).to eq('counter') end - it "should store their data" do + it "stores their data" do data = Metrics.get_measurements :bar, :count => 1 expect(data).not_to be_empty data['baz'][0]['value'] == 456.0 end end - it "should not retain errors" do + it "does not retain errors" do delete_all_metrics Metrics.submit :foo => {:type => :counter, :value => 12} expect { @@ -237,7 +237,7 @@ module Librato Metrics.submit :foo => 123 end - it "should update the metric" do + it "updates the metric" do Metrics.update_metric :foo, :display_name => "Foo Metric", :period => 15, :attributes => { @@ -251,7 +251,7 @@ module Librato end context "without an existing metric" do - it "should create the metric if type specified" do + it "creates the metric if type specified" do delete_all_metrics Metrics.update_metric :foo, :display_name => "Foo Metric", :type => 'gauge', @@ -265,7 +265,7 @@ module Librato expect(foo['attributes']['display_max']).to eq(1000) end - it "should raise error if no type specified" do + it "raises error if no type specified" do delete_all_metrics expect { Metrics.update_metric :foo, :display_name => "Foo Metric", @@ -285,7 +285,7 @@ module Librato Metrics.submit 'my.1' => 1, 'my.2' => 2, 'my.3' => 3, 'my.4' => 4 end - it "should support named list" do + it "supports named list" do names = ['my.1', 'my.3'] Metrics.update_metrics :names => names, :period => 60 @@ -295,7 +295,7 @@ module Librato end end - it "should support patterns" do + it "supports patterns" do Metrics.update_metrics :names => 'my.*', :exclude => ['my.3'], :display_max => 100 @@ -316,35 +316,35 @@ module Librato end describe "#sources" do - it "should work" do + it "works" do sources = Metrics.sources expect(sources).to be_an(Array) test_source = sources.detect { |s| s["name"] == "sources_api_test" } expect(test_source["display_name"]).to eq("Sources Api Test") end - it "should allow filtering by name" do + it "allows filtering by name" do sources = Metrics.sources name: 'sources_api_test' expect(sources.all? {|s| s['name'] =~ /sources_api_test/}).to be_truthy end end describe "#get_source" do - it "should work" do + it "works" do test_source = Metrics.get_source("sources_api_test") expect(test_source["display_name"]).to eq("Sources Api Test") end end describe "#update_source" do - it "should update an existing source" do + it "updates an existing source" do Metrics.update_source("sources_api_test", display_name: "Updated Source Name") test_source = Metrics.get_source("sources_api_test") expect(test_source["display_name"]).to eq("Updated Source Name") end - it "should create new sources" do + it "creates new sources" do source_name = "sources_api_test_#{Time.now.to_f}" expect { no_source = Metrics.get_source(source_name) diff --git a/spec/unit/metrics/aggregator_spec.rb b/spec/unit/metrics/aggregator_spec.rb index 64cd52f..e71fc24 100644 --- a/spec/unit/metrics/aggregator_spec.rb +++ b/spec/unit/metrics/aggregator_spec.rb @@ -11,7 +11,7 @@ module Metrics describe "initialization" do context "with specified client" do - it "should set to client" do + it "sets to client" do barney = Client.new a = Aggregator.new(:client => barney) expect(a.client).to eq(barney) @@ -19,21 +19,21 @@ module Metrics end context "without specified client" do - it "should use Librato::Metrics client" do + it "uses Librato::Metrics client" do a = Aggregator.new expect(a.client).to eq(Librato::Metrics.client) end end context "with specified source" do - it "should set to source" do + it "sets to source" do a = Aggregator.new(:source => 'rubble') expect(a.source).to eq('rubble') end end context "without specified source" do - it "should not have a source" do + it "does not have a source" do a = Aggregator.new expect(a.source).to be_nil end @@ -41,12 +41,12 @@ module Metrics end describe "#add" do - it "should allow chaining" do + it "allows chaining" do expect(subject.add(:foo => 1234)).to eq(subject) end context "with single hash argument" do - it "should record a single aggregate" do + it "records a single aggregate" do subject.add :foo => 3000 expected = { #:measure_time => @time, TODO: support specific time :gauges => [ @@ -60,7 +60,7 @@ module Metrics expect(subject.queued).to equal_unordered(expected) end - it "should aggregate multiple measurements" do + it "aggregates multiple measurements" do subject.add :foo => 1 subject.add :foo => 2 subject.add :foo => 3 @@ -77,7 +77,7 @@ module Metrics expect(subject.queued).to equal_unordered(expected) end - it "should respect source argument" do + it "respects source argument" do subject.add :foo => {:source => 'alpha', :value => 1} subject.add :foo => 5 subject.add :foo => {:source => :alpha, :value => 6} @@ -92,7 +92,7 @@ module Metrics end context "with a prefix set" do - it "should auto-prepend names" do + it "auto-prepends names" do subject = Aggregator.new(:prefix => 'foo') subject.add :bar => 1 subject.add :bar => 12 @@ -111,7 +111,7 @@ module Metrics end context "with multiple hash arguments" do - it "should record a single aggregate" do + it "records a single aggregate" do subject.add :foo => 3000 subject.add :bar => 30 expected = { @@ -132,7 +132,7 @@ module Metrics expect(subject.queued).to equal_unordered(expected) end - it "should aggregate multiple measurements" do + it "aggregates multiple measurements" do subject.add :foo => 1 subject.add :foo => 2 subject.add :foo => 3 @@ -163,13 +163,13 @@ module Metrics end describe "#queued" do - it "should include global source if set" do + it "includes global source if set" do a = Aggregator.new(:source => 'blah') a.add :foo => 12 expect(a.queued[:source]).to eq('blah') end - it "should include global measure_time if set" do + it "includes global measure_time if set" do measure_time = (Time.now-1000).to_i a = Aggregator.new(:measure_time => measure_time) a.add :foo => 12 @@ -184,7 +184,7 @@ module Metrics end context "when successful" do - it "should flush queued metrics and return true" do + it "flushes queued metrics and return true" do subject.add :steps => 2042, :distance => 1234 expect(subject.submit).to be true expect(subject.empty?).to be true @@ -192,7 +192,7 @@ module Metrics end context "when failed" do - it "should preserve queue and return false" do + it "preserves queue and return false" do subject.add :steps => 2042, :distance => 1234 subject.persister.return_value(false) expect(subject.submit).to be false @@ -203,7 +203,7 @@ module Metrics describe "#time" do context "with metric name only" do - it "should queue metric with timed value" do + it "queues metric with timed value" do 1.upto(5) do subject.time :sleeping do sleep 0.1 @@ -216,7 +216,7 @@ module Metrics expect(queued[:sum]).to be_within(150).of(500) end - it "should return the result of the block" do + it "returns the result of the block" do result = subject.time :returning do :hi_there end @@ -233,13 +233,13 @@ module Metrics client end - it "should not submit immediately" do + it "does not submit immediately" do timed_agg = Aggregator.new(:client => client, :autosubmit_interval => 1) timed_agg.add :foo => 1 expect(timed_agg.persister.persisted).to be_nil # nothing sent end - it "should submit after interval" do + it "submits after interval" do timed_agg = Aggregator.new(:client => client, :autosubmit_interval => 1) timed_agg.add :foo => 1 sleep 1 diff --git a/spec/unit/metrics/client_spec.rb b/spec/unit/metrics/client_spec.rb index 1c86ec6..5a4a0d5 100644 --- a/spec/unit/metrics/client_spec.rb +++ b/spec/unit/metrics/client_spec.rb @@ -7,20 +7,20 @@ module Metrics describe "#agent_identifier" do context "when given a single string argument" do - it "should set agent_identifier" do + it "sets agent_identifier" do subject.agent_identifier 'mycollector/0.1 (dev_id:foo)' expect(subject.agent_identifier).to eq('mycollector/0.1 (dev_id:foo)') end end context "when given three arguments" do - it "should compose an agent string" do + it "composes an agent string" do subject.agent_identifier('test_app', '0.5', 'foobar') expect(subject.agent_identifier).to eq('test_app/0.5 (dev_id:foobar)') end context "when given an empty string" do - it "should set to empty" do + it "sets to empty" do subject.agent_identifier '' expect(subject.agent_identifier).to be_empty end @@ -28,20 +28,20 @@ module Metrics end context "when given two arguments" do - it "should raise error" do + it "raises error" do expect { subject.agent_identifier('test_app', '0.5') }.to raise_error(ArgumentError) end end end describe "#api_endpoint" do - it "should default to metrics" do + it "defaults to metrics" do expect(subject.api_endpoint).to eq('https://metrics-api.librato.com') end end describe "#api_endpoint=" do - it "should set api_endpoint" do + it "sets api_endpoint" do subject.api_endpoint = 'http://test.com/' expect(subject.api_endpoint).to eq('http://test.com/') end @@ -53,7 +53,7 @@ module Metrics describe "#authenticate" do context "when given two arguments" do - it "should store them as email and api_key" do + it "stores them as email and api_key" do subject.authenticate 'test@librato.com', 'api_key' expect(subject.email).to eq('test@librato.com') expect(subject.api_key).to eq('api_key') @@ -62,14 +62,14 @@ module Metrics end describe "#connection" do - it "should raise exception without authentication" do + it "raises exception without authentication" do subject.flush_authentication expect { subject.connection }.to raise_error(Librato::Metrics::CredentialsMissing) end end describe "#faraday_adapter" do - it "should default to Metrics default adapter" do + it "defaults to Metrics default adapter" do Metrics.faraday_adapter = :typhoeus expect(Client.new.faraday_adapter).to eq(Metrics.faraday_adapter) Metrics.faraday_adapter = nil @@ -77,7 +77,7 @@ module Metrics end describe "#faraday_adapter=" do - it "should allow setting of faraday adapter" do + it "allows setting of faraday adapter" do subject.faraday_adapter = :excon expect(subject.faraday_adapter).to eq(:excon) subject.faraday_adapter = :patron @@ -86,33 +86,33 @@ module Metrics end describe "#new_queue" do - it "should return a new queue with client set" do + it "returns a new queue with client set" do queue = subject.new_queue expect(queue.client).to eq(subject) end end describe "#persistence" do - it "should default to direct" do + it "defaults to direct" do subject.send(:flush_persistence) expect(subject.persistence).to eq(:direct) end - it "should allow configuration of persistence method" do + it "allows configuration of persistence method" do subject.persistence = :fake expect(subject.persistence).to eq(:fake) end end describe "#submit" do - it "should persist metrics immediately" do + it "persists metrics immediately" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test expect(subject.submit(:foo => 123)).to be true expect(subject.persister.persisted).to eq({:gauges => [{:name => 'foo', :value => 123}]}) end - it "should tolerate muliple metrics" do + it "tolerates muliple metrics" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test expect { subject.submit :foo => 123, :bar => 456 }.not_to raise_error diff --git a/spec/unit/metrics/connection_spec.rb b/spec/unit/metrics/connection_spec.rb index dcc29aa..7e1a456 100644 --- a/spec/unit/metrics/connection_spec.rb +++ b/spec/unit/metrics/connection_spec.rb @@ -7,13 +7,13 @@ module Metrics describe "#api_endpoint" do context "when not provided" do - it "should be default" do + it "uses default" do expect(subject.api_endpoint).to eq('https://metrics-api.librato.com') end end context "when provided" do - it "should be respected" do + it "uses provided endpoint" do connection = Connection.new(:api_endpoint => 'http://test.com/') expect(connection.api_endpoint).to eq('http://test.com/') end @@ -22,14 +22,14 @@ module Metrics describe "#user_agent" do context "without an agent_identifier" do - it "should render standard string" do + it "renders standard string" do connection = Connection.new(:client => Client.new) expect(connection.user_agent).to start_with('librato-metrics') end end context "with an agent_identifier" do - it "should render agent_identifier first" do + it "renders agent_identifier first" do client = Client.new client.agent_identifier('foo', '0.5', 'bar') connection = Connection.new(:client => client) @@ -38,7 +38,7 @@ module Metrics end context "with a custom user agent set" do - it "should use custom user agent" do + it "uses custom user agent" do client = Client.new client.custom_user_agent = 'foo agent' connection = Connection.new(:client => client) @@ -51,7 +51,7 @@ module Metrics describe "network operations" do context "when missing client" do - it "should raise exception" do + it "raises exception" do expect { subject.get 'metrics' }.to raise_error(NoClientProvided) end end @@ -64,7 +64,7 @@ module Metrics end context "with 400 class errors" do - it "should not retry" do + it "does not retry" do Middleware::CountRequests.reset with_rackup('status.ru') do expect { @@ -79,7 +79,7 @@ module Metrics end context "with 500 class errors" do - it "should retry" do + it "retries" do Middleware::CountRequests.reset with_rackup('status.ru') do expect { @@ -89,7 +89,7 @@ module Metrics expect(Middleware::CountRequests.total_requests).to eq(4) # did retries end - it "should send consistent body with retries" do + it "sends consistent body with retries" do Middleware::CountRequests.reset status = 0 begin @@ -103,7 +103,7 @@ module Metrics status = error.response[:status].to_i end expect(Middleware::CountRequests.total_requests).to eq(4) # did retries - expect(status).to eq(502) #, 'body should be sent for retries' + expect(status).to eq(502) # body is sent for retries end end end diff --git a/spec/unit/metrics/queue/autosubmission_spec.rb b/spec/unit/metrics/queue/autosubmission_spec.rb index 8dd426f..27607bf 100644 --- a/spec/unit/metrics/queue/autosubmission_spec.rb +++ b/spec/unit/metrics/queue/autosubmission_spec.rb @@ -8,21 +8,21 @@ module Metrics let(:client) { Client.new.tap{ |c| c.persistence = :test } } context "with an autosubmit count" do - it "should submit when the max is reached" do + it "submits when the max is reached" do vol_queue = Queue.new(:client => client, :autosubmit_count => 2) vol_queue.add :foo => 1 vol_queue.add :bar => 2 expect(vol_queue.persister.persisted).not_to be_nil # sent end - it "should not submit if the max has not been reached" do + it "does not submit if the max has not been reached" do vol_queue = Queue.new(:client => client, :autosubmit_count => 5) vol_queue.add :foo => 1 vol_queue.add :bar => 2 expect(vol_queue.persister.persisted).to be_nil # nothing sent end - it 'should submit when merging' do + it 'submits when merging' do queue = Queue.new(:client => client, :autosubmit_count => 5) (1..3).each {|i| queue.add "metric_#{i}" => 1 } @@ -37,13 +37,13 @@ module Metrics end context "with an autosubmit interval" do - it "should not submit immediately" do + it "does not submit immediately" do vol_queue = Queue.new(:client => client, :autosubmit_interval => 1) vol_queue.add :foo => 1 expect(vol_queue.persister.persisted).to be_nil # nothing sent end - it "should submit after interval" do + it "submits after interval" do vol_queue = Queue.new(:client => client, :autosubmit_interval => 1) vol_queue.add :foo => 1 sleep 1 diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 991b355..8a6bad7 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -12,7 +12,7 @@ module Metrics describe "initialization" do context "with specified client" do - it "should set to client" do + it "sets to client" do barney = Client queue = Queue.new(:client => barney) expect(queue.client).to eq(barney) @@ -20,7 +20,7 @@ module Metrics end context "without specified client" do - it "should use Librato::Metrics client" do + it "uses Librato::Metrics client" do queue = Queue.new expect(queue.client).to eq(Librato::Metrics.client) end @@ -28,12 +28,12 @@ module Metrics end describe "#add" do - it "should allow chaining" do + it "allows chaining" do expect(subject.add(:foo => 123)).to eq(subject) end context "with single hash argument" do - it "should record a key-value gauge" do + it "records a key-value gauge" do expected = {:gauges => [{:name => 'foo', :value => 3000, :measure_time => @time}]} subject.add :foo => 3000 expect(subject.queued).to equal_unordered(expected) @@ -41,19 +41,19 @@ module Metrics end context "with specified metric type" do - it "should record counters" do + it "records counters" do subject.add :total_visits => {:type => :counter, :value => 4000} expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]} expect(subject.queued).to equal_unordered(expected) end - it "should record gauges" do + it "records gauges" do subject.add :temperature => {:type => :gauge, :value => 34} expected = {:gauges => [{:name => 'temperature', :value => 34, :measure_time => @time}]} expect(subject.queued).to equal_unordered(expected) end - it "should accept type key as string or a symbol" do + it "accepts type key as string or a symbol" do subject.add :total_visits => {"type" => "counter", :value => 4000} expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]} expect(subject.queued).to equal_unordered(expected) @@ -61,7 +61,7 @@ module Metrics end context "with extra attributes" do - it "should record" do + it "records" do measure_time = Time.now subject.add :disk_use => {:value => 35.4, :period => 2, :description => 'current disk utilization', :measure_time => measure_time, @@ -73,7 +73,7 @@ module Metrics end context "with a prefix set" do - it "should auto-prepend names" do + it "auto-prepends names" do subject = Queue.new(:prefix => 'foo') subject.add :bar => 1 subject.add :baz => {:value => 23} @@ -84,7 +84,7 @@ module Metrics end context "when dynamically changing prefix" do - it "should auto-append names" do + it "auto-appends names" do subject.add :bar => 12 subject.prefix = 'foo' # with string subject.add :bar => 23 @@ -103,7 +103,7 @@ module Metrics end context "with multiple metrics" do - it "should record" do + it "records" do subject.add :foo => 123, :bar => 345, :baz => 567 expected = {:gauges=>[{:name=>"foo", :value=>123, :measure_time => @time}, {:name=>"bar", :value=>345, :measure_time => @time}, @@ -113,25 +113,25 @@ module Metrics end context "with a measure_time" do - it "should accept time objects" do + it "accepts time objects" do time = Time.now-5 subject.add :foo => {:measure_time => time, :value => 123} expect(subject.queued[:gauges][0][:measure_time]).to eq(time.to_i) end - it "should accept integers" do + it "accepts integers" do time = @time.to_i subject.add :foo => {:measure_time => time, :value => 123} expect(subject.queued[:gauges][0][:measure_time]).to eq(time) end - it "should accept strings" do + it "accepts strings" do time = @time.to_s subject.add :foo => {:measure_time => time, :value => 123} expect(subject.queued[:gauges][0][:measure_time]).to eq(time.to_i) end - it "should raise exception in invalid time" do + it "raises exception in invalid time" do expect { subject.add :foo => {:measure_time => '12', :value => 123} }.to raise_error(InvalidMeasureTime) @@ -140,36 +140,36 @@ module Metrics end describe "#counters" do - it "should return currently queued counters" do + it "returns currently queued counters" do subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} expect(subject.counters).to eq([{:name => 'transactions', :value => 12345, :measure_time => @time}]) end - it "should return [] when no queued counters" do + it "returns [] when no queued counters" do expect(subject.counters).to be_empty end end describe "#empty?" do - it "should return true when nothing queued" do + it "returns true when nothing queued" do expect(subject.empty?).to be true end - it "should return false with queued items" do + it "returns false with queued items" do subject.add :foo => {:type => :gauge, :value => 121212} expect(subject.empty?).to be false end end describe "#gauges" do - it "should return currently queued gauges" do + it "returns currently queued gauges" do subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} expect(subject.gauges).to eq([{:name => 'register_cents', :value => 211101, :measure_time => @time}]) end - it "should return [] when no queued gauges" do + it "returns [] when no queued gauges" do expect(subject.gauges).to be_empty end end @@ -180,11 +180,11 @@ module Metrics Librato::Metrics.persistence = :test end - it "should default to nil" do + it "defaults to nil" do expect(subject.last_submit_time).to be_nil end - it "should store last submission time" do + it "stores last submission time" do prior = Time.now subject.add :foo => 123 subject.submit @@ -194,7 +194,7 @@ module Metrics describe "#merge!" do context "with another queue" do - it "should merge gauges" do + it "merges gauges" do q1 = Queue.new q1.add :foo => 123, :bar => 456 q2 = Queue.new @@ -206,7 +206,7 @@ module Metrics expect(q2.queued).to equal_unordered(expected) end - it "should merge counters" do + it "merges counters" do q1 = Queue.new q1.add :users => {:type => :counter, :value => 1000} q1.add :sales => {:type => :counter, :value => 250} @@ -219,7 +219,7 @@ module Metrics expect(q2.queued).to equal_unordered(expected) end - it "should maintain specified sources" do + it "maintains specified sources" do q1 = Queue.new q1.add :neo => {:source => 'matrix', :value => 123} q2 = Queue.new(:source => 'red_pill') @@ -227,7 +227,7 @@ module Metrics expect(q2.queued[:gauges][0][:source]).to eq('matrix') end - it "should not change default source" do + it "does not change default source" do q1 = Queue.new(:source => 'matrix') q1.add :neo => 456 q2 = Queue.new(:source => 'red_pill') @@ -235,7 +235,7 @@ module Metrics expect(q2.queued[:source]).to eq('red_pill') end - it "should track previous default source" do + it "tracks previous default source" do q1 = Queue.new(:source => 'matrix') q1.add :neo => 456 q2 = Queue.new(:source => 'red_pill') @@ -248,7 +248,7 @@ module Metrics end end - it "should handle empty cases" do + it "handles empty cases" do q1 = Queue.new q1.add :foo => 123, :users => {:type => :counter, :value => 1000} q2 = Queue.new @@ -260,7 +260,7 @@ module Metrics end context "with an aggregator" do - it "should merge" do + it "merges" do aggregator = Aggregator.new(:source => 'aggregator') aggregator.add :timing => 102 aggregator.add :timing => 203 @@ -275,7 +275,7 @@ module Metrics end context "with a hash" do - it "should merge" do + it "merges" do to_merge = {:gauges=>[{:name => 'foo', :value => 123}], :counters=>[{:name => 'bar', :value => 456}]} q = Queue.new @@ -287,19 +287,19 @@ module Metrics end describe "#per_request" do - it "should default to 500" do + it "defaults to 500" do expect(subject.per_request).to eq(500) end end describe "#queued" do - it "should include global source if set" do + it "includes global source if set" do q = Queue.new(:source => 'blah') q.add :foo => 12 expect(q.queued[:source]).to eq('blah') end - it "should include global measure_time if set" do + it "includes global measure_time if set" do measure_time = (Time.now-1000).to_i q = Queue.new(:measure_time => measure_time) q.add :foo => 12 @@ -308,10 +308,10 @@ module Metrics end describe "#size" do - it "should return empty if gauges and counters are emtpy" do + it "returns empty if gauges and counters are emtpy" do expect(subject.size).to be_zero end - it "should return count of gauges and counters if added" do + it "returns count of gauges and counters if added" do subject.add :transactions => {:type => :counter, :value => 12345}, :register_cents => {:type => :gauge, :value => 211101} subject.add :transactions => {:type => :counter, :value => 12345}, @@ -327,7 +327,7 @@ module Metrics end context "when successful" do - it "should flush queued metrics and return true" do + it "flushes queued metrics and return true" do subject.add :steps => 2042, :distance => 1234 expect(subject.submit).to be true expect(subject.queued).to be_empty @@ -335,7 +335,7 @@ module Metrics end context "when failed" do - it "should preserve queue and return false" do + it "preserves queue and return false" do subject.add :steps => 2042, :distance => 1234 subject.persister.return_value(false) expect(subject.submit).to be false @@ -346,7 +346,7 @@ module Metrics describe "#time" do context "with metric name only" do - it "should queue metric with timed value" do + it "queues metric with timed value" do subject.time :sleeping do sleep 0.1 end @@ -358,7 +358,7 @@ module Metrics end context "with metric and options" do - it "should queue metric with value and options" do + it "queues metric with value and options" do subject.time :sleep_two, :source => 'app1', :period => 2 do sleep 0.05 end diff --git a/spec/unit/metrics_spec.rb b/spec/unit/metrics_spec.rb index d2b7ec1..823b23e 100644 --- a/spec/unit/metrics_spec.rb +++ b/spec/unit/metrics_spec.rb @@ -6,7 +6,7 @@ module Librato describe "#authorize" do context "when given two arguments" do - it "should store them on simple" do + it "stores them on simple" do Metrics.authenticate 'tester@librato.com', 'api_key' expect(Metrics.client.email).to eq('tester@librato.com') expect(Metrics.client.api_key).to eq('api_key') @@ -15,7 +15,7 @@ module Librato end describe "#faraday_adapter" do - it "should return current default adapter" do + it "returns current default adapter" do expect(Metrics.faraday_adapter).not_to be_nil end end @@ -24,7 +24,7 @@ module Librato before(:all) { @current_adapter = Metrics.faraday_adapter } after(:all) { Metrics.faraday_adapter = @current_adapter } - it "should allow setting of faraday adapter" do + it "allows setting of faraday adapter" do Metrics.faraday_adapter = :excon expect(Metrics.faraday_adapter).to eq(:excon) Metrics.faraday_adapter = :patron @@ -33,7 +33,7 @@ module Librato end describe "#persistence" do - it "should allow configuration of persistence method" do + it "allows configuration of persistence method" do Metrics.persistence = :test expect(Metrics.persistence).to eq(:test) end @@ -46,13 +46,13 @@ module Librato end after(:all) { Librato::Metrics.client.flush_authentication } - it "should persist metrics immediately" do + it "persists metrics immediately" do Metrics.persistence = :test expect(Metrics.submit(:foo => 123)).to be true expect(Metrics.persister.persisted).to eq({:gauges => [{:name => 'foo', :value => 123}]}) end - it "should tolerate multiple metrics" do + it "tolerates multiple metrics" do expect { Librato::Metrics.submit :foo => 123, :bar => 456 }.not_to raise_error expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} expect(Librato::Metrics.persister.persisted).to equal_unordered(expected) From 47dde359e855104b75c1c1a49b2ee9adad545299 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 10 Aug 2016 15:18:59 -0700 Subject: [PATCH 08/22] update context description --- spec/integration/metrics_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/metrics_spec.rb b/spec/integration/metrics_spec.rb index d9af584..3f67046 100644 --- a/spec/integration/metrics_spec.rb +++ b/spec/integration/metrics_spec.rb @@ -46,7 +46,7 @@ module Librato describe "#delete_metrics" do before(:each) { delete_all_metrics } - context 'by names' do + context 'with names' do context "with a single argument" do it "deletes named metric" do @@ -85,7 +85,7 @@ module Librato end - context 'by pattern' do + context 'with patterns' do it "filters properly" do Metrics.submit :foo => 1, :foobar => 2, :foobaz => 3, :bar => 4 Metrics.delete_metrics :names => 'fo*', :exclude => ['foobar'] From d1517cc6442a0c89d1de2becdb72eca08f7becca Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 11:56:37 -0700 Subject: [PATCH 09/22] remove deprecated methods --- lib/librato/metrics.rb | 9 +-- lib/librato/metrics/client.rb | 67 ---------------- spec/integration/deprecated_methods_spec.rb | 85 --------------------- spec/integration/metrics/queue_spec.rb | 2 +- 4 files changed, 4 insertions(+), 159 deletions(-) delete mode 100644 spec/integration/deprecated_methods_spec.rb diff --git a/lib/librato/metrics.rb b/lib/librato/metrics.rb index 3b109e7..e0b3134 100644 --- a/lib/librato/metrics.rb +++ b/lib/librato/metrics.rb @@ -26,7 +26,7 @@ module Librato # Librato::Metrics.authenticate 'email', 'api_key' # # # list current metrics - # Librato::Metrics.list + # Librato::Metrics.metrics # # # submit a metric immediately # Librato::Metrics.submit :foo => 12712 @@ -49,7 +49,7 @@ module Librato # client.authenticate 'email', 'api_key' # # # list client's metrics - # client.list + # client.metrics # # # create an associated queue # queue = client.new_queue @@ -81,10 +81,7 @@ module Metrics :delete_metrics, :update_metric, :update_metrics, :submit, :sources, :get_source, :update_source, - :create_snapshot, :get_snapshot, - # Deprecated metrics methods - :fetch, :list, :delete, :update - + :create_snapshot, :get_snapshot # The Librato::Metrics::Client being used by module-level # access. diff --git a/lib/librato/metrics/client.rb b/lib/librato/metrics/client.rb index 14a8ca1..965c077 100644 --- a/lib/librato/metrics/client.rb +++ b/lib/librato/metrics/client.rb @@ -109,12 +109,6 @@ def delete_metrics(*metric_names) true end - # Completely delete metrics with the given names. Be - # careful with this, this is instant and permanent. - # - # @deprecated Use {#delete_metrics} instead - def delete(*metric_names); delete_metrics(*metric_names); end - # Return current adapter this client will use. # Defaults to Metrics.faraday_adapter if set, otherwise # Faraday.default_adapter @@ -127,42 +121,6 @@ def faraday_adapter=(adapter) @faraday_adapter = adapter end - # Query metric data - # - # @deprecated Use {#get_metric} or {#get_measurements} instead. - # - # @example Get attributes for a metric - # attrs = Librato::Metrics.fetch :temperature - # - # @example Get 20 most recent data points for metric - # data = Librato::Metrics.fetch :temperature, :count => 20 - # - # @example Get 20 most recent data points for a specific source - # data = Librato::Metrics.fetch :temperature, :count => 20, - # :source => 'app1' - # - # @example Get the 20 most recent 15 minute data point rollups - # data = Librato::Metrics.fetch :temperature, :count => 20, - # :resolution => 900 - # - # @example Get data points for the last hour - # data = Librato::Metrics.fetch :start_time => Time.now-3600 - # - # @example Get 15 min data points from two hours to an hour ago - # data = Librato::Metrics.fetch :start_time => Time.now-7200, - # :end_time => Time.now-3600, - # :resolution => 900 - # - # A full list of query parameters can be found in the API - # documentation: {http://dev.librato.com/v1/get/metrics/:name} - # - # @param [Symbol|String] metric Metric name - # @param [Hash] options Query options - def fetch(metric, options={}) - metric = get_metric(metric, options) - options.empty? ? metric : metric["measurements"] - end - # Retrieve measurements for a given composite metric definition. # :start_time and :resolution are required options, :end_time is # optional. @@ -276,11 +234,6 @@ def metrics(options={}) Collection.paginated_metrics(connection, path, query) end - # List currently existing metrics - # - # @deprecated Use {#metrics} instead - def list(options={}); metrics(options); end - # Create a new queue which uses this client. # # @return [Queue] @@ -351,26 +304,6 @@ def update_metrics(metrics) end end - # Update one or more metrics. Note that attributes are specified in - # their own hash for updating a single metric but are included inline - # when updating multiple metrics. - # - # @deprecated Use {#update_metric} or {#update_metrics} instead - def update(metric, options={}) - if metric.respond_to?(:each) - update_metrics(metric) - else - update_metric(metric, options) - end - end - - # Update one or more metrics. Note that attributes are specified in - # their own hash for updating a single metric but are included inline - # when updating multiple metrics. - # - # @deprecated Use #update_metric instead - alias update update_metric - # List sources, optionally limited by a name. See http://dev.librato.com/v1/sources # and http://dev.librato.com/v1/get/sources # diff --git a/spec/integration/deprecated_methods_spec.rb b/spec/integration/deprecated_methods_spec.rb deleted file mode 100644 index 9791553..0000000 --- a/spec/integration/deprecated_methods_spec.rb +++ /dev/null @@ -1,85 +0,0 @@ -require 'spec_helper' - -DEPRECATED_METHODS = %w[fetch list update delete] -describe Librato::Metrics do - - DEPRECATED_METHODS.each do |deprecated_method| - it { is_expected.to respond_to(deprecated_method) } - end - - describe "Client" do - let(:client) { Librato::Metrics.client } - subject { client } - - before(:all) { prep_integration_tests } - - before do - client.submit :test_metric => 123.0 - end - - DEPRECATED_METHODS.each do |deprecated_method| - it { is_expected.to respond_to(deprecated_method) } - end - - describe "#fetch" do - context "with no measurements attributes" do - let(:metric) { client.fetch(:test_metric) } - subject { metric } - - it { is_expected.not_to be_nil } - - it "returns a metric" do - expect(metric["name"]).to eq("test_metric") - end - end - - context "with measurements attributes" do - let(:measurements) { client.fetch(:test_metric, :count => 1) } - subject { measurements } - - it { is_expected.not_to be_nil } - it { is_expected.not_to be_empty } - - it "returns the measurements" do - expect(measurements).to have_key("unassigned") - expect(measurements["unassigned"]).to be_an(Array) - expect(measurements["unassigned"].first["value"]).to eq(123.0) - end - end - end - - describe "#list" do - let(:metrics) { client.list } - subject { metrics } - - it { is_expected.not_to be_nil } - it { is_expected.not_to be_empty } - - it "returns the list of metrics" do - metric = metrics.find { |m| m["name"] == "test_metric" } - expect(metric).not_to be_nil - end - end - - describe "#update" do - before do - client.update("test_metric", :display_name => "Test Deprecated Update") - end - - let(:updated_metric) { client.get_metric("test_metric") } - - it "updates the metric" do - expect(updated_metric["display_name"]).to eq("Test Deprecated Update") - end - end - - describe "#delete" do - it "deletes the metric" do - expect(client.metrics(:name => "test_metric")).not_to be_empty - client.delete("test_metric") - expect(client.metrics(:name => "test_metric")).to be_empty - end - end - - end -end diff --git a/spec/integration/metrics/queue_spec.rb b/spec/integration/metrics/queue_spec.rb index a776960..6872c11 100644 --- a/spec/integration/metrics/queue_spec.rb +++ b/spec/integration/metrics/queue_spec.rb @@ -28,7 +28,7 @@ module Metrics end queue.submit - metrics = Metrics.list + metrics = Metrics.metrics expect(metrics.length).to eq(8) counter = Metrics.get_measurements :counter_3, :count => 1 expect(counter['unassigned'][0]['value']).to eq(3) From d5aa0a56f61251f25862c33fae56b7f6357d818e Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 12:10:34 -0700 Subject: [PATCH 10/22] unlock faraday version --- librato-metrics.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librato-metrics.gemspec b/librato-metrics.gemspec index a1a1c4c..ea79cf4 100644 --- a/librato-metrics.gemspec +++ b/librato-metrics.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |s| s.extra_rdoc_files = %w[LICENSE] ## runtime dependencies - s.add_dependency 'faraday', '~> 0.7' + s.add_dependency 'faraday' s.add_dependency 'multi_json' s.add_dependency 'aggregate', '~> 0.2.2' From 837c1c0832da933d3702a979c0e78c69729bbb16 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 13:46:59 -0700 Subject: [PATCH 11/22] remove multijson runtime dep --- lib/librato/metrics/smart_json.rb | 16 ++++++++++++---- librato-metrics.gemspec | 1 - 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/librato/metrics/smart_json.rb b/lib/librato/metrics/smart_json.rb index d97f318..3912a60 100644 --- a/lib/librato/metrics/smart_json.rb +++ b/lib/librato/metrics/smart_json.rb @@ -1,11 +1,19 @@ -require 'multi_json' +USE_MULTI_JSON = defined?(MultiJson) + +require 'json' unless USE_MULTI_JSON +require 'multi_json' if USE_MULTI_JSON module Librato module Metrics class SmartJSON - JSON_HANDLER = MultiJson + JSON_HANDLER = + if USE_MULTI_JSON + MultiJson + else + JSON # ships with 1.9 + end extend SingleForwardable - + # wrap MultiJSON's implementation so we can use any version # prefer modern syntax if available; def once at startup if JSON_HANDLER.respond_to?(:load) @@ -13,7 +21,7 @@ class SmartJSON else def_delegator JSON_HANDLER, :decode, :read end - + if JSON_HANDLER.respond_to?(:dump) def_delegator JSON_HANDLER, :dump, :write else diff --git a/librato-metrics.gemspec b/librato-metrics.gemspec index ea79cf4..f204037 100644 --- a/librato-metrics.gemspec +++ b/librato-metrics.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |s| ## runtime dependencies s.add_dependency 'faraday' - s.add_dependency 'multi_json' s.add_dependency 'aggregate', '~> 0.2.2' # omitting for now because jruby-19mode can't handle From 91897be0181ddd45a8bca5ae67e024eaba7ef8d9 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 13:58:46 -0700 Subject: [PATCH 12/22] remove hashrockets --- examples/simple.rb | 10 +- lib/librato/metrics.rb | 12 +- lib/librato/metrics/aggregator.rb | 12 +- lib/librato/metrics/annotator.rb | 22 +-- lib/librato/metrics/client.rb | 48 ++--- lib/librato/metrics/connection.rb | 4 +- lib/librato/metrics/processor.rb | 6 +- lib/librato/metrics/queue.rb | 2 +- spec/integration/metrics/annotator_spec.rb | 36 ++-- .../metrics/middleware/count_requests_spec.rb | 6 +- spec/integration/metrics/queue_spec.rb | 30 +-- spec/integration/metrics_spec.rb | 100 +++++----- spec/spec_helper.rb | 2 +- spec/unit/metrics/aggregator_spec.rb | 174 ++++++++--------- spec/unit/metrics/client_spec.rb | 8 +- spec/unit/metrics/connection_spec.rb | 8 +- .../unit/metrics/queue/autosubmission_spec.rb | 26 +-- spec/unit/metrics/queue_spec.rb | 180 +++++++++--------- spec/unit/metrics_spec.rb | 8 +- 19 files changed, 347 insertions(+), 347 deletions(-) diff --git a/examples/simple.rb b/examples/simple.rb index 679c68c..36be84c 100644 --- a/examples/simple.rb +++ b/examples/simple.rb @@ -3,13 +3,13 @@ Librato::Metrics.authenticate 'my email', 'my api key' # send a measurement of 12 for 'foo' -Librato::Metrics.submit :cpu => 54 +Librato::Metrics.submit cpu: 54 # submit multiple metrics at once -Librato::Metrics.submit :cpu => 63, :memory => 213 +Librato::Metrics.submit cpu: 63, memory: 213 # submit a metric with a custom source -Librato::Metrics.submit :cpu => {:source => 'myapp', :value => 75} +Librato::Metrics.submit cpu: {source: 'myapp', value: 75} # if you are sending many metrics it is much more performant # to submit them in sets rather than individually: @@ -17,8 +17,8 @@ queue = Librato::Metrics::Queue.new queue.add 'disk.free' => 1223121 -queue.add :memory => 2321 -queue.add :cpu => {:source => 'myapp', :value => 52} +queue.add memory: 2321 +queue.add cpu: {source: 'myapp', value: 52} #... queue.submit \ No newline at end of file diff --git a/lib/librato/metrics.rb b/lib/librato/metrics.rb index e0b3134..dd72ba4 100644 --- a/lib/librato/metrics.rb +++ b/lib/librato/metrics.rb @@ -29,17 +29,17 @@ module Librato # Librato::Metrics.metrics # # # submit a metric immediately - # Librato::Metrics.submit :foo => 12712 + # Librato::Metrics.submit foo: 12712 # # # fetch the last 10 values of foo - # Librato::Metrics.get_measurements :foo, :count => 10 + # Librato::Metrics.get_measurements :foo, count: 10 # # @example Queuing metrics for submission # queue = Librato::Metrics::Queue.new # # # queue some metrics - # queue.add :foo => 12312 - # queue.add :bar => 45678 + # queue.add foo: 12312 + # queue.add bar: 45678 # # # send the metrics # queue.submit @@ -55,8 +55,8 @@ module Librato # queue = client.new_queue # # # queue up some metrics and submit - # queue.add :foo => 12345 - # queue.add :bar => 45678 + # queue.add foo: 12345 + # queue.add bar: 45678 # queue.submit # # @note Most of the methods you can call directly on Librato::Metrics are diff --git a/lib/librato/metrics/aggregator.rb b/lib/librato/metrics/aggregator.rb index fdb5dc9..843eb89 100644 --- a/lib/librato/metrics/aggregator.rb +++ b/lib/librato/metrics/aggregator.rb @@ -97,20 +97,20 @@ def queued metric, source = metric.split(SOURCE_SEPARATOR) end entry = { - :name => metric, - :count => data.count, - :sum => data.sum, + name: metric, + count: data.count, + sum: data.sum, # TODO: make float/non-float consistent in the gem - :min => data.min.to_f, - :max => data.max.to_f + min: data.min.to_f, + max: data.max.to_f # TODO: expose v.sum2 and include } entry[:source] = source if source gauges << entry end - req = { :gauges => gauges } + req = { gauges: gauges } req[:source] = @source if @source req[:measure_time] = @measure_time if @measure_time diff --git a/lib/librato/metrics/annotator.rb b/lib/librato/metrics/annotator.rb index 11200aa..552cceb 100644 --- a/lib/librato/metrics/annotator.rb +++ b/lib/librato/metrics/annotator.rb @@ -14,15 +14,15 @@ def initialize(options={}) # annotator.add :deployments, 'deployed v45' # # @example Annotation with start and end times - # annotator.add :deployments, 'deployed v56', :start_time => start, - # :end_time => end_time + # annotator.add :deployments, 'deployed v56', start_time: start, + # end_time: end_time # # @example Annotation with a specific source - # annotator.add :deployments, 'deployed v60', :source => 'app12' + # annotator.add :deployments, 'deployed v60', source: 'app12' # # @example Annotation with a description # annotator.add :deployments, 'deployed v61', - # :description => '9b562b2: shipped new feature foo!' + # description: '9b562b2: shipped new feature foo!' # # @example Annotate with automatic start and end times # annotator.add(:deployments, 'deployed v62') do @@ -41,7 +41,7 @@ def add(stream, title, options={}) event = SmartJSON.read(response.body) if block_given? yield - update_event stream, event['id'], :end_time => Time.now.to_i + update_event stream, event['id'], end_time: Time.now.to_i # need to get updated representation event = fetch_event stream, event['id'] end @@ -85,12 +85,12 @@ def delete_event(stream, id) # annotator.fetch :deployments # # @example Get events on 'deployments' between start and end times - # annotator.fetch :deployments, :start_time => start, - # :end_time => end_time + # annotator.fetch :deployments, start_time: start, + # end_time: end_time # # @example Source-limited listing - # annotator.fetch :deployments, :sources => ['foo','bar','baz'], - # :start_time => start, :end_time => end_time + # annotator.fetch :deployments, sources: ['foo','bar','baz'], + # start_time: start, end_time: end_time # def fetch(stream, options={}) response = connection.get("annotations/#{stream}", options) @@ -113,7 +113,7 @@ def fetch_event(stream, id) # streams = annotator.list # # @example List annotator streams with 'deploy' in the name - # deploy_streams = annotator.list :name => 'deploy' + # deploy_streams = annotator.list name: 'deploy' # def list(options={}) response = connection.get("annotations", options) @@ -123,7 +123,7 @@ def list(options={}) # Update an event's properties # # @example Set an end time for a previously submitted event - # annotator.update_event 'deploys', 'v24', :end_time => end_time + # annotator.update_event 'deploys', 'v24', end_time: end_time # def update_event(stream, id, options={}) url = "annotations/#{stream}/#{id}" diff --git a/lib/librato/metrics/client.rb b/lib/librato/metrics/client.rb index 965c077..0e35586 100644 --- a/lib/librato/metrics/client.rb +++ b/lib/librato/metrics/client.rb @@ -31,7 +31,7 @@ def agent_identifier(*args) end def annotator - @annotator ||= Annotator.new(:client => self) + @annotator ||= Annotator.new(client: self) end # API endpoint to use for queries and direct @@ -65,8 +65,8 @@ def authenticate(email, api_key) def connection # prevent successful creation if no credentials set raise CredentialsMissing unless (self.email and self.api_key) - @connection ||= Connection.new(:client => self, :api_endpoint => api_endpoint, - :adapter => faraday_adapter, :proxy => self.proxy) + @connection ||= Connection.new(client: self, api_endpoint: api_endpoint, + adapter: faraday_adapter, proxy: self.proxy) end # Overrride user agent for this client's connections. If you @@ -92,14 +92,14 @@ def custom_user_agent # Librato::Metrics.delete_metrics :foo, :bar # # @example Delete metrics that start with 'foo' except 'foobar' - # Librato::Metrics.delete_metrics :names => 'foo*', :exclude => ['foobar'] + # Librato::Metrics.delete_metrics names: 'foo*', exclude: ['foobar'] # def delete_metrics(*metric_names) raise(NoMetricsProvided, 'Metric name missing.') if metric_names.empty? if metric_names[0].respond_to?(:keys) # hash form params = metric_names[0] else - params = { :names => metric_names.map(&:to_s) } + params = { names: metric_names.map(&:to_s) } end connection.delete do |request| request.url connection.build_url("metrics") @@ -128,7 +128,7 @@ def faraday_adapter=(adapter) # @example Get 5m moving average of 'foo' # measurements = Librato::Metrics.get_composite # 'moving_average(mean(series("foo", "*"), {size: "5"}))', - # :start_time => Time.now.to_i - 60*60, :resolution => 300 + # start_time: Time.now.to_i - 60*60, resolution: 300 # # @param [String] definition Composite definition # @param [hash] options Query options @@ -151,7 +151,7 @@ def get_composite(definition, options={}) # metric = Librato::Metrics.get_metric :temperature # # @example Get a metric and its 20 most recent data points - # metric = Librato::Metrics.get_metric :temperature, :count => 20 + # metric = Librato::Metrics.get_metric :temperature, count: 20 # metric['measurements'] # => {...} # # A full list of query parameters can be found in the API @@ -181,23 +181,23 @@ def get_metric(name, options = {}) # Retrieve data points for a specific metric # # @example Get 20 most recent data points for metric - # data = Librato::Metrics.get_measurements :temperature, :count => 20 + # data = Librato::Metrics.get_measurements :temperature, count: 20 # # @example Get 20 most recent data points for a specific source - # data = Librato::Metrics.get_measurements :temperature, :count => 20, - # :source => 'app1' + # data = Librato::Metrics.get_measurements :temperature, count: 20, + # source: 'app1' # # @example Get the 20 most recent 15 minute data point rollups - # data = Librato::Metrics.get_measurements :temperature, :count => 20, - # :resolution => 900 + # data = Librato::Metrics.get_measurements :temperature, count: 20, + # resolution: 900 # # @example Get data points for the last hour - # data = Librato::Metrics.get_measurements :start_time => Time.now-3600 + # data = Librato::Metrics.get_measurements start_time: Time.now-3600 # # @example Get 15 min data points from two hours to an hour ago - # data = Librato::Metrics.get_measurements :start_time => Time.now-7200, - # :end_time => Time.now-3600, - # :resolution => 900 + # data = Librato::Metrics.get_measurements start_time: Time.now-7200, + # end_time: Time.now-3600, + # resolution: 900 # # A full list of query parameters can be found in the API # documentation: {http://dev.librato.com/v1/get/metrics/:name} @@ -223,7 +223,7 @@ def flush_authentication # Librato::Metrics.metrics # # @example List metrics with 'foo' in the name - # Librato::Metrics.metrics :name => 'foo' + # Librato::Metrics.metrics name: 'foo' # # @param [Hash] options def metrics(options={}) @@ -265,9 +265,9 @@ def persister # Submit all queued metrics. # def submit(args) - @queue ||= Queue.new(:client => self, - :skip_measurement_times => true, - :clear_failures => true) + @queue ||= Queue.new(client: self, + skip_measurement_times: true, + clear_failures: true) @queue.add args @queue.submit end @@ -275,10 +275,10 @@ def submit(args) # Update a single metric with new attributes. # # @example Update metric 'temperature' - # Librato::Metrics.update_metric :temperature, :period => 15, :attributes => { :color => 'F00' } + # Librato::Metrics.update_metric :temperature, period: 15, attributes: { color: 'F00' } # # @example Update metric 'humidity', creating it if it doesn't exist - # Librato::Metrics.update_metric 'humidity', :type => :gauge, :period => 60, :display_name => 'Humidity' + # Librato::Metrics.update_metric 'humidity', type: :gauge, period: 60, display_name: 'Humidity' # def update_metric(metric, options = {}) url = "metrics/#{metric}" @@ -291,10 +291,10 @@ def update_metric(metric, options = {}) # Update multiple metrics. # # @example Update multiple metrics by name - # Librato::Metrics.update_metrics :names => ["foo", "bar"], :period => 60 + # Librato::Metrics.update_metrics names: ["foo", "bar"], period: 60 # # @example Update all metrics that start with 'foo' that aren't 'foobar' - # Librato::Metrics.update_metrics :names => 'foo*', :exclude => ['foobar'], :display_min => 0 + # Librato::Metrics.update_metrics names: 'foo*', exclude: ['foobar'], display_min: 0 # def update_metrics(metrics) url = "metrics" # update multiple metrics diff --git a/lib/librato/metrics/connection.rb b/lib/librato/metrics/connection.rb index abae123..86b5f2a 100644 --- a/lib/librato/metrics/connection.rb +++ b/lib/librato/metrics/connection.rb @@ -31,8 +31,8 @@ def api_endpoint def transport raise(NoClientProvided, "No client provided.") unless @client @transport ||= Faraday::Connection.new( - :url => api_endpoint + "/v1/", - :request => {:open_timeout => 20, :timeout => 30}) do |f| + url: api_endpoint + "/v1/", + request: {open_timeout: 20, timeout: 30}) do |f| f.use Librato::Metrics::Middleware::RequestBody f.use Librato::Metrics::Middleware::Retry diff --git a/lib/librato/metrics/processor.rb b/lib/librato/metrics/processor.rb index 242336d..64616d1 100644 --- a/lib/librato/metrics/processor.rb +++ b/lib/librato/metrics/processor.rb @@ -30,7 +30,7 @@ def persister # @return Boolean def submit return true if self.queued.empty? - options = {:per_request => @per_request} + options = {per_request: @per_request} if persister.persist(self.client, self.queued, options) @last_submit_time = Time.now clear and return true @@ -54,7 +54,7 @@ def submit # end # # @example Queue API request response time w/ source - # queue.time :api_request_time, :source => 'app1' do + # queue.time :api_request_time, source: 'app1' do # # API request.. # end # @@ -64,7 +64,7 @@ def time(name, options={}) start = Time.now yield.tap do duration = (Time.now - start) * 1000.0 # milliseconds - metric = {name => options.merge({:value => duration})} + metric = {name => options.merge({value: duration})} add metric end end diff --git a/lib/librato/metrics/queue.rb b/lib/librato/metrics/queue.rb index 184d183..ad46319 100644 --- a/lib/librato/metrics/queue.rb +++ b/lib/librato/metrics/queue.rb @@ -33,7 +33,7 @@ def add(measurements) metric[:name] = key.to_s type = metric.delete(:type) || metric.delete('type') || 'gauge' else - metric = {:name => key.to_s, :value => value} + metric = {name: key.to_s, value: value} type = :gauge end if @prefix diff --git a/spec/integration/metrics/annotator_spec.rb b/spec/integration/metrics/annotator_spec.rb index fbaec8d..4c9e2bc 100644 --- a/spec/integration/metrics/annotator_spec.rb +++ b/spec/integration/metrics/annotator_spec.rb @@ -10,13 +10,13 @@ module Metrics describe "#add" do it "creates new annotation" do subject.add :deployment, "deployed v68" - annos = subject.fetch(:deployment, :start_time => Time.now.to_i-60) + annos = subject.fetch(:deployment, start_time: Time.now.to_i-60) expect(annos["events"]["unassigned"].length).to eq(1) expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68') end it "supports sources" do - subject.add :deployment, 'deployed v69', :source => 'box1' - annos = subject.fetch(:deployment, :start_time => Time.now.to_i-60) + subject.add :deployment, 'deployed v69', source: 'box1' + annos = subject.fetch(:deployment, start_time: Time.now.to_i-60) expect(annos["events"]["box1"].length).to eq(1) first = annos["events"]["box1"][0] expect(first['title']).to eq('deployed v69') @@ -24,9 +24,9 @@ module Metrics it "supports start and end times" do start_time = Time.now.to_i-120 end_time = Time.now.to_i-30 - subject.add :deployment, 'deployed v70', :start_time => start_time, - :end_time => end_time - annos = subject.fetch(:deployment, :start_time => Time.now.to_i-180) + subject.add :deployment, 'deployed v70', start_time: start_time, + end_time: end_time + annos = subject.fetch(:deployment, start_time: Time.now.to_i-180) expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] expect(first['title']).to eq('deployed v70') @@ -34,8 +34,8 @@ module Metrics expect(first['end_time']).to eq(end_time) end it "supports description" do - subject.add :deployment, 'deployed v71', :description => 'deployed foobar!' - annos = subject.fetch(:deployment, :start_time => Time.now.to_i-180) + subject.add :deployment, 'deployed v71', description: 'deployed foobar!' + annos = subject.fetch(:deployment, start_time: Time.now.to_i-180) expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] expect(first['title']).to eq('deployed v71') @@ -73,14 +73,14 @@ module Metrics it "removes an annotation event" do subject.add :deployment, 'deployed v46' subject.add :deployment, 'deployed v47' - events = subject.fetch(:deployment, :start_time => Time.now.to_i-60) + events = subject.fetch(:deployment, start_time: Time.now.to_i-60) events = events['events']['unassigned'] ids = events.reduce({}) do |hash, event| hash[event['title']] = event['id'] hash end subject.delete_event :deployment, ids['deployed v47'] - events = subject.fetch(:deployment, :start_time => Time.now.to_i-60) + events = subject.fetch(:deployment, start_time: Time.now.to_i-60) events = events['events']['unassigned'] expect(events.length).to eq(1) expect(events[0]['title']).to eq('deployed v46') @@ -100,17 +100,17 @@ module Metrics it "returns set of annotations" do subject.add :backups, "backup 22" subject.add :backups, "backup 23" - annos = subject.fetch :backups, :start_time => Time.now.to_i-60 + annos = subject.fetch :backups, start_time: Time.now.to_i-60 events = annos['events']['unassigned'] expect(events[0]['title']).to eq('backup 22') expect(events[1]['title']).to eq('backup 23') end it "respects source limits" do - subject.add :backups, "backup 24", :source => 'server_1' - subject.add :backups, "backup 25", :source => 'server_2' - subject.add :backups, "backup 26", :source => 'server_3' - annos = subject.fetch :backups, :start_time => Time.now.to_i-60, - :sources => %w{server_1 server_3} + subject.add :backups, "backup 24", source: 'server_1' + subject.add :backups, "backup 25", source: 'server_2' + subject.add :backups, "backup 26", source: 'server_3' + annos = subject.fetch :backups, start_time: Time.now.to_i-60, + sources: %w{server_1 server_3} expect(annos['events']['server_1']).not_to be_nil expect(annos['events']['server_2']).to be_nil expect(annos['events']['server_3']).not_to be_nil @@ -158,7 +158,7 @@ module Metrics end context "with an argument" do it "lists annotation streams which match" do - streams = subject.list :name => 'back' + streams = subject.list name: 'back' expect(streams['annotations'].length).to eq(1) streams = streams['annotations'].map{|i| i['name']} expect(streams).to include('backups') @@ -172,7 +172,7 @@ module Metrics end_time = (Time.now + 60).to_i annotation = subject.add 'deploys', 'v24' subject.update_event 'deploys', annotation['id'], - :end_time => end_time, :title => 'v28' + end_time: end_time, title: 'v28' data = subject.fetch_event 'deploys', annotation['id'] expect(data['title']).to eq('v28') diff --git a/spec/integration/metrics/middleware/count_requests_spec.rb b/spec/integration/metrics/middleware/count_requests_spec.rb index 6479440..641f32f 100644 --- a/spec/integration/metrics/middleware/count_requests_spec.rb +++ b/spec/integration/metrics/middleware/count_requests_spec.rb @@ -9,13 +9,13 @@ module Middleware it "counts requests" do CountRequests.reset - Metrics.submit :foo => 123 - Metrics.submit :foo => 135 + Metrics.submit foo: 123 + Metrics.submit foo: 135 expect(CountRequests.total_requests).to eq(2) end it "is resettable" do - Metrics.submit :foo => 123 + Metrics.submit foo: 123 expect(CountRequests.total_requests).to be > 0 CountRequests.reset expect(CountRequests.total_requests).to eq(0) diff --git a/spec/integration/metrics/queue_spec.rb b/spec/integration/metrics/queue_spec.rb index 6872c11..1ae0a0c 100644 --- a/spec/integration/metrics/queue_spec.rb +++ b/spec/integration/metrics/queue_spec.rb @@ -10,7 +10,7 @@ module Metrics context "with a large number of metrics" do it "submits them in multiple requests" do Middleware::CountRequests.reset - queue = Queue.new(:per_request => 3) + queue = Queue.new(per_request: 3) (1..10).each do |i| queue.add "gauge_#{i}" => 1 end @@ -19,20 +19,20 @@ module Metrics end it "persists all metrics" do - queue = Queue.new(:per_request => 2) + queue = Queue.new(per_request: 2) (1..5).each do |i| queue.add "gauge_#{i}" => i end (1..3).each do |i| - queue.add "counter_#{i}" => {:type => :counter, :value => i} + queue.add "counter_#{i}" => {type: :counter, value: i} end queue.submit metrics = Metrics.metrics expect(metrics.length).to eq(8) - counter = Metrics.get_measurements :counter_3, :count => 1 + counter = Metrics.get_measurements :counter_3, count: 1 expect(counter['unassigned'][0]['value']).to eq(3) - gauge = Metrics.get_measurements :gauge_5, :count => 1 + gauge = Metrics.get_measurements :gauge_5, count: 1 expect(gauge['unassigned'][0]['value']).to eq(5) end @@ -40,10 +40,10 @@ module Metrics source = 'yogi' measure_time = Time.now.to_i-3 queue = Queue.new( - :per_request => 3, - :source => source, - :measure_time => measure_time, - :skip_measurement_times => true + per_request: 3, + source: source, + measure_time: measure_time, + skip_measurement_times: true ) (1..5).each do |i| queue.add "gauge_#{i}" => 1 @@ -51,22 +51,22 @@ module Metrics queue.submit # verify globals have persisted for all requests - gauge = Metrics.get_measurements :gauge_5, :count => 1 + gauge = Metrics.get_measurements :gauge_5, count: 1 expect(gauge[source][0]["value"]).to eq(1.0) expect(gauge[source][0]["measure_time"]).to eq(measure_time) end end it "respects default and individual sources" do - queue = Queue.new(:source => 'default') - queue.add :foo => 123 - queue.add :bar => {:value => 456, :source => 'barsource'} + queue = Queue.new(source: 'default') + queue.add foo: 123 + queue.add bar: {value: 456, source: 'barsource'} queue.submit - foo = Metrics.get_measurements :foo, :count => 2 + foo = Metrics.get_measurements :foo, count: 2 expect(foo['default'][0]['value']).to eq(123) - bar = Metrics.get_measurements :bar, :count => 2 + bar = Metrics.get_measurements :bar, count: 2 expect(bar['barsource'][0]['value']).to eq(456) end diff --git a/spec/integration/metrics_spec.rb b/spec/integration/metrics_spec.rb index 3f67046..590b565 100644 --- a/spec/integration/metrics_spec.rb +++ b/spec/integration/metrics_spec.rb @@ -10,13 +10,13 @@ module Librato it "creates new annotation" do Metrics.annotate :deployment, "deployed v68" - annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-60) + annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-60) expect(annos["events"]["unassigned"].length).to eq(1) expect(annos["events"]["unassigned"][0]["title"]).to eq('deployed v68') end it "supports sources" do - Metrics.annotate :deployment, 'deployed v69', :source => 'box1' - annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-60) + Metrics.annotate :deployment, 'deployed v69', source: 'box1' + annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-60) expect(annos["events"]["box1"].length).to eq(1) first = annos["events"]["box1"][0] expect(first['title']).to eq('deployed v69') @@ -24,9 +24,9 @@ module Librato it "supports start and end times" do start_time = Time.now.to_i-120 end_time = Time.now.to_i-30 - Metrics.annotate :deployment, 'deployed v70', :start_time => start_time, - :end_time => end_time - annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-180) + Metrics.annotate :deployment, 'deployed v70', start_time: start_time, + end_time: end_time + annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-180) expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] expect(first['title']).to eq('deployed v70') @@ -34,8 +34,8 @@ module Librato expect(first['end_time']).to eq(end_time) end it "supports description" do - Metrics.annotate :deployment, 'deployed v71', :description => 'deployed foobar!' - annos = @annotator.fetch(:deployment, :start_time => Time.now.to_i-180) + Metrics.annotate :deployment, 'deployed v71', description: 'deployed foobar!' + annos = @annotator.fetch(:deployment, start_time: Time.now.to_i-180) expect(annos["events"]["unassigned"].length).to eq(1) first = annos["events"]["unassigned"][0] expect(first['title']).to eq('deployed v71') @@ -50,20 +50,20 @@ module Librato context "with a single argument" do it "deletes named metric" do - Metrics.submit :foo => 123 - expect(Metrics.metrics(:name => :foo)).not_to be_empty + Metrics.submit foo: 123 + expect(Metrics.metrics(name: :foo)).not_to be_empty Metrics.delete_metrics :foo - expect(Metrics.metrics(:name => :foo)).to be_empty + expect(Metrics.metrics(name: :foo)).to be_empty end end context "with multiple arguments" do it "deletes named metrics" do - Metrics.submit :foo => 123, :bar => 345, :baz => 567 + Metrics.submit foo: 123, bar: 345, baz: 567 Metrics.delete_metrics :foo, :bar - expect(Metrics.metrics(:name => :foo)).to be_empty - expect(Metrics.metrics(:name => :bar)).to be_empty - expect(Metrics.metrics(:name => :baz)).not_to be_empty + expect(Metrics.metrics(name: :foo)).to be_empty + expect(Metrics.metrics(name: :bar)).to be_empty + expect(Metrics.metrics(name: :baz)).not_to be_empty end end @@ -87,8 +87,8 @@ module Librato context 'with patterns' do it "filters properly" do - Metrics.submit :foo => 1, :foobar => 2, :foobaz => 3, :bar => 4 - Metrics.delete_metrics :names => 'fo*', :exclude => ['foobar'] + Metrics.submit foo: 1, foobar: 2, foobaz: 3, bar: 4 + Metrics.delete_metrics names: 'fo*', exclude: ['foobar'] %w{foo foobaz}.each do |name| expect { @@ -106,12 +106,12 @@ module Librato describe "#get_metric" do before(:all) do delete_all_metrics - Metrics.submit :my_counter => {:type => :counter, :value => 0, :measure_time => Time.now.to_i-60} + Metrics.submit my_counter: {type: :counter, value: 0, measure_time: Time.now.to_i-60} 1.upto(2).each do |i| measure_time = Time.now.to_i - (5+i) - opts = {:measure_time => measure_time, :type => :counter} - Metrics.submit :my_counter => opts.merge(:value => i) - Metrics.submit :my_counter => opts.merge(:source => 'baz', :value => i+1) + opts = {measure_time: measure_time, type: :counter} + Metrics.submit my_counter: opts.merge(value: i) + Metrics.submit my_counter: opts.merge(source: 'baz', value: i+1) end end @@ -126,7 +126,7 @@ module Librato context "with a start_time" do it "returns entries since that time" do # 1 hr ago - metric = Metrics.get_metric :my_counter, :start_time => Time.now-3600 + metric = Metrics.get_metric :my_counter, start_time: Time.now-3600 data = metric['measurements'] expect(data['unassigned'].length).to eq(3) expect(data['baz'].length).to eq(2) @@ -135,7 +135,7 @@ module Librato context "with a count limit" do it "returns that number of entries per source" do - metric = Metrics.get_metric :my_counter, :count => 2 + metric = Metrics.get_metric :my_counter, count: 2 data = metric['measurements'] expect(data['unassigned'].length).to eq(2) expect(data['baz'].length).to eq(2) @@ -144,7 +144,7 @@ module Librato context "with a source limit" do it "only returns that source" do - metric = Metrics.get_metric :my_counter, :source => 'baz', :start_time => Time.now-3600 + metric = Metrics.get_metric :my_counter, source: 'baz', start_time: Time.now-3600 data = metric['measurements'] expect(data['baz'].length).to eq(2) expect(data['unassigned']).to be_nil @@ -156,7 +156,7 @@ module Librato describe "#metrics" do before(:all) do delete_all_metrics - Metrics.submit :foo => 123, :bar => 345, :baz => 678, :foo_2 => 901 + Metrics.submit foo: 123, bar: 345, baz: 678, foo_2: 901 end context "without arguments" do @@ -168,7 +168,7 @@ module Librato context "with a name argument" do it "lists metrics that match" do - metric_names = Metrics.metrics(:name => 'foo').map { |metric| metric['name'] } + metric_names = Metrics.metrics(name: 'foo').map { |metric| metric['name'] } expect(metric_names.sort).to eq(%w{foo foo_2}.sort) end end @@ -180,7 +180,7 @@ module Librato context "with a gauge" do before(:all) do delete_all_metrics - Metrics.submit :foo => 123 + Metrics.submit foo: 123 end it "creates the metrics" do @@ -190,7 +190,7 @@ module Librato end it "stores their data" do - data = Metrics.get_measurements :foo, :count => 1 + data = Metrics.get_measurements :foo, count: 1 expect(data).not_to be_empty data['unassigned'][0]['value'] == 123.0 end @@ -199,7 +199,7 @@ module Librato context "with a counter" do before(:all) do delete_all_metrics - Metrics.submit :bar => {:type => :counter, :source => 'baz', :value => 456} + Metrics.submit bar: {type: :counter, source: 'baz', value: 456} end it "creates the metrics" do @@ -209,7 +209,7 @@ module Librato end it "stores their data" do - data = Metrics.get_measurements :bar, :count => 1 + data = Metrics.get_measurements :bar, count: 1 expect(data).not_to be_empty data['baz'][0]['value'] == 456.0 end @@ -217,12 +217,12 @@ module Librato it "does not retain errors" do delete_all_metrics - Metrics.submit :foo => {:type => :counter, :value => 12} + Metrics.submit foo: {type: :counter, value: 12} expect { - Metrics.submit :foo => 15 # submitting as gauge + Metrics.submit foo: 15 # submitting as gauge }.to raise_error expect { - Metrics.submit :foo => {:type => :counter, :value => 17} + Metrics.submit foo: {type: :counter, value: 17} }.not_to raise_error end @@ -234,14 +234,14 @@ module Librato context "with an existing metric" do before do delete_all_metrics - Metrics.submit :foo => 123 + Metrics.submit foo: 123 end it "updates the metric" do - Metrics.update_metric :foo, :display_name => "Foo Metric", - :period => 15, - :attributes => { - :display_max => 1000 + Metrics.update_metric :foo, display_name: "Foo Metric", + period: 15, + attributes: { + display_max: 1000 } foo = Metrics.get_metric :foo expect(foo['display_name']).to eq('Foo Metric') @@ -253,11 +253,11 @@ module Librato context "without an existing metric" do it "creates the metric if type specified" do delete_all_metrics - Metrics.update_metric :foo, :display_name => "Foo Metric", - :type => 'gauge', - :period => 15, - :attributes => { - :display_max => 1000 + Metrics.update_metric :foo, display_name: "Foo Metric", + type: 'gauge', + period: 15, + attributes: { + display_max: 1000 } foo = Metrics.get_metric :foo expect(foo['display_name']).to eq('Foo Metric') @@ -268,10 +268,10 @@ module Librato it "raises error if no type specified" do delete_all_metrics expect { - Metrics.update_metric :foo, :display_name => "Foo Metric", - :period => 15, - :attributes => { - :display_max => 1000 + Metrics.update_metric :foo, display_name: "Foo Metric", + period: 15, + attributes: { + display_max: 1000 } }.to raise_error end @@ -287,7 +287,7 @@ module Librato it "supports named list" do names = ['my.1', 'my.3'] - Metrics.update_metrics :names => names, :period => 60 + Metrics.update_metrics names: names, period: 60 names.each do |name| metric = Metrics.get_metric name @@ -296,8 +296,8 @@ module Librato end it "supports patterns" do - Metrics.update_metrics :names => 'my.*', :exclude => ['my.3'], - :display_max => 100 + Metrics.update_metrics names: 'my.*', exclude: ['my.3'], + display_max: 100 %w{my.1 my.2 my.4}.each do |name| metric = Metrics.get_metric name diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bd3690e..81597df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -74,7 +74,7 @@ def with_rackup(name) # sets before comparision # # @example -# {:foo => [1,3,2]}.should equal_unordered({:foo => [1,2,3]}) +# {foo: [1,3,2]}.should equal_unordered({foo: [1,2,3]}) RSpec::Matchers.define :equal_unordered do |result| result.each do |key, value| result[key] = value.to_set if value.respond_to?(:to_set) diff --git a/spec/unit/metrics/aggregator_spec.rb b/spec/unit/metrics/aggregator_spec.rb index e71fc24..8b82d6d 100644 --- a/spec/unit/metrics/aggregator_spec.rb +++ b/spec/unit/metrics/aggregator_spec.rb @@ -13,7 +13,7 @@ module Metrics context "with specified client" do it "sets to client" do barney = Client.new - a = Aggregator.new(:client => barney) + a = Aggregator.new(client: barney) expect(a.client).to eq(barney) end end @@ -27,7 +27,7 @@ module Metrics context "with specified source" do it "sets to source" do - a = Aggregator.new(:source => 'rubble') + a = Aggregator.new(source: 'rubble') expect(a.source).to eq('rubble') end end @@ -42,66 +42,66 @@ module Metrics describe "#add" do it "allows chaining" do - expect(subject.add(:foo => 1234)).to eq(subject) + expect(subject.add(foo: 1234)).to eq(subject) end context "with single hash argument" do it "records a single aggregate" do - subject.add :foo => 3000 - expected = { #:measure_time => @time, TODO: support specific time - :gauges => [ - { :name => 'foo', - :count => 1, - :sum => 3000.0, - :min => 3000.0, - :max => 3000.0} + subject.add foo: 3000 + expected = { #measure_time: @time, TODO: support specific time + gauges: [ + { name: 'foo', + count: 1, + sum: 3000.0, + min: 3000.0, + max: 3000.0} ] } expect(subject.queued).to equal_unordered(expected) end it "aggregates multiple measurements" do - subject.add :foo => 1 - subject.add :foo => 2 - subject.add :foo => 3 - subject.add :foo => 4 - subject.add :foo => 5 - expected = { :gauges => [ - { :name => 'foo', - :count => 5, - :sum => 15.0, - :min => 1.0, - :max => 5.0} + subject.add foo: 1 + subject.add foo: 2 + subject.add foo: 3 + subject.add foo: 4 + subject.add foo: 5 + expected = { gauges: [ + { name: 'foo', + count: 5, + sum: 15.0, + min: 1.0, + max: 5.0} ] } expect(subject.queued).to equal_unordered(expected) end it "respects source argument" do - subject.add :foo => {:source => 'alpha', :value => 1} - subject.add :foo => 5 - subject.add :foo => {:source => :alpha, :value => 6} - subject.add :foo => 10 - expected = { :gauges => [ - { :name => 'foo', :source => 'alpha', :count => 2, - :sum => 7.0, :min => 1.0, :max => 6.0 }, - { :name => 'foo', :count => 2, - :sum => 15.0, :min => 5.0, :max => 10.0 } + subject.add foo: {source: 'alpha', value: 1} + subject.add foo: 5 + subject.add foo: {source: :alpha, value: 6} + subject.add foo: 10 + expected = { gauges: [ + { name: 'foo', source: 'alpha', count: 2, + sum: 7.0, min: 1.0, max: 6.0 }, + { name: 'foo', count: 2, + sum: 15.0, min: 5.0, max: 10.0 } ]} expect(subject.queued).to equal_unordered(expected) end context "with a prefix set" do it "auto-prepends names" do - subject = Aggregator.new(:prefix => 'foo') - subject.add :bar => 1 - subject.add :bar => 12 - expected = {:gauges => [ - { :name =>'foo.bar', - :count => 2, - :sum => 13.0, - :min => 1.0, - :max => 12.0 + subject = Aggregator.new(prefix: 'foo') + subject.add bar: 1 + subject.add bar: 12 + expected = {gauges: [ + { name:'foo.bar', + count: 2, + sum: 13.0, + min: 1.0, + max: 12.0 } ] } @@ -112,49 +112,49 @@ module Metrics context "with multiple hash arguments" do it "records a single aggregate" do - subject.add :foo => 3000 - subject.add :bar => 30 + subject.add foo: 3000 + subject.add bar: 30 expected = { - #:measure_time => @time, TODO: support specific time - :gauges => [ - { :name => 'foo', - :count => 1, - :sum => 3000.0, - :min => 3000.0, - :max => 3000.0}, - { :name => 'bar', - :count => 1, - :sum => 30.0, - :min => 30.0, - :max => 30.0}, + #measure_time: @time, TODO: support specific time + gauges: [ + { name: 'foo', + count: 1, + sum: 3000.0, + min: 3000.0, + max: 3000.0}, + { name: 'bar', + count: 1, + sum: 30.0, + min: 30.0, + max: 30.0}, ] } expect(subject.queued).to equal_unordered(expected) end it "aggregates multiple measurements" do - subject.add :foo => 1 - subject.add :foo => 2 - subject.add :foo => 3 - subject.add :foo => 4 - subject.add :foo => 5 - - subject.add :bar => 6 - subject.add :bar => 7 - subject.add :bar => 8 - subject.add :bar => 9 - subject.add :bar => 10 - expected = { :gauges => [ - { :name => 'foo', - :count => 5, - :sum => 15.0, - :min => 1.0, - :max => 5.0}, - { :name => 'bar', - :count => 5, - :sum => 40.0, - :min => 6.0, - :max => 10.0} + subject.add foo: 1 + subject.add foo: 2 + subject.add foo: 3 + subject.add foo: 4 + subject.add foo: 5 + + subject.add bar: 6 + subject.add bar: 7 + subject.add bar: 8 + subject.add bar: 9 + subject.add bar: 10 + expected = { gauges: [ + { name: 'foo', + count: 5, + sum: 15.0, + min: 1.0, + max: 5.0}, + { name: 'bar', + count: 5, + sum: 40.0, + min: 6.0, + max: 10.0} ] } expect(subject.queued).to equal_unordered(expected) @@ -164,15 +164,15 @@ module Metrics describe "#queued" do it "includes global source if set" do - a = Aggregator.new(:source => 'blah') - a.add :foo => 12 + a = Aggregator.new(source: 'blah') + a.add foo: 12 expect(a.queued[:source]).to eq('blah') end it "includes global measure_time if set" do measure_time = (Time.now-1000).to_i - a = Aggregator.new(:measure_time => measure_time) - a.add :foo => 12 + a = Aggregator.new(measure_time: measure_time) + a.add foo: 12 expect(a.queued[:measure_time]).to eq(measure_time) end end @@ -185,7 +185,7 @@ module Metrics context "when successful" do it "flushes queued metrics and return true" do - subject.add :steps => 2042, :distance => 1234 + subject.add steps: 2042, distance: 1234 expect(subject.submit).to be true expect(subject.empty?).to be true end @@ -193,7 +193,7 @@ module Metrics context "when failed" do it "preserves queue and return false" do - subject.add :steps => 2042, :distance => 1234 + subject.add steps: 2042, distance: 1234 subject.persister.return_value(false) expect(subject.submit).to be false expect(subject.empty?).to be false @@ -234,16 +234,16 @@ module Metrics end it "does not submit immediately" do - timed_agg = Aggregator.new(:client => client, :autosubmit_interval => 1) - timed_agg.add :foo => 1 + timed_agg = Aggregator.new(client: client, autosubmit_interval: 1) + timed_agg.add foo: 1 expect(timed_agg.persister.persisted).to be_nil # nothing sent end it "submits after interval" do - timed_agg = Aggregator.new(:client => client, :autosubmit_interval => 1) - timed_agg.add :foo => 1 + timed_agg = Aggregator.new(client: client, autosubmit_interval: 1) + timed_agg.add foo: 1 sleep 1 - timed_agg.add :foo => 2 + timed_agg.add foo: 2 expect(timed_agg.persister.persisted).not_to be_nil # sent end end diff --git a/spec/unit/metrics/client_spec.rb b/spec/unit/metrics/client_spec.rb index 5a4a0d5..c611e19 100644 --- a/spec/unit/metrics/client_spec.rb +++ b/spec/unit/metrics/client_spec.rb @@ -108,15 +108,15 @@ module Metrics it "persists metrics immediately" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test - expect(subject.submit(:foo => 123)).to be true - expect(subject.persister.persisted).to eq({:gauges => [{:name => 'foo', :value => 123}]}) + expect(subject.submit(foo: 123)).to be true + expect(subject.persister.persisted).to eq({gauges: [{name: 'foo', value: 123}]}) end it "tolerates muliple metrics" do subject.authenticate 'me@librato.com', 'foo' subject.persistence = :test - expect { subject.submit :foo => 123, :bar => 456 }.not_to raise_error - expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} + expect { subject.submit foo: 123, bar: 456 }.not_to raise_error + expected = {gauges: [{name: 'foo', value: 123}, {name: 'bar', value: 456}]} expect(subject.persister.persisted).to equal_unordered(expected) end end diff --git a/spec/unit/metrics/connection_spec.rb b/spec/unit/metrics/connection_spec.rb index 7e1a456..87c270a 100644 --- a/spec/unit/metrics/connection_spec.rb +++ b/spec/unit/metrics/connection_spec.rb @@ -14,7 +14,7 @@ module Metrics context "when provided" do it "uses provided endpoint" do - connection = Connection.new(:api_endpoint => 'http://test.com/') + connection = Connection.new(api_endpoint: 'http://test.com/') expect(connection.api_endpoint).to eq('http://test.com/') end end @@ -23,7 +23,7 @@ module Metrics describe "#user_agent" do context "without an agent_identifier" do it "renders standard string" do - connection = Connection.new(:client => Client.new) + connection = Connection.new(client: Client.new) expect(connection.user_agent).to start_with('librato-metrics') end end @@ -32,7 +32,7 @@ module Metrics it "renders agent_identifier first" do client = Client.new client.agent_identifier('foo', '0.5', 'bar') - connection = Connection.new(:client => client) + connection = Connection.new(client: client) expect(connection.user_agent).to start_with('foo/0.5') end end @@ -41,7 +41,7 @@ module Metrics it "uses custom user agent" do client = Client.new client.custom_user_agent = 'foo agent' - connection = Connection.new(:client => client) + connection = Connection.new(client: client) expect(connection.user_agent).to eq('foo agent') end end diff --git a/spec/unit/metrics/queue/autosubmission_spec.rb b/spec/unit/metrics/queue/autosubmission_spec.rb index 27607bf..ad6fefe 100644 --- a/spec/unit/metrics/queue/autosubmission_spec.rb +++ b/spec/unit/metrics/queue/autosubmission_spec.rb @@ -9,24 +9,24 @@ module Metrics context "with an autosubmit count" do it "submits when the max is reached" do - vol_queue = Queue.new(:client => client, :autosubmit_count => 2) - vol_queue.add :foo => 1 - vol_queue.add :bar => 2 + vol_queue = Queue.new(client: client, autosubmit_count: 2) + vol_queue.add foo: 1 + vol_queue.add bar: 2 expect(vol_queue.persister.persisted).not_to be_nil # sent end it "does not submit if the max has not been reached" do - vol_queue = Queue.new(:client => client, :autosubmit_count => 5) - vol_queue.add :foo => 1 - vol_queue.add :bar => 2 + vol_queue = Queue.new(client: client, autosubmit_count: 5) + vol_queue.add foo: 1 + vol_queue.add bar: 2 expect(vol_queue.persister.persisted).to be_nil # nothing sent end it 'submits when merging' do - queue = Queue.new(:client => client, :autosubmit_count => 5) + queue = Queue.new(client: client, autosubmit_count: 5) (1..3).each {|i| queue.add "metric_#{i}" => 1 } - to_merge = Queue.new(:client => client) + to_merge = Queue.new(client: client) (1..5).each {|i| to_merge.add "metric_#{i}" => 1 } queue.merge!(to_merge) @@ -38,16 +38,16 @@ module Metrics context "with an autosubmit interval" do it "does not submit immediately" do - vol_queue = Queue.new(:client => client, :autosubmit_interval => 1) - vol_queue.add :foo => 1 + vol_queue = Queue.new(client: client, autosubmit_interval: 1) + vol_queue.add foo: 1 expect(vol_queue.persister.persisted).to be_nil # nothing sent end it "submits after interval" do - vol_queue = Queue.new(:client => client, :autosubmit_interval => 1) - vol_queue.add :foo => 1 + vol_queue = Queue.new(client: client, autosubmit_interval: 1) + vol_queue.add foo: 1 sleep 1 - vol_queue.add :foo => 2 + vol_queue.add foo: 2 expect(vol_queue.persister.persisted).not_to be_nil # sent end end diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index 8a6bad7..b2813c1 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -14,7 +14,7 @@ module Metrics context "with specified client" do it "sets to client" do barney = Client - queue = Queue.new(:client => barney) + queue = Queue.new(client: barney) expect(queue.client).to eq(barney) end end @@ -29,33 +29,33 @@ module Metrics describe "#add" do it "allows chaining" do - expect(subject.add(:foo => 123)).to eq(subject) + expect(subject.add(foo: 123)).to eq(subject) end context "with single hash argument" do it "records a key-value gauge" do - expected = {:gauges => [{:name => 'foo', :value => 3000, :measure_time => @time}]} - subject.add :foo => 3000 + expected = {gauges: [{name: 'foo', value: 3000, measure_time: @time}]} + subject.add foo: 3000 expect(subject.queued).to equal_unordered(expected) end end context "with specified metric type" do it "records counters" do - subject.add :total_visits => {:type => :counter, :value => 4000} - expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]} + subject.add total_visits: {type: :counter, value: 4000} + expected = {counters: [{name: 'total_visits', value: 4000, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end it "records gauges" do - subject.add :temperature => {:type => :gauge, :value => 34} - expected = {:gauges => [{:name => 'temperature', :value => 34, :measure_time => @time}]} + subject.add temperature: {type: :gauge, value: 34} + expected = {gauges: [{name: 'temperature', value: 34, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end it "accepts type key as string or a symbol" do - subject.add :total_visits => {"type" => "counter", :value => 4000} - expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]} + subject.add total_visits: {"type" => "counter", value: 4000} + expected = {counters: [{name: 'total_visits', value: 4000, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end end @@ -63,40 +63,40 @@ module Metrics context "with extra attributes" do it "records" do measure_time = Time.now - subject.add :disk_use => {:value => 35.4, :period => 2, - :description => 'current disk utilization', :measure_time => measure_time, - :source => 'db2'} - expected = {:gauges => [{:value => 35.4, :name => 'disk_use', :period => 2, - :description => 'current disk utilization', :measure_time => measure_time.to_i, - :source => 'db2'}]} + subject.add disk_use: {value: 35.4, period: 2, + description: 'current disk utilization', measure_time: measure_time, + source: 'db2'} + expected = {gauges: [{value: 35.4, name: 'disk_use', period: 2, + description: 'current disk utilization', measure_time: measure_time.to_i, + source: 'db2'}]} expect(subject.queued).to equal_unordered(expected) end context "with a prefix set" do it "auto-prepends names" do - subject = Queue.new(:prefix => 'foo') - subject.add :bar => 1 - subject.add :baz => {:value => 23} - expected = {:gauges => [{:name =>'foo.bar', :value => 1, :measure_time => @time}, - {:name => 'foo.baz', :value => 23, :measure_time => @time}]} + subject = Queue.new(prefix: 'foo') + subject.add bar: 1 + subject.add baz: {value: 23} + expected = {gauges: [{name:'foo.bar', value: 1, measure_time: @time}, + {name: 'foo.baz', value: 23, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end end context "when dynamically changing prefix" do it "auto-appends names" do - subject.add :bar => 12 + subject.add bar: 12 subject.prefix = 'foo' # with string - subject.add :bar => 23 + subject.add bar: 23 subject.prefix = :foo # with symbol - subject.add :bar => 34 + subject.add bar: 34 subject.prefix = nil # unsetting - subject.add :bar => 45 - expected = {:gauges => [ - {:name => 'bar', :value => 12, :measure_time => @time}, - {:name => 'foo.bar', :value => 23, :measure_time => @time}, - {:name => 'foo.bar', :value => 34, :measure_time => @time}, - {:name => 'bar', :value => 45, :measure_time => @time}]} + subject.add bar: 45 + expected = {gauges: [ + {name: 'bar', value: 12, measure_time: @time}, + {name: 'foo.bar', value: 23, measure_time: @time}, + {name: 'foo.bar', value: 34, measure_time: @time}, + {name: 'bar', value: 45, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end end @@ -104,10 +104,10 @@ module Metrics context "with multiple metrics" do it "records" do - subject.add :foo => 123, :bar => 345, :baz => 567 - expected = {:gauges=>[{:name=>"foo", :value=>123, :measure_time => @time}, - {:name=>"bar", :value=>345, :measure_time => @time}, - {:name=>"baz", :value=>567, :measure_time => @time}]} + subject.add foo: 123, bar: 345, baz: 567 + expected = {gauges:[{name:"foo", value:123, measure_time: @time}, + {name:"bar", value:345, measure_time: @time}, + {name:"baz", value:567, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end end @@ -115,25 +115,25 @@ module Metrics context "with a measure_time" do it "accepts time objects" do time = Time.now-5 - subject.add :foo => {:measure_time => time, :value => 123} + subject.add foo: {measure_time: time, value: 123} expect(subject.queued[:gauges][0][:measure_time]).to eq(time.to_i) end it "accepts integers" do time = @time.to_i - subject.add :foo => {:measure_time => time, :value => 123} + subject.add foo: {measure_time: time, value: 123} expect(subject.queued[:gauges][0][:measure_time]).to eq(time) end it "accepts strings" do time = @time.to_s - subject.add :foo => {:measure_time => time, :value => 123} + subject.add foo: {measure_time: time, value: 123} expect(subject.queued[:gauges][0][:measure_time]).to eq(time.to_i) end it "raises exception in invalid time" do expect { - subject.add :foo => {:measure_time => '12', :value => 123} + subject.add foo: {measure_time: '12', value: 123} }.to raise_error(InvalidMeasureTime) end end @@ -141,9 +141,9 @@ module Metrics describe "#counters" do it "returns currently queued counters" do - subject.add :transactions => {:type => :counter, :value => 12345}, - :register_cents => {:type => :gauge, :value => 211101} - expect(subject.counters).to eq([{:name => 'transactions', :value => 12345, :measure_time => @time}]) + subject.add transactions: {type: :counter, value: 12345}, + register_cents: {type: :gauge, value: 211101} + expect(subject.counters).to eq([{name: 'transactions', value: 12345, measure_time: @time}]) end it "returns [] when no queued counters" do @@ -157,16 +157,16 @@ module Metrics end it "returns false with queued items" do - subject.add :foo => {:type => :gauge, :value => 121212} + subject.add foo: {type: :gauge, value: 121212} expect(subject.empty?).to be false end end describe "#gauges" do it "returns currently queued gauges" do - subject.add :transactions => {:type => :counter, :value => 12345}, - :register_cents => {:type => :gauge, :value => 211101} - expect(subject.gauges).to eq([{:name => 'register_cents', :value => 211101, :measure_time => @time}]) + subject.add transactions: {type: :counter, value: 12345}, + register_cents: {type: :gauge, value: 211101} + expect(subject.gauges).to eq([{name: 'register_cents', value: 211101, measure_time: @time}]) end it "returns [] when no queued gauges" do @@ -186,7 +186,7 @@ module Metrics it "stores last submission time" do prior = Time.now - subject.add :foo => 123 + subject.add foo: 123 subject.submit expect(subject.last_submit_time).to be >= prior end @@ -196,50 +196,50 @@ module Metrics context "with another queue" do it "merges gauges" do q1 = Queue.new - q1.add :foo => 123, :bar => 456 + q1.add foo: 123, bar: 456 q2 = Queue.new - q2.add :baz => 678 + q2.add baz: 678 q2.merge!(q1) - expected = {:gauges=>[{:name=>"foo", :value=>123, :measure_time => @time}, - {:name=>"bar", :value=>456, :measure_time => @time}, - {:name=>"baz", :value=>678, :measure_time => @time}]} + expected = {gauges:[{name:"foo", value:123, measure_time: @time}, + {name:"bar", value:456, measure_time: @time}, + {name:"baz", value:678, measure_time: @time}]} expect(q2.queued).to equal_unordered(expected) end it "merges counters" do q1 = Queue.new - q1.add :users => {:type => :counter, :value => 1000} - q1.add :sales => {:type => :counter, :value => 250} + q1.add users: {type: :counter, value: 1000} + q1.add sales: {type: :counter, value: 250} q2 = Queue.new - q2.add :signups => {:type => :counter, :value => 500} + q2.add signups: {type: :counter, value: 500} q2.merge!(q1) - expected = {:counters=>[{:name=>"users", :value=>1000, :measure_time => @time}, - {:name=>"sales", :value=>250, :measure_time => @time}, - {:name=>"signups", :value=>500, :measure_time => @time}]} + expected = {counters:[{name:"users", value:1000, measure_time: @time}, + {name:"sales", value:250, measure_time: @time}, + {name:"signups", value:500, measure_time: @time}]} expect(q2.queued).to equal_unordered(expected) end it "maintains specified sources" do q1 = Queue.new - q1.add :neo => {:source => 'matrix', :value => 123} - q2 = Queue.new(:source => 'red_pill') + q1.add neo: {source: 'matrix', value: 123} + q2 = Queue.new(source: 'red_pill') q2.merge!(q1) expect(q2.queued[:gauges][0][:source]).to eq('matrix') end it "does not change default source" do - q1 = Queue.new(:source => 'matrix') - q1.add :neo => 456 - q2 = Queue.new(:source => 'red_pill') + q1 = Queue.new(source: 'matrix') + q1.add neo: 456 + q2 = Queue.new(source: 'red_pill') q2.merge!(q1) expect(q2.queued[:source]).to eq('red_pill') end it "tracks previous default source" do - q1 = Queue.new(:source => 'matrix') - q1.add :neo => 456 - q2 = Queue.new(:source => 'red_pill') - q2.add :morpheus => 678 + q1 = Queue.new(source: 'matrix') + q1.add neo: 456 + q2 = Queue.new(source: 'red_pill') + q2.add morpheus: 678 q2.merge!(q1) q2.queued[:gauges].each do |gauge| if gauge[:name] == 'neo' @@ -250,34 +250,34 @@ module Metrics it "handles empty cases" do q1 = Queue.new - q1.add :foo => 123, :users => {:type => :counter, :value => 1000} + q1.add foo: 123, users: {type: :counter, value: 1000} q2 = Queue.new q2.merge!(q1) - expected = {:counters => [{:name=>"users", :value=>1000, :measure_time => @time}], - :gauges => [{:name=>"foo", :value=>123, :measure_time => @time}]} + expected = {counters: [{name:"users", value:1000, measure_time: @time}], + gauges: [{name:"foo", value:123, measure_time: @time}]} expect(q2.queued).to eq(expected) end end context "with an aggregator" do it "merges" do - aggregator = Aggregator.new(:source => 'aggregator') - aggregator.add :timing => 102 - aggregator.add :timing => 203 - queue = Queue.new(:source => 'queue') - queue.add :gauge => 42 + aggregator = Aggregator.new(source: 'aggregator') + aggregator.add timing: 102 + aggregator.add timing: 203 + queue = Queue.new(source: 'queue') + queue.add gauge: 42 queue.merge!(aggregator) - expected = {:gauges=>[{:name=>"gauge", :value=>42, :measure_time=>@time}, - {:name=>"timing", :count=>2, :sum=>305.0, :min=>102.0, :max=>203.0, :source=>"aggregator"}], - :source=>'queue'} + expected = {gauges:[{name:"gauge", value:42, measure_time:@time}, + {name:"timing", count:2, sum:305.0, min:102.0, max:203.0, source:"aggregator"}], + source:'queue'} expect(queue.queued).to equal_unordered(expected) end end context "with a hash" do it "merges" do - to_merge = {:gauges=>[{:name => 'foo', :value => 123}], - :counters=>[{:name => 'bar', :value => 456}]} + to_merge = {gauges:[{name: 'foo', value: 123}], + counters:[{name: 'bar', value: 456}]} q = Queue.new q.merge!(to_merge) expect(q.gauges.length).to eq(1) @@ -294,15 +294,15 @@ module Metrics describe "#queued" do it "includes global source if set" do - q = Queue.new(:source => 'blah') - q.add :foo => 12 + q = Queue.new(source: 'blah') + q.add foo: 12 expect(q.queued[:source]).to eq('blah') end it "includes global measure_time if set" do measure_time = (Time.now-1000).to_i - q = Queue.new(:measure_time => measure_time) - q.add :foo => 12 + q = Queue.new(measure_time: measure_time) + q.add foo: 12 expect(q.queued[:measure_time]).to eq(measure_time) end end @@ -312,10 +312,10 @@ module Metrics expect(subject.size).to be_zero end it "returns count of gauges and counters if added" do - subject.add :transactions => {:type => :counter, :value => 12345}, - :register_cents => {:type => :gauge, :value => 211101} - subject.add :transactions => {:type => :counter, :value => 12345}, - :register_cents => {:type => :gauge, :value => 211101} + subject.add transactions: {type: :counter, value: 12345}, + register_cents: {type: :gauge, value: 211101} + subject.add transactions: {type: :counter, value: 12345}, + register_cents: {type: :gauge, value: 211101} expect(subject.size).to eq(4) end end @@ -328,7 +328,7 @@ module Metrics context "when successful" do it "flushes queued metrics and return true" do - subject.add :steps => 2042, :distance => 1234 + subject.add steps: 2042, distance: 1234 expect(subject.submit).to be true expect(subject.queued).to be_empty end @@ -336,7 +336,7 @@ module Metrics context "when failed" do it "preserves queue and return false" do - subject.add :steps => 2042, :distance => 1234 + subject.add steps: 2042, distance: 1234 subject.persister.return_value(false) expect(subject.submit).to be false expect(subject.queued).not_to be_empty @@ -359,7 +359,7 @@ module Metrics context "with metric and options" do it "queues metric with value and options" do - subject.time :sleep_two, :source => 'app1', :period => 2 do + subject.time :sleep_two, source: 'app1', period: 2 do sleep 0.05 end queued = subject.queued[:gauges][0] diff --git a/spec/unit/metrics_spec.rb b/spec/unit/metrics_spec.rb index 823b23e..4f154e6 100644 --- a/spec/unit/metrics_spec.rb +++ b/spec/unit/metrics_spec.rb @@ -48,13 +48,13 @@ module Librato it "persists metrics immediately" do Metrics.persistence = :test - expect(Metrics.submit(:foo => 123)).to be true - expect(Metrics.persister.persisted).to eq({:gauges => [{:name => 'foo', :value => 123}]}) + expect(Metrics.submit(foo: 123)).to be true + expect(Metrics.persister.persisted).to eq({gauges: [{name: 'foo', value: 123}]}) end it "tolerates multiple metrics" do - expect { Librato::Metrics.submit :foo => 123, :bar => 456 }.not_to raise_error - expected = {:gauges => [{:name => 'foo', :value => 123}, {:name => 'bar', :value => 456}]} + expect { Librato::Metrics.submit foo: 123, bar: 456 }.not_to raise_error + expected = {gauges: [{name: 'foo', value: 123}, {name: 'bar', value: 456}]} expect(Librato::Metrics.persister.persisted).to equal_unordered(expected) end end From aa4e927ac04ff5ce1254c1a8fceb829d982908fe Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 15:28:27 -0700 Subject: [PATCH 13/22] update README --- README.md | 66 ++++++++++++++++----------------- Rakefile | 5 +-- spec/unit/metrics/queue_spec.rb | 2 +- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 680894a..be3c5ac 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,11 @@ If you are using jruby, you need to ensure [jruby-openssl](https://github.com/jr If you are looking for the quickest possible route to getting a data into Metrics, you only need two lines: Librato::Metrics.authenticate 'email', 'api_key' - Librato::Metrics.submit :my_metric => 42, :my_other_metric => 1002 + Librato::Metrics.submit my_metric: 42, my_other_metric: 1002 Unspecified metrics will send a *gauge*, but if you need to send a different metric type or include additional properties, simply use a hash: - Librato::Metrics.submit :my_metric => {:type => :counter, :value => 1002, :source => 'myapp'} + Librato::Metrics.submit my_metric: {type: :counter, value: 1002, source: 'myapp'} While this is all you need to get started, if you are sending a number of metrics regularly a queue may be easier/more performant so read on... @@ -53,7 +53,7 @@ If you are sending very many measurements or sending them very often, it will be Queue up a simple gauge metric named `temperature`: queue = Librato::Metrics::Queue.new - queue.add :temperature => 32.2 + queue.add temperature: 32.2 While symbols are used by convention for metric names, strings will work just as well: @@ -64,18 +64,18 @@ If you are tracking measurements over several seconds/minutes, the queue will ha If you want to specify a time other than queuing time for the measurement: # use a epoch integer - queue.add :humidity => {:measure_time => 1336508422, :value => 48.2} + queue.add humidity: {measure_time: 1336508422, value: 48.2} # use a Time object to correct for a 5 second delay - queue.add :humidity => {:measure_time => Time.now-5, :value => 37.6} + queue.add humidity: {measure_time: Time.now-5, value: 37.6} You can queue multiple metrics at once. Here's a gauge (`load`) and a counter (`visits`): - queue.add :load => 2.2, :visits => {:type => :counter, :value => 400} + queue.add load: 2.2, visits: {type: :counter, value: 400} Queue up a metric with a specified source: - queue.add :cpu => {:source => 'app1', :value => 92.6} + queue.add cpu: {source: 'app1', value: 92.6} A complete [list of metric attributes](http://dev.librato.com/v1/metrics) is available in the [API documentation](http://dev.librato.com/v1). @@ -90,23 +90,23 @@ If you are measuring something very frequently e.g. per-request in a web applica Aggregate a simple gauge metric named `response_latency`: aggregator = Librato::Metrics::Aggregator.new - aggregator.add :response_latency => 85.0 - aggregator.add :response_latency => 100.5 - aggregator.add :response_latency => 150.2 - aggregator.add :response_latency => 90.1 - aggregator.add :response_latency => 92.0 + aggregator.add response_latency: 85.0 + aggregator.add response_latency: 100.5 + aggregator.add response_latency: 150.2 + aggregator.add response_latency: 90.1 + aggregator.add response_latency: 92.0 Which would result in a gauge measurement like: - {:name => "response_latency", :count => 5, :sum => 517.8, :min => 85.0, :max => 150.2} + {name: "response_latency", count: 5, sum: 517.8, min: 85.0, max: 150.2} You can specify a source during aggregate construction: - aggregator = Librato::Metrics::Aggregator.new(:source => 'foobar') + aggregator = Librato::Metrics::Aggregator.new(source: 'foobar') You can aggregate multiple metrics at once: - aggregator.add :app_latency => 35.2, :db_latency => 120.7 + aggregator.add app_latency: 35.2, db_latency: 120.7 Send the currently aggregated metrics to Metrics: @@ -124,7 +124,7 @@ The difference between the two is that `Queue` submits each timing measurement i If you need extra attributes for a `Queue` timing measurement, simply add them on: - queue.time :my_measurement, :source => 'app1' do + queue.time :my_measurement, source: 'app1' do # do work... end @@ -138,9 +138,9 @@ At a minimum each annotation needs to be assigned to a stream and to have a titl There are a number of optional fields which can make annotations even more powerful: - Librato::Metrics.annotate :deployments, 'deployed v46', :source => 'frontend', - :start_time => 1354662596, :end_time => 1354662608, - :description => 'Deployed 6f3bc6e67682: fix lotsa bugs…' + Librato::Metrics.annotate :deployments, 'deployed v46', source: 'frontend', + start_time: 1354662596, end_time: 1354662608, + description: 'Deployed 6f3bc6e67682: fix lotsa bugs…' You can also automatically annotate the start and end time of an action by using `annotate`'s block form: @@ -156,7 +156,7 @@ More fine-grained control of annotations is available via the `Annotator` object streams = annotator.list # fetch a list of events in the last hour from a stream - annotator.fetch :deployments, :start_time => (Time.now.to_i-3600) + annotator.fetch :deployments, start_time: (Time.now.to_i-3600) # delete an event annotator.delete_event 'deployments', 23 @@ -168,15 +168,15 @@ See the documentation of `Annotator` for more details and examples of use. Both `Queue` and `Aggregator` support automatically submitting measurements on a given time interval: # submit once per minute - timed_queue = Librato::Metrics::Queue.new(:autosubmit_interval => 60) + timed_queue = Librato::Metrics::Queue.new(autosubmit_interval: 60) # submit every 5 minutes - timed_aggregator = Librato::Metrics::Aggregator.new(:autosubmit_interval => 300) + timed_aggregator = Librato::Metrics::Aggregator.new(autosubmit_interval: 300) `Queue` also supports auto-submission based on measurement volume: # submit when the 400th measurement is queued - volume_queue = Librato::Metrics::Queue.new(:autosubmit_count => 400) + volume_queue = Librato::Metrics::Queue.new(autosubmit_count: 400) These options can also be combined for more flexible behavior. @@ -192,7 +192,7 @@ Get name and properties for all metrics you have in the system: Get only metrics whose name includes `time`: - metrics = Librato::Metrics.metrics :name => 'time' + metrics = Librato::Metrics.metrics name: 'time' ## Querying Metric Data @@ -202,19 +202,19 @@ Get attributes for metric `temperature`: Get the 20 most recent data points for `temperature`: - data = Librato::Metrics.get_measurements :temperature, :count => 20 + data = Librato::Metrics.get_measurements :temperature, count: 20 Get the 20 most recent data points for `temperature` from a specific source: - data = Librato::Metrics.get_measurements :temperature, :count => 20, :source => 'app1' + data = Librato::Metrics.get_measurements :temperature, count: 20, source: 'app1' Get the 20 most recent 15 minute data point rollups for `temperature`: - data = Librato::Metrics.get_measurements :temperature, :count => 20, :resolution => 900 + data = Librato::Metrics.get_measurements :temperature, count: 20, resolution: 900 Get the 5 minute moving average for `temperature` for the last hour, assuming temperature is submitted once per minute: - data = Librato::Metrics.get_composite 'moving_average(mean(series("temperature", "*"), {size: "5"}))', :start_time => Time.now.to_i - 60*60, :resolution => 300 + data = Librato::Metrics.get_composite 'moving_average(mean(series("temperature", "*"), {size: "5"}))', start_time: Time.now.to_i - 60*60, resolution: 300 There are many more options supported for querying, take a look at the [REST API docs](http://dev.librato.com/v1/get/metrics/:name) or the individual method documentation for more details. @@ -223,7 +223,7 @@ There are many more options supported for querying, take a look at the [REST API Setting custom [properties](http://dev.librato.com/v1/metrics#metric_properties) on your metrics is easy: # assign a period and default color - Librato::Metrics.update_metric :temperature, :period => 15, :attributes => { :color => 'F00' } + Librato::Metrics.update_metric :temperature, period: 15, attributes: { color: 'F00' } It is also possible to update properties for multiple metrics at once, see the [`#update_metric` method documentation](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics/Client#update_metric-instance_method) for more information. @@ -237,7 +237,7 @@ If you ever need to remove a metric and all of its measurements, doing so is eas You can also delete using wildcards: # delete metrics that start with cpu. except for cpu.free - Librato::Metrics.delete_metrics :names => 'cpu.*', :exclude => ['cpu.free'] + Librato::Metrics.delete_metrics names: 'cpu.*', exclude: ['cpu.free'] Note that deleted metrics and their measurements are unrecoverable, so use with care. @@ -257,17 +257,17 @@ All of the same operations you can call directly from `Librato::Metrics` are ava joe.metrics # fetch the last 20 data points for Mike's metric, humidity - mike.get_measurements :humidity, :count => 20 + mike.get_measurements :humidity, count: 20 There are two ways to associate a new queue with a client: # these are functionally equivalent - joe_queue = Librato::Metrics::Queue.new(:client => joe) + joe_queue = Librato::Metrics::Queue.new(client: joe) joe_queue = joe.new_queue Once the queue is associated you can use it normally: - joe_queue.add :temperature => {:source => 'sf', :value => 65.2} + joe_queue.add temperature: {source: 'sf', value: 65.2} joe_queue.submit ## Thread Safety diff --git a/Rakefile b/Rakefile index 0a6b82c..804bdb9 100755 --- a/Rakefile +++ b/Rakefile @@ -45,8 +45,8 @@ namespace :spec do end end -task :default => :spec -task :test => :spec +task default: :spec +task test: :spec # Docs require 'yard' @@ -61,4 +61,3 @@ task :console do sh "irb -rubygems -r ./lib/librato/metrics.rb" end end - diff --git a/spec/unit/metrics/queue_spec.rb b/spec/unit/metrics/queue_spec.rb index b2813c1..6a50c52 100644 --- a/spec/unit/metrics/queue_spec.rb +++ b/spec/unit/metrics/queue_spec.rb @@ -54,7 +54,7 @@ module Metrics end it "accepts type key as string or a symbol" do - subject.add total_visits: {"type" => "counter", value: 4000} + subject.add total_visits: {type: "counter", value: 4000} expected = {counters: [{name: 'total_visits', value: 4000, measure_time: @time}]} expect(subject.queued).to equal_unordered(expected) end From 5f090f1f61dfdee687f50d72d64811041e383552 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 16:55:05 -0700 Subject: [PATCH 14/22] update travis.yml --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e5fdc2..2df777a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ sudo: false rvm: - # - 1.8.7 - # - ree - 1.9.3 - 2.1.7 - 2.2.3 @@ -23,4 +21,4 @@ branches: notifications: email: on_failure: change - on_success: never \ No newline at end of file + on_success: never From 6abff36aa2c24df5835de1e8e05ecebc08471494 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 17:07:02 -0700 Subject: [PATCH 15/22] remove comment --- lib/librato/metrics/smart_json.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librato/metrics/smart_json.rb b/lib/librato/metrics/smart_json.rb index 3912a60..64dfdc4 100644 --- a/lib/librato/metrics/smart_json.rb +++ b/lib/librato/metrics/smart_json.rb @@ -10,7 +10,7 @@ class SmartJSON if USE_MULTI_JSON MultiJson else - JSON # ships with 1.9 + JSON end extend SingleForwardable From a45103a089c6d9269ae5d2c9ad1739acc4568dca Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 17:12:31 -0700 Subject: [PATCH 16/22] update conditional --- lib/librato/metrics/smart_json.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/librato/metrics/smart_json.rb b/lib/librato/metrics/smart_json.rb index 64dfdc4..8b023a2 100644 --- a/lib/librato/metrics/smart_json.rb +++ b/lib/librato/metrics/smart_json.rb @@ -1,7 +1,10 @@ USE_MULTI_JSON = defined?(MultiJson) -require 'json' unless USE_MULTI_JSON -require 'multi_json' if USE_MULTI_JSON +if USE_MULTI_JSON + require 'multi_json' +else + require 'json' +end module Librato module Metrics From 0126fceef2b052157c6c5b506f622407d74b9ec6 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Thu, 11 Aug 2016 17:56:53 -0700 Subject: [PATCH 17/22] do not require twice --- lib/librato/metrics/smart_json.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/librato/metrics/smart_json.rb b/lib/librato/metrics/smart_json.rb index 8b023a2..c03e7a7 100644 --- a/lib/librato/metrics/smart_json.rb +++ b/lib/librato/metrics/smart_json.rb @@ -1,10 +1,6 @@ USE_MULTI_JSON = defined?(MultiJson) -if USE_MULTI_JSON - require 'multi_json' -else - require 'json' -end +require 'json' unless USE_MULTI_JSON module Librato module Metrics From 33c00151775cf438148505110e7c61b729e424ed Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Fri, 12 Aug 2016 11:03:37 -0700 Subject: [PATCH 18/22] add >= 1.9 required ruby version to gemspec --- librato-metrics.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/librato-metrics.gemspec b/librato-metrics.gemspec index f204037..2e81e8f 100644 --- a/librato-metrics.gemspec +++ b/librato-metrics.gemspec @@ -7,6 +7,7 @@ Gem::Specification.new do |s| s.specification_version = 2 if s.respond_to? :specification_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.rubygems_version = '1.3.5' + s.required_ruby_version = '>= 1.9' s.name = 'librato-metrics' s.version = Librato::Metrics::VERSION From 58bf7ae957de241793175288e2ecc64927da22bc Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 17 Aug 2016 13:33:27 -0700 Subject: [PATCH 19/22] use parse and generate for JSON --- Gemfile | 1 + lib/librato/metrics/smart_json.rb | 47 +++++++++-------- spec/unit/metrics/smart_json_spec.rb | 79 ++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 spec/unit/metrics/smart_json_spec.rb diff --git a/Gemfile b/Gemfile index 000d2e4..cc350be 100644 --- a/Gemfile +++ b/Gemfile @@ -32,4 +32,5 @@ group :test do gem 'rspec', '~> 3.5.0' gem 'sinatra' gem 'popen4' + gem 'multi_json' end diff --git a/lib/librato/metrics/smart_json.rb b/lib/librato/metrics/smart_json.rb index c03e7a7..f484fac 100644 --- a/lib/librato/metrics/smart_json.rb +++ b/lib/librato/metrics/smart_json.rb @@ -1,32 +1,35 @@ -USE_MULTI_JSON = defined?(MultiJson) - -require 'json' unless USE_MULTI_JSON - module Librato module Metrics class SmartJSON - JSON_HANDLER = - if USE_MULTI_JSON - MultiJson - else - JSON - end extend SingleForwardable - # wrap MultiJSON's implementation so we can use any version - # prefer modern syntax if available; def once at startup - if JSON_HANDLER.respond_to?(:load) - def_delegator JSON_HANDLER, :load, :read - else - def_delegator JSON_HANDLER, :decode, :read - end + @handler = + if defined?(::MultiJson) + # MultiJSON >= 1.3.0 + if MultiJson.respond_to?(:load) + def_delegator MultiJson, :load, :read + else + def_delegator MultiJson, :decode, :read + end + + # MultiJSON <= 1.2.0 + if MultiJson.respond_to?(:dump) + def_delegator MultiJson, :dump, :write + else + def_delegator MultiJson, :encode, :write + end - if JSON_HANDLER.respond_to?(:dump) - def_delegator JSON_HANDLER, :dump, :write - else - def_delegator JSON_HANDLER, :encode, :write - end + :multi_json + else + require "json/ext" + + def_delegator JSON, :parse, :read + def_delegator JSON, :generate, :write + + :json + end + define_singleton_method(:handler) { @handler } end end end diff --git a/spec/unit/metrics/smart_json_spec.rb b/spec/unit/metrics/smart_json_spec.rb new file mode 100644 index 0000000..dfa46f3 --- /dev/null +++ b/spec/unit/metrics/smart_json_spec.rb @@ -0,0 +1,79 @@ +require "spec_helper" + +module Librato + module Metrics + + describe SmartJSON do + + describe ".read" do + context "with MultiJSON" do + before do + $".delete_if {|s| s.include?("multi_json")} + require "multi_json" + load "lib/librato/metrics/smart_json.rb" + end + + after do + Object.send(:remove_const, :MultiJson) + load "lib/librato/metrics/smart_json.rb" + end + + it "uses .load or .decode" do + actual = SmartJSON.read("{\"abc\":\"def\"}") + + expect(SmartJSON.handler).to eq(:multi_json) + expect(actual).to be_a(Hash) + expect(actual).to have_key("abc") + expect(actual["abc"]).to eq("def") + end + end + + context "with JSON" do + it "uses .parse" do + actual = SmartJSON.read("{\"abc\":\"def\"}") + + expect(SmartJSON.handler).to eq(:json) + expect(actual).to be_a(Hash) + expect(actual).to have_key("abc") + expect(actual["abc"]).to eq("def") + end + end + end + + describe ".write" do + context "with MultiJSON" do + before do + $".delete_if {|s| s.include?("multi_json")} + require "multi_json" + load "lib/librato/metrics/smart_json.rb" + end + + after do + Object.send(:remove_const, :MultiJson) + load "lib/librato/metrics/smart_json.rb" + end + + it "uses .dump or .decode" do + actual = SmartJSON.write({abc: 'def'}) + + expect(SmartJSON.handler).to eq(:multi_json) + expect(actual).to be_a(String) + expect(actual).to eq("{\"abc\":\"def\"}") + end + end + + context "with JSON" do + it "uses .parse" do + actual = SmartJSON.write({abc: 'def'}) + + expect(SmartJSON.handler).to eq(:json) + expect(actual).to be_a(String) + expect(actual).to eq("{\"abc\":\"def\"}") + end + end + end + + end + + end +end From d1a603da0f918ece0d1955156589b0792a0aee76 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Wed, 17 Aug 2016 13:41:09 -0700 Subject: [PATCH 20/22] update test description --- spec/unit/metrics/smart_json_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/metrics/smart_json_spec.rb b/spec/unit/metrics/smart_json_spec.rb index dfa46f3..f0240e6 100644 --- a/spec/unit/metrics/smart_json_spec.rb +++ b/spec/unit/metrics/smart_json_spec.rb @@ -63,7 +63,7 @@ module Metrics end context "with JSON" do - it "uses .parse" do + it "uses .generate" do actual = SmartJSON.write({abc: 'def'}) expect(SmartJSON.handler).to eq(:json) From 3dd529167d354c4e0e83941ea011f3d11db7bcf8 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Tue, 23 Aug 2016 17:26:16 -0700 Subject: [PATCH 21/22] remove define_singleton_method --- lib/librato/metrics/smart_json.rb | 41 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/librato/metrics/smart_json.rb b/lib/librato/metrics/smart_json.rb index f484fac..bf8c1a2 100644 --- a/lib/librato/metrics/smart_json.rb +++ b/lib/librato/metrics/smart_json.rb @@ -3,33 +3,34 @@ module Metrics class SmartJSON extend SingleForwardable - @handler = - if defined?(::MultiJson) - # MultiJSON >= 1.3.0 - if MultiJson.respond_to?(:load) - def_delegator MultiJson, :load, :read - else - def_delegator MultiJson, :decode, :read - end + if defined?(::MultiJson) + # MultiJSON >= 1.3.0 + if MultiJson.respond_to?(:load) + def_delegator MultiJson, :load, :read + else + def_delegator MultiJson, :decode, :read + end - # MultiJSON <= 1.2.0 - if MultiJson.respond_to?(:dump) - def_delegator MultiJson, :dump, :write - else - def_delegator MultiJson, :encode, :write - end + # MultiJSON <= 1.2.0 + if MultiJson.respond_to?(:dump) + def_delegator MultiJson, :dump, :write + else + def_delegator MultiJson, :encode, :write + end + def self.handler :multi_json - else - require "json/ext" + end + else + require "json" - def_delegator JSON, :parse, :read - def_delegator JSON, :generate, :write + def_delegator JSON, :parse, :read + def_delegator JSON, :generate, :write + def self.handler :json end - - define_singleton_method(:handler) { @handler } + end end end end From eeebc29bdbb7658383c04d95fa9102f602dce431 Mon Sep 17 00:00:00 2001 From: Chance Feick Date: Tue, 23 Aug 2016 20:53:31 -0700 Subject: [PATCH 22/22] update CHANGELOG --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3addfb6..85563db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Changelog +### master +* Remove support for deprecated methods (#117) +* Upgrade rspec from 2.6 to 3.5 (#118) +* Remove support for ruby 1.8 (#119) +* Remove `MultiJson` runtime dependency (#119) +* Relax `Faraday` runtime dependency (#119) + ### Version 1.6.1 * Fix bugs with listing sources (#116) @@ -156,4 +163,4 @@ * Metric 'type' key can be string or symbol (Neil Mock) ### Version 0.1.0 -* Initial release \ No newline at end of file +* Initial release