Skip to content

Commit

Permalink
queryfrontend: fix explanation with query_range (thanos-io#6633)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiedriusS authored Aug 22, 2023
1 parent 8fcd30f commit d82948a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
19 changes: 11 additions & 8 deletions internal/cortex/querier/queryrange/results_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func (PrometheusResponseExtractor) Extract(start, end int64, from Response) Resp
return &PrometheusResponse{
Status: StatusSuccess,
Data: PrometheusData{
ResultType: promRes.Data.ResultType,
Result: extractMatrix(start, end, promRes.Data.Result),
Stats: extractStats(start, end, promRes.Data.Stats),
ResultType: promRes.Data.ResultType,
Result: extractMatrix(start, end, promRes.Data.Result),
Stats: extractStats(start, end, promRes.Data.Stats),
Explanation: promRes.Data.Explanation,
},
Headers: promRes.Headers,
}
Expand All @@ -109,9 +110,10 @@ func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp Response) Respons
return &PrometheusResponse{
Status: StatusSuccess,
Data: PrometheusData{
ResultType: promRes.Data.ResultType,
Result: promRes.Data.Result,
Stats: promRes.Data.Stats,
ResultType: promRes.Data.ResultType,
Result: promRes.Data.Result,
Stats: promRes.Data.Stats,
Explanation: promRes.Data.Explanation,
},
}
}
Expand All @@ -122,8 +124,9 @@ func (PrometheusResponseExtractor) ResponseWithoutStats(resp Response) Response
return &PrometheusResponse{
Status: StatusSuccess,
Data: PrometheusData{
ResultType: promRes.Data.ResultType,
Result: promRes.Data.Result,
ResultType: promRes.Data.ResultType,
Result: promRes.Data.Result,
Explanation: promRes.Data.Explanation,
},
Headers: promRes.Headers,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/queryfrontend/queryinstant_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (c queryInstantCodec) DecodeRequest(_ context.Context, r *http.Request, for

result.Query = r.FormValue("query")
result.Path = r.URL.Path
result.Explain = r.FormValue("explain")
result.Explain = r.FormValue(queryv1.QueryExplainParam)
result.Engine = r.FormValue("engine")

for _, header := range forwardHeaders {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ func TestQFEEngineExplanation(t *testing.T) {
explanation := rangeQuery(t, ctx, queryFrontend.Endpoint("http"), e2ethanos.QueryUpWithoutInstance,
timestamp.FromTime(now.Add(-5*time.Minute)),
timestamp.FromTime(now), 1, promclient.QueryOptions{
Explain: true,
Engine: "thanos",
Explain: true,
Engine: "thanos",
Deduplicate: true,
}, func(res model.Matrix) error {
if res.Len() == 0 {
return fmt.Errorf("expected results")
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestQFEEngineExplanation(t *testing.T) {

t.Run("explanation works with instant query", func(t *testing.T) {
_, explanation := instantQuery(t, ctx, queryFrontend.Endpoint("http"), e2ethanos.QueryUpWithoutInstance, time.Now, promclient.QueryOptions{
Deduplicate: false,
Deduplicate: true,
Engine: "thanos",
Explain: true,
}, 1)
Expand Down

0 comments on commit d82948a

Please sign in to comment.