From 6564dc6c1628ae0918cecabe6274b31e27c0678a Mon Sep 17 00:00:00 2001 From: Wataru Manji Date: Tue, 7 Jun 2022 21:33:21 +0900 Subject: [PATCH] add Content-Encoding Header (#2685) Co-authored-by: Wataru Manji --- app/vmalert/remotewrite/remotewrite.go | 3 +++ app/vmalert/remotewrite/remotewrite_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/app/vmalert/remotewrite/remotewrite.go b/app/vmalert/remotewrite/remotewrite.go index 992cea22b..6d94c9ba0 100644 --- a/app/vmalert/remotewrite/remotewrite.go +++ b/app/vmalert/remotewrite/remotewrite.go @@ -236,6 +236,9 @@ func (c *Client) send(ctx context.Context, data []byte) error { if err != nil { return fmt.Errorf("failed to create new HTTP request: %w", err) } + + req.Header.Set("Content-Encoding", "snappy") + if c.authCfg != nil { if auth := c.authCfg.GetAuthHeader(); auth != "" { req.Header.Set("Authorization", auth) diff --git a/app/vmalert/remotewrite/remotewrite_test.go b/app/vmalert/remotewrite/remotewrite_test.go index 18a9cfff6..8f2a64b5d 100644 --- a/app/vmalert/remotewrite/remotewrite_test.go +++ b/app/vmalert/remotewrite/remotewrite_test.go @@ -80,6 +80,12 @@ func (rw *rwServer) handler(w http.ResponseWriter, r *http.Request) { rw.err(w, fmt.Errorf("bad method %q", r.Method)) return } + + h := r.Header.Get("Content-Encoding") + if h != "snappy" { + rw.err(w, fmt.Errorf("header read error: Content-Encoding is not snappy (%q)", h)) + } + data, err := ioutil.ReadAll(r.Body) if err != nil { rw.err(w, fmt.Errorf("body read err: %w", err))