← Back to Pull requests

feat(recipe): let components declare the Prometheus metrics they read #3450

Closed
unknown closed this pull request without merging on Oct 28, 2026 14:25 UTC
View on GitHub
unknown unknown commented on Oct 27, 2026 19:21 UTC
Author

Summary

Adds the ADR-026 runtime metrics contract to the registry: a component declares the data it queries from the runtime Prometheus server (telemetry.promql: monitorsFrom + RE2 series), the server declares the value paths the bundler owns (telemetry.promqlServer), and every bundle path (CLI, aicrd, Client.BundleComponents) writes the union of enabled consumers' declarations into the enabled server's values.

Motivation / Context

Implements the PromQL scrape-scope piece of ADR-026 (NKTP telemetry), so the runtime Prometheus scrapes only the namespaces and series its consumers declared.

Fixes: #3443
Related: #3445

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Refactoring (no functional changes)

  • Build/CI/tooling
  • Component(s) Affected

  • CLI (cmd/aicr, pkg/cli)

  • API server (cmd/aicrd, pkg/server)

  • Recipe engine / data (pkg/recipe)

  • Bundler and deployers (pkg/bundler, pkg/component)

  • Collectors / snapshotter (pkg/collector, pkg/snapshotter)

  • Validator (pkg/validator)

  • Core libraries (pkg/errors, pkg/k8s)

  • Docs/examples (docs/, examples/)

  • Other: SDK (pkg/client/v1)
  • Implementation Notes

  • Injected values: namespace selectors naming exactly the monitorsFrom namespaces, monitor selectors matching every monitor (matchExpressions: [], since the chart treats an empty map as unset), and one default scrape class keeping only the declared series.

  • Fails closed with INVALID_REQUEST when a monitorsFrom component is absent or disabled, more than one server is enabled, the server's values already set an owned path, or --set/--set-json/--set-file/--dynamic targets one. A pattern that does not compile, on its own or inside its group, fails the registry load.

  • The platform (not just the filtered bundle) is validated, so a partial bundle still checks the whole platform. With no server enabled, nothing is injected or checked.

  • Monitors from declared sources must not set spec.scrapeClass; the bundler can't check this because operators create some monitors at run time. Documented in recipe-development.md.

  • No registry component declares telemetry yet; this lands the contract and the injection only.
  • Testing

    go test -race ./pkg/recipe/... ./pkg/bundler/... ./pkg/client/v1/... ./pkg/component/...
    golangci-lint run -c .golangci.yaml ./pkg/recipe/... ./pkg/bundler/... ./pkg/client/v1/... ./pkg/component/...
    make qualify
    

  • Tests pass with -race, and lint reports 0 issues. make qualify passes, with 86.2% total coverage against the 83% floor.

  • No bundle output changes: the stock render golden, the BOM, and recipe evidence are unchanged.

  • The tests cover:

  • - each failure mode;
    - each pattern's flags staying in that pattern, so (?i)foo plus BAR doesn't match bar;
    - a pattern with an unterminated \Q, rejected at registry load;
    - monitor selectors written as match-all, with an override of them rejected;
    - --set, --set-json, --set-file, and --dynamic on owned paths rejected;
    - a --split set carrying the scope in the server's class only;
    - identical values from Make and the SDK;
    - a disabled server, which gets nothing injected and nothing checked.
  • Checked by hand against kube-prometheus-stack 84.4.0: {matchExpressions: []} renders as match-all, while an empty map falls back to the chart's release-label selector. A test against the real chart comes with #3445, where kube-prometheus-stack declares the server.
  • | Package | Coverage before | Coverage after |
    |---|---|---|
    | pkg/recipe | 91.1% | 91.2% |
    | pkg/bundler | 88.2% | 88.6% |
    | pkg/client/v1 | 86.6% | 86.6% |
    | pkg/recipe/recipetest (new) | — | 82.8% |

    Risk Assessment

  • Low — Isolated change, well-tested, easy to revert

  • Medium — Touches multiple components or has broader impact

  • High — Breaking change, affects critical paths, or complex rollout
  • Rollout notes: Inert until a registry entry declares telemetry.promqlServer; no existing recipe changes output.

    Checklist

  • Tests pass locally (make test with -race)

  • Linter passes (make lint)

  • I did not skip/disable tests to make CI green

  • I added/updated tests for new functionality

  • I updated docs if user-facing behavior changed

  • Changes follow existing patterns in the codebase

  • Commits are signed off and cryptographically signed (git commit -s -S) — GPG signing info
  • Diff: 600 lines (+450 / -150) across 7 files Reviewer: yuanchen8911 Review duration: 1144m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 600 lines diff across 7 files
    0.50
    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.383
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3450"
    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: 50.1% (MEDIUM) · Higher = larger blast radius
    50.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: 19.8% · Safe to merge
    19.8%
    Repository