Skip to content

fix: report correct status code for metric and log queries in metrics.go - #12102

Merged
trevorwhitney merged 5 commits into
mainfrom
metrics-go/fix-status
Sep 19, 2024
Merged

fix: report correct status code for metric and log queries in metrics.go#12102
trevorwhitney merged 5 commits into
mainfrom
metrics-go/fix-status

Conversation

@ashwanthgoli

@ashwanthgoli ashwanthgoli commented Mar 1, 2024

Copy link
Copy Markdown
Contributor

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
Comment thread pkg/logql/engine.go Outdated
statResult.Log(level.Debug(spLogger))

status, _ := server.ClientHTTPStatusAndError(err)
status := 200

Copy link
Copy Markdown
Contributor

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
Comment thread pkg/logql/engine.go Outdated
status, _ := server.ClientHTTPStatusAndError(err)
status := 200
if err != nil {
status, _ = server.ClientHTTPStatusAndError(err)

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

@cstyan cstyan left a comment

Copy link
Copy Markdown
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants