← Back to Pull requests

feat: metrics middleware for http handlers in admin api #7229

Closed
unknown closed this pull request without merging on Sep 30, 2026 15:37 UTC
View on GitHub
unknown unknown commented on Sep 28, 2026 19:57 UTC
Author

https://redhat.atlassian.net/browse/ARO-29406

What

This adds the counter admin_http_requests_total and the histogram admin_http_requests_duration_seconds to the admin api HTTP handlers. The implementation mirrors that of the frontend api.

Why

The admin api currently does not have any metrics for HTTP handlers. Having these metrics metrics makes dashboards and alerting at the handler level possible for an externally facing api.

Testing

Unit tests added for the metrics middleware.

Integration tests passing.

Ran the e2e serial console log test against personal dev environment:

  Will run 1 of 1 specs
  ------------------------------
  SRE should be able to retrieve serial console logs for a VM [PreLaunchSetup:None, Importance:Medium, Positivity:Positive, Core-Infra-Service, Development-Only, ARO-HCP-RP-API-Compatible, MIContainers:1]
  /home/cplace/code/ARO-29406/ARO-HCP/aro-29406-admin-api-metrics/test/e2e/admin_api.go:254
  "ts"="2026-09-28 11:10:10.734553" "level"=0 "msg"="===== TEST CASE BEGAN ====="
    STEP: creating a resource group @ 09/28/26 11:10:10.734
  "ts"="2026-09-28 11:10:10.734648" "level"=0 "msg"="creating resource group" "resourceGroup"="admin-api-serialconsole-mhtgpj2twc8x"
    STEP: creating cluster parameters @ 09/28/26 11:10:14.258
    STEP: creating customer resources @ 09/28/26 11:10:19.985
    STEP: creating the HCP cluster @ 09/28/26 11:11:19.519
  "ts"="2026-09-28 11:11:19.519853" "level"=0 "msg"="Starting HCP cluster creation" "clusterName"="sre-hcp-cluster-sc" "resourceGroup"="admin-api-serialconsole-mhtgpj2twc8x" "version"="4.20" "channelGroup"="candidate"
h    STEP: creating a nodepool to provision worker VMs @ 09/28/26 11:21:46.343
  VM size selection for selector "default-worker" in westus3:
    preferred candidate "Standard_D8s_v3": available/usable
    preferred candidate "Standard_D8s_v5": available/usable
    preferred candidate "Standard_D8as_v5": available/usable
    preferred candidate "Standard_D8s_v6": available/usable
    817 SKU(s) passed Azure checks but excluded by RP allowlist
    -> selected VM size "Standard_D8s_v3" (preferred)
    STEP: resolving current Azure identity @ 09/28/26 11:29:13.836
    STEP: getting VM name from managed resource group @ 09/28/26 11:29:14.689
    STEP: retrieving serial console logs for VM g1a2t2z2s9u6g5l-worker-lssw7-bvv8p @ 09/28/26 11:29:15.377
    STEP: reaching out to the admin API to retrieve serial console logs for VM g1a2t2z2s9u6g5l-worker-lssw7-bvv8p @ 09/28/26 11:29:15.377
    STEP: verifying serial console logs contain boot information @ 09/28/26 11:29:16.474
    STEP: testing error case: non-existent VM name @ 09/28/26 11:29:16.474
    STEP: reaching out to the admin API to retrieve serial console logs for VM non-existent-vm-12345 @ 09/28/26 11:29:16.474
    STEP: testing error case: invalid VM name format @ 09/28/26 11:29:17.028
    STEP: reaching out to the admin API to retrieve serial console logs for VM -invalid-vm-name @ 09/28/26 11:29:17.028
    STEP: testing error case: empty VM name @ 09/28/26 11:29:17.17
    STEP: reaching out to the admin API to retrieve serial console logs for VM  @ 09/28/26 11:29:17.17
  "ts"="2026-09-28 11:29:17.303111" "level"=0 "msg"="===== TEST CASE ENDED: SUCCESS ====="

Verified the metrics endpoint via Grafana, which shows routes/codes expected from manual testing and e2e test execution:
<img width="1373" height="963" alt="image" src="https://github.com/user-attachments/assets/b833a579-eff5-4887-a349-15f4cd5cb4af" />

The 401 <no match> entries were confirmed to be random /mcp traffic, and 401 <no match> is the expected behavior for these requests:

│ {"time":"2026-09-28T18:43:46.516847826Z","level":"INFO","msg":"Got request.","path":"/mcp","method":"post"}                                               │
│ {"time":"2026-09-28T18:43:46.516869659Z","level":"INFO","msg":"Geneva Action client principal headers","path":"/mcp","method":"post","headers":""}        │
│ {"time":"2026-09-28T18:43:46.516895372Z","level":"INFO","msg":"Completed request.","path":"/mcp","method":"post","duration":"71.606µs"}                   │
│ {"time":"2026-09-28T18:43:57.203775302Z","level":"INFO","msg":"Got request.","path":"/mcp","method":"post"}                                               │
│ {"time":"2026-09-28T18:43:57.203800067Z","level":"INFO","msg":"Geneva Action client principal headers","path":"/mcp","method":"post","headers":""}        │
│ {"time":"2026-09-28T18:43:57.203832745Z","level":"INFO","msg":"Completed request.","path":"/mcp","method":"post","duration":"81.949µs"}                   │

PR Checklist

  • PR is scoped to a single task (no mixed concerns)

  • Title follows Conventional Commits format

  • Summary explains the "Why" behind the change

  • Linked to relevant ticket/issue

  • Screenshots included (if dashboards or other UI changes)

  • Self-reviewed the diff

  • CI/CD checks are passing (ignore Tide)

  • Draft PR used for WIP (if applicable)

  • Commit history is clean (rebased/squashed)

  • Tricky code blocks are commented

  • Specific reviewers tagged

  • All comment threads resolved before merge
  • If E2E tests are included:

  • E2E tests follow Principles of Good E2E Test Case Design

  • If new E2E use case is covered (via a new test or new check/verifier),

  • demonstrate that the test is able to detect a defect/error and fail with
    proper error message and logs which communicates nature of the problem.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: garrickdabbs Review duration: 2620m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #7229"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%
    Repository