Skip to content

rate_limit: fix swapped metric tag and prefix in YAML configs - #13601

Open
sinhaparth5 wants to merge 1 commit into
apache:masterfrom
sinhaparth5:fix-rate-limit-metric-tag-prefix
Open

rate_limit: fix swapped metric tag and prefix in YAML configs#13601
sinhaparth5 wants to merge 1 commit into
apache:masterfrom
sinhaparth5:fix-rate-limit-metric-tag-prefix

Conversation

@sinhaparth5

Copy link
Copy Markdown

RateLimiter::initializeMetrics() takes the tag before the prefix:

void initializeMetrics(uint type, std::string tag, std::string prefix = RATE_LIMITER_METRIC_PREFIX)

The remap path passes them in that order (txn_limiter.cc:182), but the YAML
path passed (prefix, tag). metric_helper() builds the name as
prefix + "." + type + "." + tag, so every SNI limiter with a metrics node
came out as tag.sni.prefix.

This affects a metrics node even when only one of the two keys is set, since
the unset one takes its default and the two get swapped together.

Testing

New autest rate_limit_metric_names covers all three shapes: both keys set,
only tag set, and only prefix set.

Run against the plugin built without this change, traffic_ctl metric match
reports the reversed names, which is what the test now pins:

onlytag.sni.plugin.rate_limiter.queued          (expected plugin.rate_limiter.sni.onlytag.queued)
prefixonly.example.com.sni.onlyprefix.queued    (expected onlyprefix.sni.prefixonly.example.com.queued)

All 7 rate_limit autests pass with the change.

Fixes: #13599

initializeMetrics() takes the tag before the prefix, and the remap path
passes them in that order, but the YAML path had them reversed. Every SNI
limiter with a metrics node was named tag.sni.prefix instead of
prefix.sni.tag, including when only one of the keys was set and the other
came from its default.

Fixes: apache#13599

Copilot AI 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.

Pull request overview

Fixes rate_limit YAML metrics naming by correcting the argument order passed to RateLimiter::initializeMetrics() so metrics are consistently generated as prefix.type.tag (matching the remap path and the metric helper’s concatenation order).

Changes:

  • Fix swapped (prefix, tag)(tag, prefix) when initializing metrics for YAML-defined SNI limiters.
  • Improve the related debug log line to label prefix and tag explicitly.
  • Add a new gold test that asserts correct metric names for YAML configurations with: both keys set, only tag set, and only prefix set.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
plugins/experimental/rate_limit/limiter.h Corrects YAML metrics initialization to pass (tag, prefix) into initializeMetrics() so metric names are built in the intended order.
tests/gold_tests/pluginTest/rate_limit/rate_limit_metric_names.test.py Adds an autest that validates metric naming for all relevant YAML metrics node shapes and guards against regressions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

rate_limit: YAML metrics node swaps the metric tag and prefix

2 participants