Skip to content

fix: clamp negative count metric values to 0#1690

Open
valyria257 wants to merge 2 commits into
nginx:mainfrom
valyria257:nginxaas-1520-non-neg-metrics
Open

fix: clamp negative count metric values to 0#1690
valyria257 wants to merge 2 commits into
nginx:mainfrom
valyria257:nginxaas-1520-non-neg-metrics

Conversation

@valyria257
Copy link
Copy Markdown
Collaborator

@valyria257 valyria257 commented May 18, 2026

Proposed changes

If nginx reset the values of the counters used for these metric values,
then the gauge values will be negative because they are calculated
based on the current value minus the previous value.

Since these gauges are tracking counts, it doesn't make sense for them
to be negative. The current value should always be greater than the
previous because it is based on a counter, unless it's been reset to 0.

Thus, this will set the gauge values to 0 if the delta is negative.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • I have run make install-tools and have attached any dependency changes to this pull request
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes
  • If applicable, I have updated any relevant documentation (README.md)
  • If applicable, I have tested my cross-platform changes on Ubuntu 22, Redhat 8, SUSE 15 and FreeBSD 13

If nginx reset the values of the counters used for these metric values,
then the gauge values will be negative because they are calculated
based on the current value minus the previous value.

Since these gauges are tracking counts, it doesn't make sense for them
to be negative. The current value should always be greater than the
previous because it is based on a counter, unless it's been reset to 0.

Thus, this will set the gauge values to 0 if the delta is negative.
@valyria257 valyria257 requested a review from a team as a code owner May 18, 2026 23:12
@github-actions github-actions Bot added bug Something isn't working chore Pull requests for routine tasks dependencies labels May 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.00%. Comparing base (59d9c4d) to head (377b4f3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1690      +/-   ##
==========================================
+ Coverage   84.99%   85.00%   +0.01%     
==========================================
  Files         104      104              
  Lines       13579    13579              
==========================================
+ Hits        11541    11543       +2     
+ Misses       1524     1522       -2     
  Partials      514      514              
Files with missing lines Coverage Δ
...collector/nginxplusreceiver/record/http_metrics.go 100.00% <100.00%> (ø)
.../nginxplusreceiver/record/location_zone_metrics.go 100.00% <100.00%> (ø)
...or/nginxplusreceiver/record/server_zone_metrics.go 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59d9c4d...377b4f3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working chore Pull requests for routine tasks dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant