Skip to content
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

Handle query parsing errors on QFE range split middleware #6172

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#6172](https://github.com/thanos-io/thanos/pull/6172) query-frontend: return JSON formatted errors for invalid PromQL expression in the split by interval middleware.
- [#6171](https://github.com/thanos-io/thanos/pull/6171) Store: fix error handling on limits.

### Changed
Expand Down
2 changes: 1 addition & 1 deletion internal/cortex/querier/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func splitQuery(r Request, interval time.Duration) ([]Request, error) {
func EvaluateAtModifierFunction(query string, start, end int64) (string, error) {
expr, err := parser.ParseExpr(query)
if err != nil {
return "", httpgrpc.Errorf(http.StatusBadRequest, "%s", err)
return "", httpgrpc.Errorf(http.StatusBadRequest, `{"status": "error", "error": "%s"}`, err)
}
parser.Inspect(expr, func(n parser.Node, _ []parser.Node) error {
if selector, ok := n.(*parser.VectorSelector); ok {
Expand Down
20 changes: 20 additions & 0 deletions pkg/queryfrontend/split_by_interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package queryfrontend

import (
"encoding/json"
"strconv"
"testing"
"time"

"github.com/weaveworks/common/httpgrpc"

"github.com/stretchr/testify/require"
"github.com/thanos-io/thanos/internal/cortex/querier/queryrange"
)
Expand Down Expand Up @@ -238,3 +241,20 @@ func TestSplitQuery(t *testing.T) {
})
}
}

func TestSplitQuery_PromQLErrorReturnsJson(t *testing.T) {
input := &ThanosQueryRangeRequest{
Start: 2 * 3600 * seconds,
End: 3 * 3 * 3600 * seconds,
Step: 15 * seconds,
Query: "foo{",
}
queries, err := splitQuery(input, 1*time.Hour)
require.Error(t, err)
require.Nil(t, queries)

resp, ok := httpgrpc.HTTPResponseFromError(err)
require.True(t, ok, "could not assemble httpgrpc.HTTPResponse, is not status.Status")

require.True(t, json.Valid(resp.Body), "error message is not valid JSON: %s", resp.Body)
}