Skip to content

test(monitoring): encode prod telemetry target inventory (#9587) - #11099

Merged
undivisible merged 6 commits into
BasedHardware:mainfrom
aryanorastar:fix/9587-telemetry-contract
Aug 14, 2026
Merged

undivisible merged 6 commits into
BasedHardware:mainfrom
aryanorastar:fix/9587-telemetry-contract

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Repo-enforceable slice of #9587: declare expected prod scrape targets in backend/charts/monitoring/expected-targets.prod.yaml.
  • Static contract tests assert values/ServiceMonitor wiring, token scrape auth, omi-journey-scrape-missing coverage for enforced jobs, Telegram receiver + instatus_component labels, and scrape-health noDataState.
  • Wire backend/charts/monitoring/** contract sources into unit-test selection so inventory/values drift is caught on PRs.
  • Complements #9138 / #11093 via documented managed-GKE exclusions — does not duplicate control-plane alert disables.
  • Explicitly deferred: live Instatus/Telegram delivery tests, notification-policy rework, expanding scrape-missing to Parakeet/GPU/Stackdriver/ksm, backend-sync Cloud Run scrape path.

Test plan

  • pytest tests/unit/test_monitoring_telemetry_contract.py
  • pytest tests/unit/test_workflow_contracts.py::test_selector_docs_and_flat_utils_do_not_force_full_suite_via_globs
  • Confirm PR CI selects the monitoring contracts when inventory/values change
    Failure-Class: none

…re#9587)

Add a declared expected-targets inventory, static contract tests for scrape
wiring/routing/no-data semantics, and PR CI selector coverage for monitoring
contract sources — without live Grafana or Instatus changes.

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 5 files

Confidence score: 4/5

  • backend/tests/unit/test_monitoring_telemetry_contract.py has two contract-test blind spots: it only checks inventory->scrape existence (not scrape->inventory) and uses a loose substring match for enforced jobs, so undeclared scrape jobs or incorrectly enforced rules can slip through CI and reach production monitoring unnoticed — add the reverse set assertion and assert against the specific rule field/expression structure instead of raw substring presence.
  • backend/scripts/select_backend_unit_tests.py now depends on two separate source tuples for monitoring, which can drift and cause monitoring-related changes to skip the contract tests (or run them unexpectedly), weakening PR safety signals — centralize the paths in a shared MONITORING_CONTRACT_SOURCES constant and reference it from both selection points.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/scripts/select_backend_unit_tests.py">

<violation number="1" location="backend/scripts/select_backend_unit_tests.py:318">
P3: Adding or removing a monitoring source now requires editing two independent tuples; if they drift, a changed file can be ignored or selected without the monitoring tests. A shared `MONITORING_CONTRACT_SOURCES` tuple reused by both branches would keep the selector contract consistent.</violation>
</file>

<file name="backend/tests/unit/test_monitoring_telemetry_contract.py">

<violation number="1" location="backend/tests/unit/test_monitoring_telemetry_contract.py:68">
P2: The existence check is one-directional, so a scrape job added to prod additionalScrapeConfigs without a matching inventory entry passes silently. Add the reverse assertion so added-but-undeclared jobs are caught on PRs, matching the stated drift-detection goal; both sets are currently equal so this stays green.</violation>

<violation number="2" location="backend/tests/unit/test_monitoring_telemetry_contract.py:119">
P3: The enforcement check only asserts the enforced job name appears somewhere in the serialized alert rule (via substring search), so it would still pass if the job name appeared in an annotation or label but was accidentally removed from the `up{job=~"..."}` selector that actually triggers the alert. This is a static string-membership tripwire rather than a check that the job is wired into the query expression, so it can silently miss selector drift. Consider parsing the PromQL expression (e.g. extracting the `up{job=~"..."}` alternation from `data[].model.expr`) and asserting the enforced job is a member of that alternation, or at minimum label this test/assertion explicitly as a static tripwire per AGENTS.md guidance.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

if job.get('coverage_status') != 'enforced':
continue
assert job.get('coverage_alert') == 'omi-journey-scrape-missing'
assert job['name'] in blob, (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The enforcement check only asserts the enforced job name appears somewhere in the serialized alert rule (via substring search), so it would still pass if the job name appeared in an annotation or label but was accidentally removed from the up{job=~"..."} selector that actually triggers the alert. This is a static string-membership tripwire rather than a check that the job is wired into the query expression, so it can silently miss selector drift. Consider parsing the PromQL expression (e.g. extracting the up{job=~"..."} alternation from data[].model.expr) and asserting the enforced job is a member of that alternation, or at minimum label this test/assertion explicitly as a static tripwire per AGENTS.md guidance.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_monitoring_telemetry_contract.py, line 119:

<comment>The enforcement check only asserts the enforced job name appears somewhere in the serialized alert rule (via substring search), so it would still pass if the job name appeared in an annotation or label but was accidentally removed from the `up{job=~"..."}` selector that actually triggers the alert. This is a static string-membership tripwire rather than a check that the job is wired into the query expression, so it can silently miss selector drift. Consider parsing the PromQL expression (e.g. extracting the `up{job=~"..."}` alternation from `data[].model.expr`) and asserting the enforced job is a member of that alternation, or at minimum label this test/assertion explicitly as a static tripwire per AGENTS.md guidance.</comment>

<file context>
@@ -0,0 +1,157 @@
+        if job.get('coverage_status') != 'enforced':
+            continue
+        assert job.get('coverage_alert') == 'omi-journey-scrape-missing'
+        assert job['name'] in blob, (
+            f"enforced job {job['name']!r} must appear in omi-journey-scrape-missing expr"
+        )
</file context>

aryanorastar and others added 2 commits August 5, 2026 00:58
…ardware#9587)

Three real gaps cubic flagged:

- test_additional_scrape_jobs_exist_in_prod_values was one-directional:
  it checked every inventory job exists in prod additionalScrapeConfigs,
  but not the reverse. A job added straight to prod values without a
  matching inventory entry is undeclared monitoring drift and would
  silently pass. Added the reverse assertion.
- test_enforced_coverage_alert_includes_declared_jobs fell back to
  substring-searching json.dumps(scrape_rule) when data[].model.expr
  was empty, so a job name appearing in any unrelated field (uid,
  title, a label) could pass even though the actual alerting
  expression was wrong or missing. Require expr directly and fail
  loudly if extraction failed, instead of silently widening the
  search surface.
- select_backend_unit_tests.py had the same 6-item monitoring source
  tuple duplicated verbatim in AREA_TESTS and in
  is_selectable_backend_path's intentional-exception check — a classic
  copy-paste drift risk (a future maintainer changes one without the
  other, and CI selection silently stops matching the monitoring unit
  contract). Extracted MONITORING_CONTRACT_SOURCES as the single
  source both now reference.

Verified: ran all 11 test_monitoring_telemetry_contract.py assertions
directly against the real prod config files (backend/tests/unit/conftest.py
pulls in google-cloud deps not installed in this sandbox, so bypassed
pytest collection and called each test function directly) — 11/11
pass, including the new stricter reverse/expr checks, confirming no
hidden pre-existing drift in the real inventory/values/alert-rules
files. Sanity-checked is_selectable_backend_path and the AREA_TESTS
monitoring mapping resolve identically after the dedup. black --check
clean on both files.

Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Addressed on `b8078ce5`:

  • One-directional check: added the reverse assertion — a job added straight to prod `additionalScrapeConfigs` without a matching inventory entry is undeclared drift and now fails fast instead of passing silently.
  • Unsafe substring fallback: the enforced-coverage test fell back to substring-searching the whole serialized rule when `expr` was empty, so a job name could match an unrelated field and pass even with a wrong/missing alerting expression. Now requires `expr` directly and fails loudly if extraction failed.
  • Duplicated source tuple: the same 6-item monitoring path list was copy-pasted in two places in `select_backend_unit_tests.py`. Extracted `MONITORING_CONTRACT_SOURCES` as the single source both now reference.

Verified against the real config files, not mocks: ran all 11 assertions in `test_monitoring_telemetry_contract.py` directly (bypassed pytest collection since `conftest.py` pulls in google-cloud deps not available in this sandbox) — 11/11 pass including the new stricter checks, confirming there's no hidden pre-existing drift in the actual inventory/values/alert-rules files that the old one-directional test was missing. Sanity-checked the selector script resolves identically after dedup. `black --check` clean.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior backend Backend Task (python) labels Aug 4, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tightening this after the earlier review. The current code direction looks useful: the inventory is checked both ways against prod additionalScrapeConfigs, the enforced coverage assertion now reads the Grafana expression directly, and the monitoring test-selection paths are centralized.

One blocking item remains before this can merge: the Repo Checks / Hygiene gate is failing on failure-class-protocol because the fix(backend): address cubic review on telemetry contract test (#9587) commit does not include the required Failure-Class: FC-<slug> | new | none declaration. Since this PR changes workflow/test-selection behavior and production monitoring contracts, I’m also leaving it for human maintainer review after CI is green.

Suggested next step: amend the fix commit message/body with the appropriate failure-class declaration (likely Failure-Class: none if this is not tied to an existing/new semantic failure class), then rerun CI.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level the Failure-Class: none declaration is on the current PR body, and Repo Checks / PR Metadata Preflight are green on this head (b8078ce5). Hygiene is skipping (not failing) on the latest run.

Could you dismiss the Changes Requested / re-review when you have a moment? Happy to escalate with need human response if you'd rather a human pass on the monitoring-contract surface.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prod telemetry target inventory test (#9587) is a reasonable contract lock; approving, test-only.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response

The only remaining merge blocker is your stale Changes Requested from the Failure-Class hygiene note. On current head b8078ce5:

  • Failure-Class: none is in the PR body
  • All checks green (Hygiene skipping as intended; PR Metadata Preflight green)
  • @kodjima33 approved (test-only contract lock)

Please dismiss the Changes Requested / re-review so the merge gate can clear. No further author code work pending.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up. I rechecked the current head (b8078ce5) against the earlier automation feedback.

What looks good now:

  • The inventory/prod additionalScrapeConfigs check is now bidirectional, so undeclared prod scrape jobs should fail the contract.
  • The enforced coverage check now reads the Grafana alert expression directly instead of falling back to matching the whole serialized rule.
  • The monitoring test-selection sources are centralized via MONITORING_CONTRACT_SOURCES and select the monitoring contract tests for the relevant chart/alert/inventory paths.
  • Direct execution of the 11 telemetry contract assertions passes locally against the real repo files; the targeted selector check also selects the expected monitoring tests. Full local pytest collection was blocked by missing sandbox deps (google from backend/tests/unit/conftest.py), but the GitHub backend unit suite is green on this head.

I’m not seeing another code-change blocker from this pass. Because this PR changes workflow/test-selection behavior and production monitoring contract coverage, I’m still leaving final merge sign-off to a human maintainer rather than formal automated approval.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response

Merge is still blocked by your earlier Changes Requested from the Failure-Class hygiene note, even though your latest pass on b8078ce5 found no code-change blocker.

Current state:

  • Failure-Class: none is on the PR body; PR Metadata Preflight + Hygiene are green/skipping as intended
  • Bidirectional inventory check, expr-based enforced coverage, and MONITORING_CONTRACT_SOURCES centralization are in
  • CI green; @kodjima33 APPROVED (test-only)

Please dismiss the stale Changes Requested / leave a human APPROVE or clear the gate so this can land. No further author code work pending.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — dismiss stale CR.

Head @b8078ce56b already carries Failure-Class: none + the inventory/expr tightening from your earlier pass. kodjima33 APPROVED. Merge is only blocked by the stale CHANGES_REQUESTED. Could you dismiss / APPROVE?

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level follow-up: PR #11099 is fully CI-green at b8078ce, with @kodjima33 approval. Your latest re-review found no code-change blocker and confirmed the 11 telemetry assertions plus selector coverage. The older CHANGES_REQUESTED review remains the only merge blocker; please dismiss it or leave the formal maintainer approval when ready.

Keep prod telemetry inventory contract tip current for CR dismiss.
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — please dismiss the stale CHANGES_REQUESTED on #11099.

Author-clear:

  • Your later COMMENTED pass on b8078ce56b found no code-change blocker (bidirectional inventory, expr-based coverage, MONITORING_CONTRACT_SOURCES)
  • Failure-Class: none is on the PR body; Metadata Preflight green; Hygiene skip/success on latest Repo Checks
  • @kodjima33 APPROVED (test-only)
  • Tip refreshed onto current main @a5e01b3b1448 — local test_monitoring_telemetry_contract.py 11 passed

Merge is only blocked by the older Failure-Class hygiene CR. Please dismiss it (or leave human APPROVE) when you can.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prod telemetry target inventory contract tests — approve only; the declared prod inventory is not verifiable from the repo.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — please dismiss the stale CHANGES_REQUESTED on #11099.

Author-clear on tip $(git rev-parse --short HEAD) (just refreshed onto current main):

  • Your later COMMENTED pass on b8078ce56b found no code-change blocker (bidirectional inventory, expr-based coverage, MONITORING_CONTRACT_SOURCES)
  • Failure-Class: none is on the PR body; Metadata Preflight green; Hygiene skip/success as intended
  • @kodjima33 APPROVED (test-only; re-approved after tip refresh)
  • Local: test_monitoring_telemetry_contract.py → 11 passed after merge/main

Merge is only blocked by the older Failure-Class hygiene CR from 2026-08-04. Please dismiss it (or leave human APPROVE) so the gate can clear.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Correction: tip is 1778322c45 (merge/main refresh). Please dismiss the stale CHANGES_REQUESTED on that head.

@Git-on-my-level
Git-on-my-level dismissed their stale review August 8, 2026 19:26

Resolved on current head: failure-class / hygiene gate is now green, and the later automation pass plus current checks found no remaining code blocker.

@Git-on-my-level Git-on-my-level removed needs-maintainer-review Needs a human maintainer to sign off before merge workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior labels Aug 8, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 need human response — merge when ready on #11099.

Author-clear on tip 10e3dc7c0115 (refreshed onto current main):

  • Your APPROVE stands (test-only contract lock; re-approved after prior tip refresh)
  • @Git-on-my-level stale Failure-Class CR dismissed 20h ago; workflow/needs-maintainer labels removed
  • Local: test_monitoring_telemetry_contract.py → 11 passed after main refresh
  • MERGEABLE CLEAN · Failure-Class: none

Please merge when you can (or @beastoin if you want a second glance at the declared prod inventory vs live).

@Git-on-my-level Git-on-my-level added the positive-signal Automation verified a genuine fix/quality contribution label Aug 9, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for keeping this tight and for addressing the earlier contract-test feedback. I rechecked the current head and this looks like a useful monitoring-contract lock; leaving this as a positive maintainer signal rather than formal approval because the PR is in the prod monitoring/workflow surface and already has human approval.

Specific review notes:

  • backend/charts/monitoring/README.md accurately scopes the new inventory as CI-enforced repo metadata and explicitly defers live Instatus delivery / notification-policy work instead of over-claiming production verification.
  • backend/charts/monitoring/expected-targets.prod.yaml matches the prod additionalScrapeConfigs job set I checked locally, separates enforced coverage from declared-only gaps, and documents the managed GKE control-plane exclusions without changing alert behavior.
  • backend/tests/unit/test_monitoring_telemetry_contract.py now checks both inventory→values and values→inventory drift, verifies metrics-scrape-token usage for token-protected jobs, reads the actual omi-journey-scrape-missing Grafana expression, and keeps declared-only jobs from claiming coverage alerts prematurely.
  • backend/scripts/select_backend_unit_tests.py centralizes the monitoring source paths in MONITORING_CONTRACT_SOURCES, so the selector mapping and selectable-path exception should not drift independently.
  • backend/tests/unit/test_workflow_contracts.py covers the monitoring chart path-selection exception while keeping docs/AGENTS paths ignored and preserving the full-suite fallback for unmapped runtime files.

Validation: repo CI is green in the supplied context. In this sandbox, direct pytest collection is blocked by missing google dependencies in backend/tests/unit/conftest.py, so I also ran a no-secret static check over the real inventory/values/alert-rules files and confirmed the declared/configured scrape-job sets match, enforced jobs are present in the alert expression, and receiver/Instatus labels are valid.

No code-change blocker found from this pass; leaving for human maintainer review/merge because this touches prod monitoring contracts and workflow test selection.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 need human response — merge when ready on #11099 / #9587.

Author-clear on 10e3dc7c01:

  • APPROVED (yours, test-only) + MERGEABLE CLEAN + all checks green
  • David dismissed the stale Failure-Class CR; positive-signal; workflow/needs-maintainer labels removed
  • Bidirectional inventory, expr-based scrape-missing coverage, MONITORING_CONTRACT_SOURCES centralization unchanged

Please merge when you can.

@undivisible undivisible added human Human-authored pull request workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior docs-tooling Layer: Documentation, examples, dev tools labels Aug 10, 2026
@Git-on-my-level Git-on-my-level removed the docs-tooling Layer: Documentation, examples, dev tools label Aug 10, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 merge-gate ping: current head is APPROVED, MERGEABLE/CLEAN, and CI is green. No author-side blocker remains; please merge or state an explicit hold.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the follow-up. I rechecked this head against the previous automation feedback and the current diff looks like a solid static contract slice rather than a runtime monitoring change.

What I verified:

  • backend/charts/monitoring/expected-targets.prod.yaml now declares the prod scrape inventory, routing label set, no-data semantics, and managed-GKE exclusions explicitly. The declared-only vs enforced distinction is clear, and it does not claim Phase 2 Instatus/notification-policy coverage.
  • backend/tests/unit/test_monitoring_telemetry_contract.py cross-checks that inventory against prod additionalScrapeConfigs in both directions, verifies token-backed scrapes use the metrics-scrape token, checks kube-state-metrics/parakeet/Stackdriver presence, and reads the actual omi-journey-scrape-missing Grafana expression for enforced coverage.
  • backend/scripts/select_backend_unit_tests.py centralizes the monitoring contract source paths in MONITORING_CONTRACT_SOURCES, and the chart-path exception is narrow enough to keep unrelated chart/docs changes from forcing broad backend selection.
  • backend/tests/unit/test_workflow_contracts.py updates the selector contract so monitoring alert JSON changes select the monitoring contract tests instead of being ignored as chart artifacts.
  • backend/charts/monitoring/README.md accurately describes what is enforced now and what remains deferred.

Validation run locally:

  • python -m pytest tests/unit/test_monitoring_telemetry_contract.py tests/unit/test_workflow_contracts.py::test_selector_docs_and_flat_utils_do_not_force_full_suite_via_globs -q → 12 passed.

I do not see a blocking production-code issue in this PR. Keeping this as a positive signal rather than formal automation approval because it touches workflow-sensitive test selection / monitoring contract behavior and is tied to the larger #9587 sequence; final merge decision should stay with maintainers for that scope.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 @beastoin final merge-gate ping: #11099 is APPROVED, MERGEABLE/CLEAN, conflict-free, and all checks passed. The monitoring inventory contract has a positive maintainer signal and no author-side blocker. Please merge or state an explicit hold.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 merge ping: still APPROVED and MERGEABLE. Author-side is clear.

@undivisible
undivisible merged commit eb90b61 into BasedHardware:main Aug 14, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) human Human-authored pull request positive-signal Automation verified a genuine fix/quality contribution workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants