← Back to Pull requests

feat: expose detailedMetric on global rate limit rules #9762

Closed
unknown closed this pull request without merging on Oct 30, 2026 12:06 UTC
View on GitHub
unknown unknown commented on Aug 16, 2026 06:19 UTC
Author

Fixes #9083

What this does

The envoyproxy/ratelimit service supports a detailed_metric flag on rate-limit descriptors that includes the resolved descriptor value in the emitted metrics — so ratelimit_service_rate_limit_ counters become per-value instead of aggregated. Envoy Gateway never surfaced it, so it was always false.

This adds a detailedMetric boolean to global rate-limit rules, mirroring the existing shadowMode field.

spec:
  rateLimit:
    type: Global
    global:
      rules:
      - clientSelectors:
        - headers:
          - name: x-client-id
            type: Distinct
        detailedMetric: true   # <-- new
        limit:
          requests: 10
          unit: Minute

With it enabled, instead of one aggregated series you get one per descriptor value:

ratelimit_service_rate_limit_total_hits{...,key2="rule-0-match-0_1234"} 1
ratelimit_service_rate_limit_total_hits{...,key2="rule-0-match-0_4567"} 4

Design

Mirrors shadowMode exactly through the pipeline:

  • API — api/v1alpha1/ratelimit_types.go: DetailedMetric bool on RateLimitRule

  • IR — internal/ir/xds.go: same field

  • API → IR — internal/gatewayapi/backendtrafficpolicy.go (buildRateLimitRule)

  • IR → RLS config — internal/xds/translator/ratelimit.go: new isRuleDetailedMetric helper sets pbDesc.DetailedMetric on each generated descriptor (same sites as ShadowMode)
  • When unset, existing behavior (aggregated metrics) is preserved. As the issue notes, enabling it can produce high metric cardinality for descriptors with many distinct values — documented in the field godoc.

    Testing

    Generated code (deepcopy, CRDs, API reference docs) was regenerated with the repo's own tooling (controller-gen, crd-ref-docs).

  • New ratelimit-config golden global-detailed-metric asserting detailed_metric in the generated rate-limit service config

  • Extended the gatewayapi backendtrafficpolicy-with-ratelimit fixture to exercise the API→IR conversion
  • go test ./internal/xds/translator/ ./internal/gatewayapi/ ./internal/ir/ ./api/...
    go vet ./internal/xds/translator/ ./internal/gatewayapi/ ./internal/ir/ ./api/...
    

    ---

    This PR was authored with the assistance of Claude, an AI assistant.

    🤖 Generated with Claude Code

    Diff: 304 lines (+228 / -76) across 3 files Reviewer: vishals-3 Review duration: 108347m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 304 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.342
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9762"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%