Skip to content

rate_limit: YAML metrics node swaps the metric tag and prefix #13599

Description

@sinhaparth5

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). The YAML path
does not (limiter.h:228):

std::string prefix = metrics["prefix"] ? metrics["prefix"].as<std::string>() : RATE_LIMITER_METRIC_PREFIX;
std::string tag    = metrics["tag"] ? metrics["tag"].as<std::string>() : name();

initializeMetrics(RATE_LIMITER_TYPE_SNI, prefix, tag);

metric_helper() builds the name as prefix + "." + type + "." + tag
(limiter.cc:60-74), so the two halves come out reversed. Every SNI limiter
configured with a metrics node gets the wrong metric name, including when
only one of the two keys is set, because the defaults get swapped along with
them.

Reproduce

selector:
  - sni: example.com
    limit: 100
    metrics:
      prefix: myprefix
      tag: mytag

traffic_ctl metric match rate reports:

mytag.sni.myprefix.queued

instead of myprefix.sni.mytag.queued.

With only tag: mytag set, the name is mytag.sni.plugin.rate_limiter.queued
rather than plugin.rate_limiter.sni.mytag.queued. With only
prefix: myprefix set it is example.com.sni.myprefix.queued rather than
myprefix.sni.example.com.queued.

Present on master (a2011c2), dating to #10559. No autest covers the metric
names, which is why it has gone unnoticed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions