Skip to content

Commit

Permalink
Fix splitByInterval incorrect error response format (#5260) (#5261)
Browse files Browse the repository at this point in the history
* fix query frontend incorrect error response format



* update changelog



* fix integration test



---------

Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 authored Apr 12, 2023
1 parent 66948fd commit 5371089
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* [BUGFIX] Query Frontend: Disable `absent`, `absent_over_time` and `scalar` for vertical sharding. #5221
* [BUGFIX] Catch context error in the s3 bucket client. #5240
* [BUGFIX] Fix query frontend remote read empty body. #5257
* [BUGFIX] Fix query frontend incorrect error response format at `SplitByQuery` middleware. #5260

## 1.14.0 2022-12-02

Expand Down
16 changes: 15 additions & 1 deletion integration/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"testing"
"time"

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

// No need to repeat the query 400 test for each user.
if userID == 0 {
start := time.Unix(1595846748, 806*1e6)
end := time.Unix(1595846750, 806*1e6)

_, err := c.QueryRange("up)", start, end, time.Second)
require.Error(t, err)

apiErr, ok := err.(*v1.Error)
require.True(t, ok)
require.Equal(t, apiErr.Type, v1.ErrBadData)
}

for q := 0; q < numQueriesPerUser; q++ {
go func() {
defer wg.Done()
Expand All @@ -359,7 +373,7 @@ func runQueryFrontendTest(t *testing.T, cfg queryFrontendTestConfig) {

wg.Wait()

extra := float64(2)
extra := float64(3)
if cfg.testMissingMetricName {
extra++
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func formatGrafanaStatsFields(r *http.Request) []interface{} {
fields := make([]interface{}, 0, 2)
fields := make([]interface{}, 0, 4)
if dashboardUID := r.Header.Get("X-Dashboard-Uid"); dashboardUID != "" {
fields = append(fields, dashboardUID)
fields = append(fields, "X-Dashboard-Uid", dashboardUID)
}
if panelID := r.Header.Get("X-Panel-Id"); panelID != "" {
fields = append(fields, panelID)
fields = append(fields, "X-Panel-Id", panelID)
}
return fields
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/querier/tripperware/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func (s splitByInterval) Do(ctx context.Context, r tripperware.Request) (tripper
// to line up the boundaries with step.
reqs, err := splitQuery(r, s.interval(r))
if err != nil {
return nil, err
// If the query itself is bad, we don't return error but send the query
// to querier to return the expected error message. This is not very efficient
// but should be okay for now.
// TODO(yeya24): query frontend can reuse the Prometheus API handler and return
// expected error message locally without passing it to the querier through network.
return s.next.Do(ctx, r)
}
s.splitByCounter.Add(float64(len(reqs)))

Expand Down

0 comments on commit 5371089

Please sign in to comment.