rate_limit: don't update metrics when a selector has no metrics: block#13343
Open
moonchen wants to merge 1 commit into
Open
rate_limit: don't update metrics when a selector has no metrics: block#13343moonchen wants to merge 1 commit into
moonchen wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a subtle metrics mis-accounting issue in the experimental rate_limit plugin by ensuring the RateLimiter’s metric ID array starts in an explicit “not registered” state, making metric increments a no-op unless metrics are configured and registered.
Changes:
- Initialize
RateLimiter::_metricstoTS_ERRORin the default constructor via_metrics.fill(TS_ERROR). - Add an explanatory comment documenting why
TS_ERRORis required to avoid silently incrementing metric id0when selectors omit ametrics:block.
A selector configured without a `metrics:` block should be a metrics no-op. It isn't: _metrics is value-initialized to 0, but incrementMetric() only suppresses the update when an entry equals the TS_ERROR (-1) sentinel that metric_helper() uses for "not registered". So the guard never fires and every queue/reject/expire/resume calls TSStatIntIncrement() on an unregistered ID. (It currently lands on the reserved bad_id slot, so it is absorbed rather than fatal -- but the plugin still should not emit anything.) Default _metrics to TS_ERROR in the constructor so incrementMetric() stays a no-op until metrics are actually registered. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6e3aa18 to
9fa7af3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A rate_limit selector configured without a
metrics:block should be a metrics no-op. It isn't._metricsis value-initialized to0, butincrementMetric()only suppresses the update when an entry equals theTS_ERROR(−1) sentinel thatmetric_helper()uses for "not registered":_metricsis only populated byinitializeMetrics(), whichparseYaml()calls only when a selector has ametrics:block. Without that block the guard never fires, so every queue/reject/expire/resume (sni_limiter.cc,sni_selector.cc,txn_limiter.cc) callsTSStatIntIncrement()on an unregistered ID. It currently lands on the reservedproxy.process.api.metrics.bad_idslot (id 0), so it's absorbed rather than fatal — but the plugin still shouldn't be emitting anything.Fix
Default
_metricstoTS_ERRORin the constructor — the same "not registered" markermetric_helper()writes per element — soincrementMetric()stays a no-op until metrics are actually registered.Testing
The equivalent fix was validated under AddressSanitizer on a 10.x branch. Not built against
masterlocally — relying on CI for the compile.