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: report correct status code for metric and log queries in metrics.go #12102

Merged
merged 5 commits into from
Sep 19, 2024

Conversation

ashwanthgoli
Copy link
Contributor

@ashwanthgoli ashwanthgoli commented Mar 1, 2024

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_* metrics

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@ashwanthgoli ashwanthgoli marked this pull request as ready for review March 1, 2024 06:23
@ashwanthgoli ashwanthgoli requested a review from a team as a code owner March 1, 2024 06:23
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
status := 200
status := http.StatusOK

status, _ := server.ClientHTTPStatusAndError(err)
status := 200
if err != nil {
status, _ = server.ClientHTTPStatusAndError(err)
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

@cstyan cstyan left a 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

@ashwanthgoli ashwanthgoli force-pushed the metrics-go/fix-status branch from 362c5de to 436249e Compare June 25, 2024 06:47
@trevorwhitney trevorwhitney merged commit 900751c into main Sep 19, 2024
60 checks passed
@trevorwhitney trevorwhitney deleted the metrics-go/fix-status branch September 19, 2024 15:42
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.

5 participants