Skip to content

fix(prometheus): avoid replaying stream bandwidth after baseline loss - #14279

Open
Zi-Yi-Ming wants to merge 1 commit into
apache:masterfrom
Zi-Yi-Ming:fix/stream-bandwidth-baseline
Open

Zi-Yi-Ming wants to merge 1 commit into
apache:masterfrom
Zi-Yi-Ming:fix/stream-bandwidth-baseline

Conversation

@Zi-Yi-Ming

Copy link
Copy Markdown

Description

A missing publication baseline can mean a new stream metrics slot or a slot whose Prometheus counter survived eviction of its baseline. Starting from zero in the latter case adds bytes that the counter has already recorded.

When the baseline is missing, check whether the counter still exists. A surviving counter resumes from the next recorded zone total. A new slot, or an emptied metric dictionary, starts from zero. The exporter uses non-evicting writes for the publication lock and baselines, and flushes buffered increments before releasing the lock so the next publisher can see the counters.

The regression deletes a baseline twice while retaining the counter. It checks that both scrapes keep the same count and that the next session adds five bytes. The stream metrics suite also covers the first bytes of a new slot and a full dictionary reset.

Which issue(s) this PR fixes:

Fixes #14103.

Validation

Used a dedicated test etcd and the CI-pinned Test::Nginx checkout.

FLUSH_ETCD=1 TEST_NGINX_BINARY="$(command -v openresty)" \
  prove --timer -v -I/opt/test-nginx/lib -I. \
  t/stream-plugin/prometheus-metrics-service.t t/stream-plugin/prometheus-metrics.t
LC_ALL=C.UTF-8 make lint
git diff --check
  • The two stream suites passed all 109 TAP assertions. Before the fix, the updated regression failed because both baseline deletions increased the counter.
  • A local probe filled an OpenResty shared dictionary and confirmed that a failed baseline write left the counter intact. Releasing space let the exporter restore the baseline without changing the counter.
  • The full lint target passed in a temporary copy containing the patch.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Recover a lost publication baseline from the current zone total when the matching counter survives. Count new slots from zero and keep baseline writes from evicting metrics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: stream bandwidth counts old traffic again when its baseline is lost

1 participant