Skip to content

fix: ensure delta metric values are never negative#1690

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

fix: ensure delta metric values are never negative#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 the current value, most likely
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

@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

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.98%. Comparing base (59d9c4d) to head (22de71c).

Files with missing lines Patch % Lines
...collector/nginxplusreceiver/record/http_metrics.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1690      +/-   ##
==========================================
- Coverage   84.99%   84.98%   -0.01%     
==========================================
  Files         104      104              
  Lines       13579    13583       +4     
==========================================
+ Hits        11541    11544       +3     
- Misses       1524     1525       +1     
  Partials      514      514              
Files with missing lines Coverage Δ
.../nginxplusreceiver/record/location_zone_metrics.go 100.00% <100.00%> (ø)
...or/nginxplusreceiver/record/server_zone_metrics.go 100.00% <100.00%> (ø)
...collector/nginxplusreceiver/record/http_metrics.go 98.80% <80.00%> (-1.20%) ⬇️

... and 2 files 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...22de71c. Read the comment docs.

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

Comment thread internal/collector/nginxplusreceiver/record/http_metrics.go Outdated
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 the current value, most likely
0, if the delta is negative.
@valyria257 valyria257 force-pushed the nginxaas-1520-non-neg-metrics branch from 377b4f3 to 22de71c Compare May 19, 2026 21:24
@valyria257 valyria257 changed the title fix: clamp negative count metric values to 0 fix: ensure delta metric values are never negative May 19, 2026
}

// increase calculates the delta value (difference) from monotonically increasing counters.
// If the current value is less than previous value, in the case of a rest, we take the current value.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rest to reset

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.

2 participants