-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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: report correct status code for metric and log queries in metrics.go #12102
Conversation
pkg/logql/engine.go
Outdated
@@ -256,7 +256,10 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) { | |||
statResult := statsCtx.Result(time.Since(start), queueTime, q.resultLength(data)) | |||
statResult.Log(level.Debug(spLogger)) | |||
|
|||
status, _ := server.ClientHTTPStatusAndError(err) | |||
status := 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status := 200 | |
status := http.StatusOK |
pkg/logql/engine.go
Outdated
status, _ := server.ClientHTTPStatusAndError(err) | ||
status := 200 | ||
if err != nil { | ||
status, _ = server.ClientHTTPStatusAndError(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm does it make sense to add the err != nil
check in ClientHTTPStatusAndError()
and return 200 there?
Also, this would benefit from a unit test and I'm not sure how easy it would be to do it here (because of the direct call to RecordRangeAndInstantQueryMetrics()
that I am not sure we can mock), while doing it in the ClientHTTPStatusAndError()
seems much easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it makes sense to add a check there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashwanthgoli bump, I agree with Ned and Sandeep, lets see if moving the check to the server function and be if err == nil
, and then just confirm that the rest of the tests are still green
362c5de
to
436249e
Compare
What this PR does / why we need it:
metrics.go
which reports query stats is showing incorrect status code for metric and log queries.It is incorrectly reporting successful queries with
500
status code.it also affects the status label in some of the
logql_querystats_*
metricsWhich issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Checklist
CONTRIBUTING.md
guide (required)CHANGELOG.md
updatedadd-to-release-notes
labeldocs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PRdeprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR