datasources: querier: request parsing failures are not http 500 (#94488)

* datasources: querier: request parsing failures are not http500

* fix test

---------

Co-authored-by: Adam Simpson <adam@adamsimpson.net>
This commit is contained in:
Gábor Farkas 2024-10-09 23:28:27 +02:00 committed by GitHub
parent c6c93a02aa
commit 0a7b731242
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 9 deletions

View File

@ -122,15 +122,22 @@ func (r *queryREST) Connect(connectCtx context.Context, name string, _ runtime.O
// Parses the request and splits it into multiple sub queries (if necessary)
req, err := b.parser.parseRequest(ctx, raw)
if err != nil {
reason := metav1.StatusReasonInvalid
message := err.Error()
if errors.Is(err, datasources.ErrDataSourceNotFound) {
reason = metav1.StatusReasonNotFound
// TODO, can we wrap the error somehow?
err = &errorsK8s.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusBadRequest, // the URL is found, but includes bad requests
Reason: metav1.StatusReasonNotFound,
Message: "datasource not found",
}}
message = "datasource not found"
}
err = &errorsK8s.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusBadRequest,
Reason: reason,
Message: message,
}}
responder.Error(err)
return
}

View File

@ -143,9 +143,8 @@ func TestIntegrationSimpleQuery(t *testing.T) {
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "did not execute expression [Y] due to a failure to of the dependent expression or query [X]",
"reason": "BadRequest",
"details": { "uid": "sse.dependencyError" },
"message": "[sse.dependencyError] did not execute expression [Y] due to a failure to of the dependent expression or query [X]",
"reason": "Invalid",
"code": 400
}`, string(body))
// require.JSONEq(t, `{