Skip to content

Commit d39ce58

Browse files
Merge pull request #19 from abyrne55/get_params
Added option to specify GET params in custom_query()
2 parents b74ab05 + d2c70b4 commit d39ce58

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

prometheus_api_client/prometheus_connect.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _metric_filename(self, metric_name, end_timestamp):
224224
return object_path
225225

226226
@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 = {}):
228228
"""
229229
A method to send a custom query to a Prometheus Host.
230230
@@ -234,6 +234,9 @@ def custom_query(self, query: str):
234234
:param query: (str) This is a PromQL query, a few examples can be found
235235
at https://prometheus.io/docs/prometheus/latest/querying/examples/
236236
237+
:param params: (dict) Optional dictionary containing GET parameters to be
238+
sent along with the API request, such as "time"
239+
237240
:Returns: (list) A list of metric data received in response of the query sent
238241
239242
:raises: (Http Response error) Raises an exception in case of a connection error
@@ -242,11 +245,12 @@ def custom_query(self, query: str):
242245
data = None
243246
query = str(query)
244247
# 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+
)
250254
if response.status_code == 200:
251255
data = response.json()['data']['result']
252256
else:

0 commit comments

Comments
 (0)