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

Getting unexpected_error when trying to query Prometheus #11

Open
omerlh opened this issue Apr 4, 2021 · 11 comments
Open

Getting unexpected_error when trying to query Prometheus #11

omerlh opened this issue Apr 4, 2021 · 11 comments

Comments

@omerlh
Copy link

omerlh commented Apr 4, 2021

I just spent some time trying to figure why I cannot use this library to query my Prometheus instance.
Look like for newest Prometheus version (I'm running 2.25.2), the gzip encoding is required.
This is what worked for me:

const promDriver = new PrometheusDriver({
  endpoint: "http://localhost:9090",
  baseURL: "/api/v1",
  headers: {
    'Accept-Encoding': 'gzip'
  },
  warningHook: (x => console.log(x))
});

This issue is more for future people who might face the same issue - maybe worth adding something on the readme?

@samber
Copy link
Owner

samber commented May 1, 2021

Hi @omerlh

Can you tell me more about this issue, please?
I didn't find any information about such a requirement.

Are you using This library from a browser or into NodeJS? 🤔

Do you confirm this is not a proxy configuration in front of your prometheus server?

  • reference to a Prometheus Github issue?
  • some error message?

Thanks for your help ;)

(FYI, unexpected_error may be inserted into response by the library itself =>

errorType: 'unexpected_error',

@omerlh
Copy link
Author

omerlh commented May 2, 2021

I am using NodeJS. Not using proxy, but using kubectl port-forward to access prom - not sure if related...

@samber
Copy link
Owner

samber commented May 2, 2021

kubectl port-forward is a simple tcp proxy. I don't expect any error here.

I suppose your proxy connection was broken at that time, and the lib responded with an "unexecpted_error" message.

I let the issue opened, in case we have a similar bug report in the future.

@omerlh
Copy link
Author

omerlh commented May 2, 2021

Nope, this was very reproducible: as long as gzip encoding is not set, it was broken. Once I added it, it was solved...

@samber
Copy link
Owner

samber commented Jul 4, 2021

fixed v3.0.1

@samber
Copy link
Owner

samber commented Sep 19, 2021

hi @omerlh,

Since setting the Accept-Encoding header is forbidden, I wonder what browser are you using?

Looks like browsers automatically set this header.

@omerlh
Copy link
Author

omerlh commented Sep 20, 2021

I am not using a browser... The code I wrote was running in nodeJS

@samber
Copy link
Owner

samber commented Sep 20, 2021

This is really weird. I cannot reproduce your error.

Can you start a local Prometheus instance ? docker run --rm -it -p 9090:9090 prom/prometheus:v2.25.0

Then: npx ts-node examples/nodejs/app.ts (replace the hostname at the top of the file)

I upgraded Axios yesterday. Can you try again please?

@samber samber reopened this Sep 20, 2021
@omerlh
Copy link
Author

omerlh commented Sep 26, 2021

TBH it has been a while since I worked on it, so I will try to find time to look into it but not promising anything :)

@RossComputerGuy
Copy link

I get the same problem with my "proxy" I made for my API, all I did was add the Authorization header to my user's access token. Works fine in curl but fails with the error message described here.

@RossComputerGuy
Copy link

I might have a solution, it just needs to be verified. You just need to append this to your PrometheusDriver configuration:

{
  requestInterceptor: {
    onFulfilled: (cfg) => ({
      ...cfg,
      responseType: 'json',
      decompress: false
    })
  }
}

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

3 participants