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

frontend: implement cache control #1974

Merged
merged 12 commits into from
Jan 17, 2020
Next Next commit
querier: do not cache results if requested
Add an extra `Headers` field to the `PrometheusResponse` message which
contains the headers and their values that came from Prometheus.

Use them in other places to deduce if the response should be cached. If
`Cache-Control` is equal to `no-store` then it is *not* cached.

This will be used by the Thanos project to indicate when a partial
response has been returned. In such cases the result should not be
cached so that invalid data would not be stored there.

Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
GiedriusS committed Jan 16, 2020
commit 4a8a4b4194e936a55e09f74284ee3e2019fcb6f5
7 changes: 7 additions & 0 deletions pkg/querier/queryrange/query_range.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ var (

// PrometheusCodec is a codec to encode and decode Prometheus query range requests and responses.
PrometheusCodec Codec = &prometheusCodec{}

// Name of the cache control header.
cachecontrolHeader = "Cache-Control"
)

// Codec is used to encode/decode query range requests and responses so they can be passed down to middlewares.
@@ -221,6 +224,10 @@ func (prometheusCodec) DecodeResponse(ctx context.Context, r *http.Response, _ R
if err := json.Unmarshal(buf, &resp); err != nil {
return nil, httpgrpc.Errorf(http.StatusInternalServerError, "error decoding response: %v", err)
}

for h, hv := range r.Header {
resp.Headers = append(resp.Headers, &PrometheusResponseHeader{Name: h, Values: hv})
}
return &resp, nil
}

Loading