Add remote-write headers (#2701)

Co-authored-by: Wataru Manji <wataru.manji@linecorp.com>
This commit is contained in:
Wataru Manji 2022-06-13 15:59:03 +09:00 committed by Aliaksandr Valialkin
parent 8128c6db6b
commit 0cd750fa5e
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 15 additions and 0 deletions

View file

@ -237,7 +237,12 @@ func (c *Client) send(ctx context.Context, data []byte) error {
return fmt.Errorf("failed to create new HTTP request: %w", err) return fmt.Errorf("failed to create new HTTP request: %w", err)
} }
// RFC standard compliant headers
req.Header.Set("Content-Encoding", "snappy") req.Header.Set("Content-Encoding", "snappy")
req.Header.Set("Content-Type", "application/x-protobuf")
// Prometheus compliant headers
req.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
if c.authCfg != nil { if c.authCfg != nil {
if auth := c.authCfg.GetAuthHeader(); auth != "" { if auth := c.authCfg.GetAuthHeader(); auth != "" {

View file

@ -86,6 +86,16 @@ func (rw *rwServer) handler(w http.ResponseWriter, r *http.Request) {
rw.err(w, fmt.Errorf("header read error: Content-Encoding is not snappy (%q)", h)) rw.err(w, fmt.Errorf("header read error: Content-Encoding is not snappy (%q)", h))
} }
h = r.Header.Get("Content-Type")
if h != "application/x-protobuf" {
rw.err(w, fmt.Errorf("header read error: Content-Type is not x-protobuf (%q)", h))
}
h = r.Header.Get("X-Prometheus-Remote-Write-Version")
if h != "0.1.0" {
rw.err(w, fmt.Errorf("header read error: X-Prometheus-Remote-Write-Version is not 0.1.0 (%q)", h))
}
data, err := ioutil.ReadAll(r.Body) data, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
rw.err(w, fmt.Errorf("body read err: %w", err)) rw.err(w, fmt.Errorf("body read err: %w", err))