Skip to content

Commit

Permalink
[im-2290] Instrument timeout exceptions (#110)
Browse files Browse the repository at this point in the history
* instrument timeout exceptions
  • Loading branch information
anujc4 authored May 28, 2024
1 parent 17870e9 commit ec008a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
.idea
.bundle/
doc/
.yardoc/
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

_A description of your awesome changes here!_

- Instrument timeout exceptions (#110)

### 3.7.1

Features:
Expand Down
3 changes: 3 additions & 0 deletions lib/routemaster/middleware/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions spec/routemaster/integration/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ec008a2

Please sign in to comment.