Last active
December 22, 2015 05:59
-
-
Save myronmarston/6428002 to your computer and use it in GitHub Desktop.
Repro script for librato. You can remove the VCR stuff it that helps; I added it to log the requests and responses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'librato/metrics' | |
require 'vcr' | |
VCR.configure do |vcr| | |
vcr.hook_into :faraday | |
vcr.cassette_library_dir = Dir.pwd | |
end | |
puts "Running on ruby version: #{RUBY_DESCRIPTION}" | |
puts "Using librato-metrics version: #{Librato::Metrics::VERSION}" | |
$metric_name = "qless.builder.failed-job-counts-all-klasses" | |
def create_client | |
librato_email = ENV.fetch('EMAIL') { raise "Must pass [email protected]" } | |
librato_token = ENV.fetch('API_TOKEN') { raise "Must pass API_TOKEN=someapitoken" } | |
$client = Librato::Metrics::Client.new | |
$client.authenticate(librato_email, librato_token) | |
end | |
def remove_all_metrics_to_produce_a_clean_slate | |
puts "Deleting all prior metrics to create a clean slate" | |
names = $client.list.map { |m| m.fetch("name") } | |
$client.delete(*names) if names.any? | |
end | |
def submit_metrics | |
puts "Submitting metric" | |
queue = $client.new_queue(source: "test") | |
queue.add($metric_name => 2) | |
queue.submit | |
end | |
def fetch_metric | |
puts "Sleeping for a bit to avoid eventual consistency issues" | |
sleep 5 | |
puts "Fetching metric" | |
raw = $client.fetch($metric_name, count: 2) | |
puts raw.inspect | |
end | |
VCR.use_cassette("librato") do | |
create_client | |
remove_all_metrics_to_produce_a_clean_slate | |
submit_metrics | |
fetch_metric | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
http_interactions: | |
- request: | |
method: get | |
uri: https://metrics-api.librato.com/v1/metrics | |
body: | |
encoding: US-ASCII | |
string: '' | |
headers: | |
User-Agent: | |
- librato-metrics/1.0.4 (ruby; 1.9.3p327; x86_64-darwin11.4.0) direct-faraday/0.8.8 | |
Content-Type: | |
- application/json | |
Authorization: | |
- Basic <redacted> | |
response: | |
status: | |
code: 200 | |
message: | |
headers: | |
content-type: | |
- application/json;charset=utf-8 | |
date: | |
- Tue, 03 Sep 2013 18:56:07 GMT | |
server: | |
- nginx/1.0.15 | |
status: | |
- 200 OK | |
content-length: | |
- '66' | |
connection: | |
- Close | |
body: | |
encoding: US-ASCII | |
string: ! '{"query":{"offset":0,"length":0,"found":0,"total":0},"metrics":[]}' | |
http_version: | |
recorded_at: Tue, 03 Sep 2013 18:56:05 GMT | |
- request: | |
method: post | |
uri: https://metrics-api.librato.com/v1/metrics | |
body: | |
encoding: UTF-8 | |
string: ! '{"gauges":[{"name":"qless.builder.failed-job-counts-all-klasses","value":2,"measure_time":1378234566}],"source":"test"}' | |
headers: | |
User-Agent: | |
- librato-metrics/1.0.4 (ruby; 1.9.3p327; x86_64-darwin11.4.0) direct-faraday/0.8.8 | |
Content-Type: | |
- application/json | |
Authorization: | |
- Basic <redacted> | |
response: | |
status: | |
code: 200 | |
message: | |
headers: | |
content-type: | |
- application/json;charset=utf-8 | |
date: | |
- Tue, 03 Sep 2013 18:56:08 GMT | |
server: | |
- nginx/1.0.15 | |
status: | |
- 200 OK | |
content-length: | |
- '0' | |
connection: | |
- Close | |
body: | |
encoding: US-ASCII | |
string: '' | |
http_version: | |
recorded_at: Tue, 03 Sep 2013 18:56:07 GMT | |
- request: | |
method: get | |
uri: https://metrics-api.librato.com/v1/metrics/qless.builder.failed-job-counts-all-klasses?count=2&resolution=1 | |
body: | |
encoding: US-ASCII | |
string: '' | |
headers: | |
User-Agent: | |
- librato-metrics/1.0.4 (ruby; 1.9.3p327; x86_64-darwin11.4.0) direct-faraday/0.8.8 | |
Content-Type: | |
- application/json | |
Authorization: | |
- Basic <redacted> | |
response: | |
status: | |
code: 404 | |
message: | |
headers: | |
content-type: | |
- application/json | |
date: | |
- Tue, 03 Sep 2013 18:56:14 GMT | |
server: | |
- nginx/1.0.15 | |
status: | |
- 404 Not Found | |
content-length: | |
- '36' | |
connection: | |
- Close | |
body: | |
encoding: US-ASCII | |
string: ! '{"errors":{"request":["Not Found"]}}' | |
http_version: | |
recorded_at: Tue, 03 Sep 2013 18:56:13 GMT | |
recorded_with: VCR 2.4.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ EMAIL=<redacted> API_TOKEN=<redacted> bundle exec ruby librato-repro-script.rb | |
Running on ruby version: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.0] | |
Using librato-metrics version: 1.0.4 | |
Deleting all prior metrics to create a clean slate | |
Submitting metric | |
Sleeping for a bit to avoid eventual consistency issues | |
Fetching metric | |
/Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/librato-metrics-1.0.4/lib/librato/metrics/middleware/expects_status.rb:15:in `on_complete': {:method=>:get, :body=>"{\"errors\":{\"request\":[\"Not Found\"]}}", :url=>#<URI::HTTPS:0x007fa5c23aad80 URL:https://metrics-api.librato.com/v1/metrics/qless.builder.failed-job-counts-all-klasses?count=2&resolution=1>, :request_headers=>{"User-Agent"=>"librato-metrics/1.0.4 (ruby; 1.9.3p327; x86_64-darwin11.4.0) direct-faraday/0.8.8", "Content-Type"=>"application/json", "Authorization"=>"Basic <redacted>=="}, :parallel_manager=>nil, :request=>{:open_timeout=>20, :timeout=>30, :proxy=>nil}, :ssl=>{}, :request_body=>nil, :status=>404, :response_headers=>{"content-type"=>"application/json", "date"=>"Tue, 03 Sep 2013 18:49:50 GMT", "server"=>"nginx/1.0.15", "status"=>"404 Not Found", "content-length"=>"36", "connection"=>"Close"}, :response=>#<Faraday::Response:0x007fa5c3472ca8 @env={...}, @on_complete_callbacks=[]>} (Librato::Metrics::NotFound) | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:9:in `block in call' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:63:in `on_complete' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/librato-metrics-1.0.4/lib/librato/metrics/middleware/count_requests.rb:22:in `call' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/librato-metrics-1.0.4/lib/librato/metrics/middleware/retry.rb:17:in `call' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/librato-metrics-1.0.4/lib/librato/metrics/middleware/request_body.rb:11:in `call' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/faraday-0.8.8/lib/faraday/connection.rb:253:in `run_request' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/faraday-0.8.8/lib/faraday/connection.rb:106:in `get' | |
from /Users/myron/code/vanguard/bundle/ruby/1.9.1/gems/librato-metrics-1.0.4/lib/librato/metrics/client.rb:160:in `fetch' | |
from librato-repro-script.rb:31:in `fetch_metric' | |
from librato-repro-script.rb:38:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment