Skip to content

Commit 1242aa5

Browse files
authored
feat(loki): allow disabling cache for query_range requests (#21112)
Allows disabling results cache via Cache-Control headers for query_range requests (the same way it's done for instant queries).
1 parent 66f9832 commit 1242aa5

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎pkg/querier/queryrange/codec.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ func (Codec) DecodeRequest(_ context.Context, r *http.Request, _ []string) (quer
342342
if err != nil {
343343
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
344344
}
345+
346+
req.CachingOptions = queryrangebase.CachingOptions{
347+
Disabled: disableCacheReq,
348+
}
349+
345350
return req, nil
346351
case InstantQueryOp:
347352
req, err := parseInstantQuery(r)

‎pkg/querier/queryrange/codec_test.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,35 @@ func Test_codec_DecodeRequest_cacheHeader(t *testing.T) {
341341
},
342342
},
343343
},
344+
{
345+
"query_range",
346+
func() (*http.Request, error) {
347+
req, err := http.NewRequest(
348+
http.MethodGet,
349+
fmt.Sprintf(`/query_range?start=%d&end=%d&query={foo="bar"}&step=10&limit=200&direction=FORWARD`, start.UnixNano(), end.UnixNano()),
350+
nil,
351+
)
352+
if err == nil {
353+
req.Header.Set(cacheControlHeader, noCacheVal)
354+
}
355+
return req, err
356+
},
357+
&LokiRequest{
358+
Query: `{foo="bar"}`,
359+
Limit: 200,
360+
Step: 10000, // step is expected in ms
361+
Direction: logproto.FORWARD,
362+
Path: "/query_range",
363+
StartTs: start,
364+
EndTs: end,
365+
Plan: &plan.QueryPlan{
366+
AST: syntax.MustParseExpr(`{foo="bar"}`),
367+
},
368+
CachingOptions: queryrangebase.CachingOptions{
369+
Disabled: true,
370+
},
371+
},
372+
},
344373
}
345374
for _, tt := range tests {
346375
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)