diff --git a/.gitignore b/.gitignore index bf3b83b..3652efd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.vscode +.idea .bundle/ doc/ .yardoc/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b251cf..3099794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ _A description of your awesome changes here!_ +- Instrument timeout exceptions (#110) + ### 3.7.1 Features: diff --git a/lib/routemaster/middleware/metrics.rb b/lib/routemaster/middleware/metrics.rb index ac97ffe..eec348a 100644 --- a/lib/routemaster/middleware/metrics.rb +++ b/lib/routemaster/middleware/metrics.rb @@ -22,6 +22,9 @@ def call(request_env) rescue Routemaster::Errors::BaseError => e increment_response_count(response_tags(e.env)) raise e + rescue Faraday::TimeoutError => e + increment_response_count(%W[source:#{source_peer} destination:#{request_env.url.host} status:timeout]) + raise e end end end diff --git a/spec/routemaster/integration/api_client_spec.rb b/spec/routemaster/integration/api_client_spec.rb index 81dcdf1..33bbd46 100644 --- a/spec/routemaster/integration/api_client_spec.rb +++ b/spec/routemaster/integration/api_client_spec.rb @@ -394,5 +394,32 @@ def timestamp ; subject.get(url).body.updated_at ; end 'api_client.latency', tags: %w[source:test_service destination:127.0.0.1 verb:get] ) end + + context 'when the response status code is non-2xx' do + it 'sends the response metrics with the status code and error class fatal resource' do + expect { subject.post("#{host}/429") }.to raise_error(Routemaster::Errors::ResourceThrottling) + + expect(metrics_client).to have_received(:increment).with( + 'api_client.response.count', tags: %w[source:test_service destination:127.0.0.1 status:429] + ) + end + + it 'sends the response metrics with the status code and error class fatal resource' do + expect { subject.post("#{host}/500") }.to raise_error(Routemaster::Errors::FatalResource) + + expect(metrics_client).to have_received(:increment).with( + 'api_client.response.count', tags: %w[source:test_service destination:127.0.0.1 status:500] + ) + end + + it 'sends the response metrics with the status code and error class fatal resource' do + stub_request(:put, "#{host}/429").to_timeout + expect { subject.put("#{host}/429") }.to raise_error(Faraday::TimeoutError) + + expect(metrics_client).to have_received(:increment).with( + 'api_client.response.count', tags: %w[source:test_service destination:127.0.0.1 status:timeout] + ).at_least(1).times + end + end end end