Skip to content

Querier: return 400 for an invalid instant query time - #7980

Open
blaketsk wants to merge 2 commits into
cortexproject:masterfrom
blaketsk:queryapi-invalid-param-status
Open

blaketsk wants to merge 2 commits into
cortexproject:masterfrom
blaketsk:queryapi-invalid-param-status

Conversation

@blaketsk

@blaketsk blaketsk commented Dec 1, 2026

Copy link
Copy Markdown

What this PR does:

Returns 400 bad_data instead of 500 server_error for an instant query with an invalid time parameter, for example /api/v1/query?query=up&time=invalid.

util.ParseTimeParam returns the 400 httpgrpc error from util.ParseTime wrapped with errors.Wrapf. DecorateWithParamName then used gogo/status.FromError, which only looks at the error itself and doesn't unwrap it, so the status was lost and RespondFromGRPCError reported it as a server error. This PR switches DecorateWithParamName to google.golang.org/grpc/status, whose FromError finds the status of a wrapped error. The error message is unchanged.

The start, end and step parameters of range queries weren't affected, because their errors aren't wrapped. Test_InvalidParamReturnsBadRequest covers them too, as a regression test. The time case of that test and the wrapped error case of Test_DecorateWithParamName fail without the change.

The message of a wrapped error still includes the gRPC status text, as it did before: invalid parameter "time"; Invalid time value for 'time': rpc error: code = Code(400) desc = cannot parse "invalid" to a valid timestamp. Using the message of the innermost status would make it cleaner, but would change the error text users see, so I left it out. Happy to do it here or in a follow-up if you prefer.

I noticed this while testing #7979.

Which issue(s) this PR fixes:
None, I found no existing issue.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

AI disclosure: per GENAI_POLICY.md, the fix and the tests were prepared with Claude Code. I reviewed and verified the changes.

🤖 Generated with Claude Code

An instant query with an invalid time parameter returned
500 server_error instead of 400 bad_data. util.ParseTimeParam wraps
the 400 httpgrpc error with errors.Wrapf, and DecorateWithParamName
used gogo/status.FromError, which doesn't unwrap errors, so the status
was lost and the error was reported as a server error.

Use google.golang.org/grpc/status, whose FromError finds the status of
a wrapped error. The error message is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d
Signed-off-by: Andrey Osipov <[email protected]>
@blaketsk
blaketsk requested a review from a team as a code owner December 1, 2026 16:20
@blaketsk
blaketsk requested a review from friedrichg December 1, 2026 16:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant