Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[im-2290] Instrument timeout exceptions #110

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If the circuit is open we won't report any metrics)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but we would know how many timeouts we received before the breaker was tripped. We anyway don't push any metric once a circuit trips. We would have to record circuitbox metrics for that information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add connection too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdym? Routemaster::Errors::BaseError and Faraday::TimeoutError are the only exceptions that are monitored by CircuitBox

Copy link
Contributor

@smnalex smnalex May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant Faraday::ConnectionFailed, but sorry, forgot that you made this change only for CB.

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
Loading