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).
This commit is contained in:
Ivan Kalita
2026-03-09 14:19:16 +01:00
committed by GitHub
parent 66f983286e
commit 1242aa5547
2 changed files with 34 additions and 0 deletions

View File

@@ -342,6 +342,11 @@ func (Codec) DecodeRequest(_ context.Context, r *http.Request, _ []string) (quer
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
req.CachingOptions = queryrangebase.CachingOptions{
Disabled: disableCacheReq,
}
return req, nil
case InstantQueryOp:
req, err := parseInstantQuery(r)

View File

@@ -341,6 +341,35 @@ func Test_codec_DecodeRequest_cacheHeader(t *testing.T) {
},
},
},
{
"query_range",
func() (*http.Request, error) {
req, err := http.NewRequest(
http.MethodGet,
fmt.Sprintf(`/query_range?start=%d&end=%d&query={foo="bar"}&step=10&limit=200&direction=FORWARD`, start.UnixNano(), end.UnixNano()),
nil,
)
if err == nil {
req.Header.Set(cacheControlHeader, noCacheVal)
}
return req, err
},
&LokiRequest{
Query: `{foo="bar"}`,
Limit: 200,
Step: 10000, // step is expected in ms
Direction: logproto.FORWARD,
Path: "/query_range",
StartTs: start,
EndTs: end,
Plan: &plan.QueryPlan{
AST: syntax.MustParseExpr(`{foo="bar"}`),
},
CachingOptions: queryrangebase.CachingOptions{
Disabled: true,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {