Skip to content

fix(monitoring): accept the Cloud Run metrics egress filter at Cloud Monitoring - #12099

Merged
Git-on-my-level merged 2 commits into
mainfrom
fix/cloud-run-metrics-exporter-filter
Aug 23, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
fix/cloud-run-metrics-exporter-filter

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Summary

The Cloud Run metrics egress bridge added in #11998 has never imported a single series. The dedicated Stackdriver exporter is deployed and healthy in dev, its Prometheus target is up, and every one of its Cloud Monitoring queries returns HTTP 400. This makes the filter acceptable to Cloud Monitoring, and adds the alert that would have caught it on day one.

Cloud Monitoring rejects a filter that mixes AND with OR across resource.labels restrictions:

googleapi: Error 400: Field filter had an invalid value of
"metric.type="prometheus.googleapis.com/omi_client_journey_terminal_total/counter" AND
 (resource.labels.cluster="__run__" AND (resource.labels.namespace="backend" OR
  resource.labels.namespace="desktop-backend"))":
AND and OR cannot be mixed for 'resource.labels' restrictions., badRequest

The disjunction is now expressed as one_of("backend","desktop-backend"), which the filter grammar defines for exactly this case. The namespace scope is kept: dropping it would import every omi_* series from every Cloud Run service and job in the project, not just backend and desktop-backend.

Why nothing caught this

The exporter answers the 400 per descriptor and stays Available. Its Prometheus target stays up. The deploy workflow verifies Helm status, Deployment rollout, and Service existence. The one ingestion alert counts Stackdriver-mangled names, and a bridge that imports nothing produces no mangled names, so it sits green. The runbook's own verification step queried the mangled form, which returns zero on a healthy deployment — the check was inverted.

Every signal in the path was scoped to the relay process rather than to its cargo, so 100% query failure rendered as an empty Grafana panel, which reads as no traffic.

Changes

  • dev_omi_cloud_run_metrics_exporter.yaml, prod_omi_cloud_run_metrics_exporter.yaml: one_of(...) filter.
  • New alert omi-cloud-run-metrics-egress-query-rejected — fires on stackdriver_monitoring_last_scrape_error > 0 for the egress job for 15m. This is the signal that was missing; it would have fired 15 minutes after feat(monitoring): ingest Cloud Run application metrics #11998 rolled out.
  • test_monitoring_telemetry_contract.py: the exporter contract now covers both environments (the dev file was entirely unasserted, and dev is what the automatic post-merge rollout installs), pins the corrected filter, and adds a narrow static tripwire for the mixed AND/OR shape. The tripwire is deliberately not called a grammar check: it does not parse the filter language and does not call Cloud Monitoring.
  • Runbook: verification step 6 now requires stackdriver_monitoring_last_scrape_error == 0 and a non-zero count of plain omi_* names, and states why up is not proof.

Live evidence

Gathered against based-hardware-dev and based-hardware before this change:

Signal Value
dev-omi-cloud-run-metrics-exporter Deployment 1/1 Available, 21h
up{job="cloud-run-application-metrics"} 1
stackdriver_monitoring_api_calls_total on that job 54112
stackdriver_monitoring_last_scrape_error on that job 1
omi_* series on that job 0

Candidate filters tested directly against the Cloud Monitoring v3 timeSeries API, 20m window, view=HEADERS:

Filter Result
current, AND + OR mixed HTTP 400
... AND resource.labels.namespace=one_of("backend","desktop-backend") 200, 450 timeSeries
... AND resource.labels.cluster="__run__" only 200, 450 timeSeries
metric.type only, no resource restriction 200, 450 timeSeries

Returned series carry resource.type=prometheus_target, resource.labels{cluster="__run__", namespace="backend", job="omi-cloud-run-application-metrics"} and metric.labels{journey, outcome, service_name, client_kind} — confirming the stackdriver_prometheus_target_prometheus_googleapis_com_ prefix the scrape job's rewrite regex expects.

Product invariants affected

  • INV-DATA-1

The routing guard change touches no serving authority. It widens nothing about where any client is routed: it replaces one over-specific literal in an exemption marker (resource.labels.namespace="desktop-backend") with the monitored-resource literal that actually identifies Cloud Run (resource.labels.cluster="__run__"), so a read-only metrics reader stops being classified as retired GKE desktop-backend ownership. Every production-family routing pin, and the retired-GKE rule itself, is unchanged; test_current_config_is_pinned still validates the live tree, and all 12 guard tests pass.

Verification

  • test_monitoring_telemetry_contract.py, test_monitoring_alert_rule_contract.py, test_journey_observability.py, test_cloud_run_metrics_egress_workflow.py: 53 passed
  • Negative proof: restoring the original filter fails both the exact-string assertion and the tripwire, the latter naming the cause.
  • black --line-length=120 --skip-string-normalization: unchanged. ruff --target-version py39: clean.
  • alert-rules.json verified structurally, not by reading the diff: 72 → 73 rules, exactly one uid added, zero pre-existing rules altered, order preserved, and the split source in alerts/cloud-run-ingestion.json byte-identical to the combined entry.

