Skip to content

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

Open
aryanorastar wants to merge 3 commits into
BasedHardware:mainfrom
aryanorastar:fix/9587-telemetry-contract
Open

test(monitoring): encode prod telemetry target inventory (#9587)#11099
aryanorastar wants to merge 3 commits into
BasedHardware:mainfrom
aryanorastar:fix/9587-telemetry-contract

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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 <cursoragent@cursor.com>
@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

Comment thread backend/tests/unit/test_monitoring_telemetry_contract.py Outdated
Comment thread backend/scripts/select_backend_unit_tests.py Outdated
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 <cursoragent@cursor.com>
@aryanorastar

Copy link
Copy Markdown
Contributor 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
Collaborator

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
Contributor 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
Contributor 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
Collaborator

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
Contributor 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
Contributor 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
Contributor 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge 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.

3 participants