@@ -396,6 +396,7 @@ def custom_query(self, query: str, params: dict = None, timeout: int = None):
396
396
at https://prometheus.io/docs/prometheus/latest/querying/examples/
397
397
:param params: (dict) Optional dictionary containing GET parameters to be
398
398
sent along with the API request, such as "time"
399
+ :param timeout: (int) A timeout (in seconds) applied to the request
399
400
:returns: (list) A list of metric data received in response of the query sent
400
401
:raises:
401
402
(RequestException) Raises an exception in case of a connection error
@@ -404,6 +405,7 @@ def custom_query(self, query: str, params: dict = None, timeout: int = None):
404
405
params = params or {}
405
406
data = None
406
407
query = str (query )
408
+ timeout = self ._timeout if timeout is None else timeout
407
409
# using the query API to get raw data
408
410
response = self ._session .get (
409
411
"{0}/api/v1/query" .format (self .url ),
@@ -412,7 +414,7 @@ def custom_query(self, query: str, params: dict = None, timeout: int = None):
412
414
headers = self .headers ,
413
415
auth = self .auth ,
414
416
cert = self ._session .cert ,
415
- timeout = self . _timeout ,
417
+ timeout = timeout ,
416
418
)
417
419
if response .status_code == 200 :
418
420
data = response .json ()["data" ]["result" ]
@@ -424,7 +426,7 @@ def custom_query(self, query: str, params: dict = None, timeout: int = None):
424
426
return data
425
427
426
428
def custom_query_range (
427
- self , query : str , start_time : datetime , end_time : datetime , step : str , params : dict = None
429
+ self , query : str , start_time : datetime , end_time : datetime , step : str , params : dict = None , timeout : int = None
428
430
):
429
431
"""
430
432
Send a query_range to a Prometheus Host.
@@ -439,6 +441,7 @@ def custom_query_range(
439
441
:param step: (str) Query resolution step width in duration format or float number of seconds
440
442
:param params: (dict) Optional dictionary containing GET parameters to be
441
443
sent along with the API request, such as "timeout"
444
+ :param timeout: (int) A timeout (in seconds) applied to the request
442
445
:returns: (dict) A dict of metric data received in response of the query sent
443
446
:raises:
444
447
(RequestException) Raises an exception in case of a connection error
@@ -449,6 +452,7 @@ def custom_query_range(
449
452
params = params or {}
450
453
data = None
451
454
query = str (query )
455
+ timeout = self ._timeout if timeout is None else timeout
452
456
# using the query_range API to get raw data
453
457
response = self ._session .get (
454
458
"{0}/api/v1/query_range" .format (self .url ),
@@ -457,7 +461,7 @@ def custom_query_range(
457
461
headers = self .headers ,
458
462
auth = self .auth ,
459
463
cert = self ._session .cert ,
460
- timeout = self . _timeout ,
464
+ timeout = timeout ,
461
465
)
462
466
if response .status_code == 200 :
463
467
data = response .json ()["data" ]["result" ]
0 commit comments