fix: report correct status code for metric and log queries in metrics.go - #12102
Conversation
| statResult.Log(level.Debug(spLogger)) | ||
|
|
||
| status, _ := server.ClientHTTPStatusAndError(err) | ||
| status := 200 |
There was a problem hiding this comment.
| status := 200 | |
| status := http.StatusOK |
| status, _ := server.ClientHTTPStatusAndError(err) | ||
| status := 200 | ||
| if err != nil { | ||
| status, _ = server.ClientHTTPStatusAndError(err) |
There was a problem hiding this comment.
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.
yeah, it makes sense to add a check there.
cstyan
left a comment
There was a problem hiding this comment.
@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.gowhich reports query stats is showing incorrect status code for metric and log queries.It is incorrectly reporting successful queries with
500status 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.mdguide (required)CHANGELOG.mdupdatedadd-to-release-noteslabeldocs/sources/setup/upgrade/_index.mdproduction/helm/loki/Chart.yamland updateproduction/helm/loki/CHANGELOG.mdandproduction/helm/loki/README.md. Example PRdeprecated-config.yamlanddeleted-config.yamlfiles respectively in thetools/deprecated-config-checkerdirectory. Example PR