Not in this PR

  • The new alert rule is added to the repo mirror. Per backend/charts/monitoring/README.md, prod is the live source, so merging this does not make the rule fire; it is provisioned separately.
  • Prod has never served a sidecar revision (backend-465cd0f-32620507075-1 went Ready then retired at 0% traffic), so prod Cloud Monitoring has no omi_* descriptors at all yet. That is a rollout state, not a defect, and it is unblocked by the normal deploy workflows.

Review

Diagnosis, the one_of() repair, the rewrite regex, the rollout sequence, and the failure-class choice were independently reviewed by GPT-5.6 (codex) against this checkout. Its corrections are folded in: the tripwire test was renamed to stop overclaiming, the runbook query was inverted back, the egress-error alert was added, and the plan to hand-promote the retired prod revision was dropped in favour of the deploy workflows, which already do candidate → validate → promote → verify → roll back.

Failure-Class: new

Review in cubic

r added 2 commits August 23, 2026 13:42
…Monitoring

The dedicated Stackdriver exporter added in #11998 has never imported a
single series. Cloud Monitoring rejects a filter that mixes AND with OR
across resource.labels restrictions, so every descriptor query returned
HTTP 400 while the exporter stayed Available, its Prometheus target
stayed up, and Grafana showed empty panels that read as no traffic.

Express the namespace disjunction as one_of(...), which the filter
grammar defines for this case. Keep the namespace scope: dropping it
would import every omi_ series from every Cloud Run service in the
project.

Add omi-cloud-run-metrics-egress-query-rejected, alerting on the
exporter's own upstream error rather than on its liveness. Extend the
exporter contract test to cover the dev values file, which was
unasserted and is what the automatic post-merge rollout installs.
Correct the runbook's verification step, which queried the mangled
metric name that a healthy deployment no longer produces.
…d resource

The production-data-plane-routing guard exempts the Stackdriver egress
values files from its retired-GKE-desktop-backend rule only when they
contain the literal resource.labels.namespace="desktop-backend". That
pins the exemption to one spelling of a filter rather than to what makes
the file a Cloud Run observer, so rewriting the disjunction as one_of(...)
to satisfy Cloud Monitoring's grammar made a read-only metrics reader
look like retired GKE ownership.

Key the exemption on resource.labels.cluster="__run__" instead. That is
Cloud Run's reserved pseudo-cluster, so together with the
prometheus.googleapis.com/ prefix it identifies the monitored resource
directly and survives any future edit to the namespace set.
@Git-on-my-level
Git-on-my-level merged commit bdf68d5 into main Aug 23, 2026
40 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/cloud-run-metrics-exporter-filter branch August 23, 2026 17:56
formed2forge pushed a commit to formed2forge/omi that referenced this pull request Aug 24, 2026
…Monitoring (BasedHardware#12099)

* fix(monitoring): accept the Cloud Run metrics egress filter at Cloud Monitoring

The dedicated Stackdriver exporter added in BasedHardware#11998 has never imported a
single series. Cloud Monitoring rejects a filter that mixes AND with OR
across resource.labels restrictions, so every descriptor query returned
HTTP 400 while the exporter stayed Available, its Prometheus target
stayed up, and Grafana showed empty panels that read as no traffic.

Express the namespace disjunction as one_of(...), which the filter
grammar defines for this case. Keep the namespace scope: dropping it
would import every omi_ series from every Cloud Run service in the
project.

Add omi-cloud-run-metrics-egress-query-rejected, alerting on the
exporter's own upstream error rather than on its liveness. Extend the
exporter contract test to cover the dev values file, which was
unasserted and is what the automatic post-merge rollout installs.
Correct the runbook's verification step, which queried the mangled
metric name that a healthy deployment no longer produces.

* fix(monitoring): key the Cloud Run observer exemption on the monitored resource

The production-data-plane-routing guard exempts the Stackdriver egress
values files from its retired-GKE-desktop-backend rule only when they
contain the literal resource.labels.namespace="desktop-backend". That
pins the exemption to one spelling of a filter rather than to what makes
the file a Cloud Run observer, so rewriting the disjunction as one_of(...)
to satisfy Cloud Monitoring's grammar made a read-only metrics reader
look like retired GKE ownership.

Key the exemption on resource.labels.cluster="__run__" instead. That is
Cloud Run's reserved pseudo-cluster, so together with the
prometheus.googleapis.com/ prefix it identifies the monitored resource
directly and survives any future edit to the namespace set.

---------

Co-authored-by: r <r@r>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant