Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to add filters in API Prometheus query via awscurl in python script #197

Closed
lyrecoSquared opened this issue Mar 19, 2024 · 3 comments
Closed

Comments

@lyrecoSquared
Copy link

I am trying to query an Amazon Managed Service for Prometheus endpoint to extract some metrics data via a python script using the make_request method in the following way (cleary this is an example snippet):

import awscurl.awscurl as aws

uri = 'https://<SERVICE>-workspaces.<REGION>.amazonaws.com/workspaces/<WORKSPACE_ID>/api/v1/query_range?query=http_request_total&start=1710720000.0&end=1710806400.0&step=1h'

headers = {
    'Content-Type': 'application/json',
}
awscurl_auth_params = {
        'method': 'GET',
        'service': <SERVICE>,
        'region': <REGION>,
        'uri': uri,
        'headers': headers,
        'data': '',
        'access_key': <ACCES_KEY>,
        'secret_key': <SECRET_KEY>,
        'security_token': None,
        'data_binary': False}
r = aws.make_request(**awscurl_auth_params)

In this way, I am able to successfully connect to the endpoint and download the data related to the query query=http_request_total&start=1710720000.0&end=1710806400.0&step=1h.

However, as soon as I try to add a filter (as statuscode="200") in the query (e.g. query=http_request_total{statuscode="200"}&start=1710720000.0&end=1710806400.0&step=1h), the same script as above, returns a tedious 400 status code and an annoying 'x-amzn-errortype': 'InvalidQueryStringException' error.

What am I doing wrong?

Thanks in advance.

@okigan
Copy link
Owner

okigan commented Mar 19, 2024 via email

@lyrecoSquared
Copy link
Author

I tried to encode the quotes, replacing them with %22 but it still gives me the error.
Thanks anyway, I will surely check for some info in prior issues.

@lyrecoSquared
Copy link
Author

For the sake of completeness: #169 (comment) worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants