prometheus-api-client-python icon indicating copy to clipboard operation
prometheus-api-client-python copied to clipboard

Domain name parse error: unexpected identifier

Open rmalenko opened this issue 2 years ago • 3 comments

I have got this error full domain name au.edu in error message \\"au\\" i.e .edu is disappeared

File "./prometheus_query.py", line 35, in <module>
    metric_data = prom.custom_query(
  File "/usr/local/lib/python3.8/dist-packages/prometheus_api_client/prometheus_connect.py", line 355, in custom_query
    raise PrometheusApiClientException(
prometheus_api_client.exceptions.PrometheusApiClientException: HTTP Status Code 400 (b'{"status":"error","errorType":"bad_data","error":"invalid parameter \\"query\\": 1:70: parse error: unexpected identifier \\"aubg\\" in label matching, expected string"}')

my code is:

domain = "au.edu"

metric_data = prom.custom_query(
    query="avg_over_time(host_tracker_uptime_percent{job='donodeexporter', zone="f'{domain}'"}[30d])"
)
metric_df = MetricSnapshotDataFrame(metric_data)
print(metric_df.head())

If I provide domain name this code works

metric_data = prom.custom_query(
    query="avg_over_time(host_tracker_uptime_percent{job='donodeexporter', zone='au.edu'}[30d])"
)
metric_df = MetricSnapshotDataFrame(metric_data)
print(metric_df.head())
    instance             job                   zone     timestamp                                        value
0  prom.k.com  donodeexporter  au.edu 2022-11-03 11:44:08.178999808  99.921485

rmalenko avatar Nov 03 '22 11:11 rmalenko

I believe the issue is simply a matter of quotation marks. To fix it, you should add single quotes around "f'{domain}'". Here's an example of what the corrected query should look like:

query="avg_over_time(host_tracker_uptime_percent{job='donodeexporter', zone='"f'{domain}'"' }[30d])"

Currently, the computed value of your query is:

avg_over_time(host_tracker_uptime_percent{job='donodeexporter', zone=au.edu}[30d])

But it should be:

avg_over_time(host_tracker_uptime_percent{job='donodeexporter', zone='au.edu'}[30d])

Please update your query accordingly.

@rmalenko

psujit775 avatar Mar 22 '23 02:03 psujit775

@psujit775 thank you!

rmalenko avatar Mar 22 '23 08:03 rmalenko

Hi @rmalenko, was your error resolved? Could this issue be closed now?

chauhankaranraj avatar Mar 31 '23 03:03 chauhankaranraj