Skip to content

Commit 5371089

Browse files
authored
Fix splitByInterval incorrect error response format (#5260) (#5261)
* fix query frontend incorrect error response format * update changelog * fix integration test --------- Signed-off-by: Ben Ye <[email protected]>
1 parent 66948fd commit 5371089

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
* [BUGFIX] Query Frontend: Disable `absent`, `absent_over_time` and `scalar` for vertical sharding. #5221
6262
* [BUGFIX] Catch context error in the s3 bucket client. #5240
6363
* [BUGFIX] Fix query frontend remote read empty body. #5257
64+
* [BUGFIX] Fix query frontend incorrect error response format at `SplitByQuery` middleware. #5260
6465

6566
## 1.14.0 2022-12-02
6667

integration/query_frontend_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"testing"
1515
"time"
1616

17+
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
1718
"github.com/prometheus/common/model"
1819
"github.com/prometheus/prometheus/model/labels"
1920
"github.com/prometheus/prometheus/prompb"
@@ -345,6 +346,19 @@ func runQueryFrontendTest(t *testing.T, cfg queryFrontendTestConfig) {
345346
assert.Equal(t, model.LabelSet{labels.MetricName: "series_1"}, result[0])
346347
}
347348

349+
// No need to repeat the query 400 test for each user.
350+
if userID == 0 {
351+
start := time.Unix(1595846748, 806*1e6)
352+
end := time.Unix(1595846750, 806*1e6)
353+
354+
_, err := c.QueryRange("up)", start, end, time.Second)
355+
require.Error(t, err)
356+
357+
apiErr, ok := err.(*v1.Error)
358+
require.True(t, ok)
359+
require.Equal(t, apiErr.Type, v1.ErrBadData)
360+
}
361+
348362
for q := 0; q < numQueriesPerUser; q++ {
349363
go func() {
350364
defer wg.Done()
@@ -359,7 +373,7 @@ func runQueryFrontendTest(t *testing.T, cfg queryFrontendTestConfig) {
359373

360374
wg.Wait()
361375

362-
extra := float64(2)
376+
extra := float64(3)
363377
if cfg.testMissingMetricName {
364378
extra++
365379
}

pkg/frontend/transport/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
203203
}
204204

205205
func formatGrafanaStatsFields(r *http.Request) []interface{} {
206-
fields := make([]interface{}, 0, 2)
206+
fields := make([]interface{}, 0, 4)
207207
if dashboardUID := r.Header.Get("X-Dashboard-Uid"); dashboardUID != "" {
208-
fields = append(fields, dashboardUID)
208+
fields = append(fields, "X-Dashboard-Uid", dashboardUID)
209209
}
210210
if panelID := r.Header.Get("X-Panel-Id"); panelID != "" {
211-
fields = append(fields, panelID)
211+
fields = append(fields, "X-Panel-Id", panelID)
212212
}
213213
return fields
214214
}

pkg/querier/tripperware/queryrange/split_by_interval.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ func (s splitByInterval) Do(ctx context.Context, r tripperware.Request) (tripper
4747
// to line up the boundaries with step.
4848
reqs, err := splitQuery(r, s.interval(r))
4949
if err != nil {
50-
return nil, err
50+
// If the query itself is bad, we don't return error but send the query
51+
// to querier to return the expected error message. This is not very efficient
52+
// but should be okay for now.
53+
// TODO(yeya24): query frontend can reuse the Prometheus API handler and return
54+
// expected error message locally without passing it to the querier through network.
55+
return s.next.Do(ctx, r)
5156
}
5257
s.splitByCounter.Add(float64(len(reqs)))
5358

0 commit comments

Comments
 (0)