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

Fix the response status code logged in 'query stats' on error #8407

Merged
merged 6 commits into from
Jun 18, 2024

Conversation

pracucci
Copy link
Collaborator

What this PR does

Today, if an error occurs in the query-frontend middlewares, the "query stats" log contains status_code=0. However, we actually return a valid HTTP response to the client, with a legit status code, so we should log the actual status_code.

This PR fixes it.

Which issue(s) this PR fixes or relates to

N/A

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

Signed-off-by: Marco Pracucci <marco@pracucci.com>

// If we've been able to get the HTTP response from the error, then we send
// it with the right status code and response body content.
if res != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: the logic should have not been changed at all (at least not intentionally). What I'm doing here is exactly what we did before calling httpgrpc.WriteResponse(w, resp) and httpgrpc.WriteError(w, err).

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
@pracucci pracucci marked this pull request as ready for review June 18, 2024 07:42
@pracucci pracucci requested a review from a team as a code owner June 18, 2024 07:42
Copy link
Contributor

@krajorama krajorama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with 2 nits

httpgrpc.WriteError(w, err)
// Otherwise, we do fallback to a 5xx error, returning the non-formatted error
// message in the response body.
statusCode = http.StatusInternalServerError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think it works better as a fallback if you put this line at the top of the function, then any time we cannot or miss updating it, the result will be http.StatusInternalServerError

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the problem but I'm not convinced that having a default is the right thing to do. I want to make sure that we always return the right status code. To solve it, I took a different approach and I removed the named return parameter so that it's intentional what we return: 793436b

pkg/frontend/transport/handler_test.go Show resolved Hide resolved
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
@pracucci pracucci enabled auto-merge (squash) June 18, 2024 12:12
@pracucci pracucci merged commit 9ef6747 into main Jun 18, 2024
29 checks passed
@pracucci pracucci deleted the fix-query-stats-status-code-on-error branch June 18, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants