huksley / prometheus-remote-write

Send samples to prometheus via remote_write from NodeJS
MIT License
20 stars 6 forks source link

Write request fails in Prometheus v2.54.0 (2024-08-09) #7

Open 029A-h opened 1 month ago

029A-h commented 1 month ago

In the recent version of Prometheus (since v2.54.0), write requests fail with a 415 HTTP status code (Unsupported Media Type) and the error message: expected application/x-protobuf as the first (media) part, got application/vnd.google.protobuf content-type.

As observed in write_handler.go:81, the Content-Type header is validated against application/x-protobuf, which is different from the default header application/vnd.google.protobuf used in the prometheus-remote-write library.

Quick Fix: Add the Content-Type header to the config object as follows:

Copy code
const config = {
  ...
  headers: {
    'Content-Type': 'application/x-protobuf'
  }
  ...
};

Suggested Solution: Change the default content type in remote write requests to application/x-protobuf.

huksley commented 1 month ago

Yeah, it seems like 'application/vnd.google.protobuf' is a legacy thing, even 1.0 older spec requires 'application/x-protobuf' content type. I am glad there no other changes needed...

https://prometheus.io/docs/specs/remote_write_spec/