Skip to content

Fix splitByInterval incorrect error response format #5260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [ENHANCEMENT] Querier: Batch Iterator optimization to prevent transversing it multiple times query ranges steps does not overlap. #5237
* [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.15.0 in progress

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