Search code examples
prometheuspromql

getting invalid parameter error while using prometheus api from postman


I encountered this error while trying to run the memory usage query but seems like whenever the query encounters '+' operator, the below error is thrown. There is no error while using other operators like '-', '/' and '*'. The issue is seen in Postman and also when I try to run the query using Python requests lib. The query works well in Grafana and Prometheus Web UI.

Get - http:///api/v1/query?query=count(up{instance=~".:9100"} == 1) + 100 Query - count(up{instance=~".:9100"} == 1) + 100 Error - { "status": "error", "errorType": "bad_data", "error": "invalid parameter "query": 1:39: parse error: unexpected number "100"" }

Prometheus Version - 2.48.1


Solution

  • You must URL encode query string parameters both the key (query) and the value (in this case your PromQL) i.e. count(up{instance=~".:9100"} == 1) + 100.

    Using URLencoder, yields:

    count%28up%7Binstance%3D~%22.%3A9100%22%7D%20%3D%3D%201%29%20%2B%20100

    query is unchanged, thus:

    api/v1/query?query=count%28up%7Binstance%3D~%22.%3A9100%22%7D%20%3D%3D%201%29%20%2B%20100