Merge "Prometheus: Add timeout for HTTP requests"
This commit is contained in:
@@ -59,6 +59,12 @@ collector_prometheus_opts = [
|
||||
default=False,
|
||||
help='Explicitly trust untrusted HTTPS responses',
|
||||
),
|
||||
cfg.FloatOpt(
|
||||
'timeout',
|
||||
default=60,
|
||||
min=0,
|
||||
help='Timeout value for http requests',
|
||||
),
|
||||
]
|
||||
cfg.CONF.register_opts(collector_prometheus_opts, PROMETHEUS_COLLECTOR_OPTS)
|
||||
|
||||
@@ -110,6 +116,7 @@ class PrometheusCollector(collector.BaseCollector):
|
||||
url,
|
||||
auth=(user, password) if user and password else None,
|
||||
verify=verify,
|
||||
timeout=CONF.collector_prometheus.timeout
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -23,10 +23,11 @@ class PrometheusClient(object):
|
||||
INSTANT_QUERY_ENDPOINT = 'query'
|
||||
RANGE_QUERY_ENDPOINT = 'query_range'
|
||||
|
||||
def __init__(self, url, auth=None, verify=True):
|
||||
def __init__(self, url, auth=None, verify=True, timeout=60):
|
||||
self.url = url
|
||||
self.auth = auth
|
||||
self.verify = verify
|
||||
self.timeout = timeout
|
||||
|
||||
def _get(self, endpoint, params):
|
||||
return requests.get(
|
||||
@@ -34,6 +35,7 @@ class PrometheusClient(object):
|
||||
params=params,
|
||||
auth=self.auth,
|
||||
verify=self.verify,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
|
||||
def get_instant(self, query, time=None, timeout=None):
|
||||
|
||||
@@ -58,6 +58,12 @@ fetcher_prometheus_opts = [
|
||||
default=False,
|
||||
help='Explicitly trust untrusted HTTPS responses',
|
||||
),
|
||||
cfg.FloatOpt(
|
||||
'timeout',
|
||||
default=60,
|
||||
min=0,
|
||||
help='Timeout value for http requests',
|
||||
),
|
||||
cfg.DictOpt(
|
||||
'filters',
|
||||
default=dict(),
|
||||
@@ -92,6 +98,7 @@ class PrometheusFetcher(fetcher.BaseFetcher):
|
||||
url,
|
||||
auth=(user, password) if user and password else None,
|
||||
verify=verify,
|
||||
timeout=CONF.fetcher_prometheus.timeout
|
||||
)
|
||||
|
||||
def get_tenants(self):
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Introduced timeout for HTTP requests sent to Prometheus. Timeout thresholds
|
||||
are 60 seconds by default and can be customized by the following options.
|
||||
|
||||
- ``[collector_prometheus] timeout``
|
||||
- ``[fetcher_prometheus] timeout``
|
||||
Reference in New Issue
Block a user