@@ -224,7 +224,7 @@ def _metric_filename(self, metric_name, end_timestamp):
224
224
return object_path
225
225
226
226
@retry (stop_max_attempt_number = MAX_REQUEST_RETRIES , wait_fixed = CONNECTION_RETRY_WAIT_TIME )
227
- def custom_query (self , query : str ):
227
+ def custom_query (self , query : str , params : dict = {} ):
228
228
"""
229
229
A method to send a custom query to a Prometheus Host.
230
230
@@ -234,6 +234,9 @@ def custom_query(self, query: str):
234
234
:param query: (str) This is a PromQL query, a few examples can be found
235
235
at https://prometheus.io/docs/prometheus/latest/querying/examples/
236
236
237
+ :param params: (dict) Optional dictionary containing GET parameters to be
238
+ sent along with the API request, such as "time"
239
+
237
240
:Returns: (list) A list of metric data received in response of the query sent
238
241
239
242
:raises: (Http Response error) Raises an exception in case of a connection error
@@ -242,11 +245,12 @@ def custom_query(self, query: str):
242
245
data = None
243
246
query = str (query )
244
247
# using the query API to get raw data
245
- response = requests .get ('{0}/api/v1/query' .format (self .url ),
246
- params = {'query' : query
247
- },
248
- verify = self .ssl_verification ,
249
- headers = self .headers )
248
+ response = requests .get (
249
+ "{0}/api/v1/query" .format (self .url ),
250
+ params = {** {"query" : query }, ** params },
251
+ verify = self .ssl_verification ,
252
+ headers = self .headers ,
253
+ )
250
254
if response .status_code == 200 :
251
255
data = response .json ()['data' ]['result' ]
252
256
else :
0 commit comments