From 0610070e593d087f1fc17af0a072462c910aabd1 Mon Sep 17 00:00:00 2001 From: BubaVV Date: Tue, 22 Aug 2023 19:40:13 +0300 Subject: [PATCH] Add timeout option for Grafana request Implemented config option to setup Grafana API request timeout Change-Id: I8cbf8ce22f199fe22c0b162ba1f419169881f193 --- watcher/conf/grafana_client.py | 8 +++++++- watcher/decision_engine/datasources/grafana.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/watcher/conf/grafana_client.py b/watcher/conf/grafana_client.py index b80a1fb1c..066ae72f4 100644 --- a/watcher/conf/grafana_client.py +++ b/watcher/conf/grafana_client.py @@ -134,7 +134,13 @@ GRAFANA_CLIENT_OPTS = [ "InfluxDB this will be the retention period. " "These queries will need to be constructed using tools " "such as Postman. Example: SELECT cpu FROM {4}." - "cpu_percent WHERE host == '{1}' AND time > now()-{2}s")] + "cpu_percent WHERE host == '{1}' AND time > now()-{2}s"), + cfg.IntOpt('http_timeout', + min=0, + default=60, + mutable=True, + help='Timeout for Grafana request') +] def register_opts(conf): diff --git a/watcher/decision_engine/datasources/grafana.py b/watcher/decision_engine/datasources/grafana.py index f7a3673e1..c8e519025 100644 --- a/watcher/decision_engine/datasources/grafana.py +++ b/watcher/decision_engine/datasources/grafana.py @@ -138,7 +138,8 @@ class GrafanaHelper(base.DataSourceBase): raise exception.DataSourceNotAvailable(self.NAME) resp = requests.get(self._base_url + str(project_id) + '/query', - params=params, headers=self._headers) + params=params, headers=self._headers, + timeout=CONF.grafana_client.http_timeout) if resp.status_code == HTTPStatus.OK: return resp elif resp.status_code == HTTPStatus.BAD_REQUEST: