Set appropriate timeouts for PrometheusClient
What does this MR do?
In #232468 (closed) we found that currently, Gitlab::HTTP
and by extension PrometheusClient
do not set a default read or even connection timeout. The default is whatever Ruby's Net::HTTP
uses, which is 60 seconds -- that is very long, and in fact a terrible default to use. HTTP services should be considered ready to respond within a few seconds at most, otherwise they should be considered unavailable and retried later.
This MR changes the connection and read timeouts for PrometheusClient
only, since this seemed to be the smallest change to make first. It sets it to:
- connect/open timeout: 5s
- read timeout: 10s
which are both still generous, but for something not on a performance critical path seemed to be reasonable.
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
Since this is just configuration, I did not add unit tests.
It is easy to verify though:
- Set Prometheus address to somewhere it is not listening, e.g.
Settings.prometheus['listen_address'] = '192.178.1.2:9090'
- Run
Gitlab::PrometheusClient.new(Gitlab::Prometheus::Internal.uri, :allow_local_requests => true).query('abc')
Before: Times out after 60s
After: Times out after 5s
Closes #232468 (closed)