Skip to content

feat(monitoring): scrape the gateway database and alert on its size - #5048

Merged
dan-petty merged 2 commits into
mainfrom
feat/4994-gateway-database-observability
Nov 12, 2026
Merged

dan-petty merged 2 commits into
mainfrom
feat/4994-gateway-database-observability

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The gateway refuses each virtual key while its database is down, and nothing measured that database. PodMonitor llm-gateway-db brings the series of its CloudNativePG exporter, and the database perimeter and the egress of monitoring admit TCP 9187. Group llm-gateway-db warns when the exporter is down, when the client connections pass 80% of max_connections, and when the databases and the WAL pass 80% of the 5Gi claim, each rule with promtool cases. Grafana provisions the upstream CloudNativePG dashboard for both CloudNativePG Clusters, and the unused copy of the chart in cnpg-system turns off. The gateway deletes spend logs older than 30 days. The dashboard linter reads a target of the expression datasource by its expression, so the upstream dashboard lints clean.

Closes #4994

Change: openspec/changes/archive/2026-11-12-4994-scrape-the-gateway-database-and-alert/

The gateway refuses each virtual key while its database is down, and nothing measured the
database. PodMonitor llm-gateway-db brings the series of its CloudNativePG exporter, and the
database perimeter and the monitoring egress admit TCP 9187. Group llm-gateway-db warns when the
exporter is down, when the connections pass 80% of max_connections, and when the databases and
the WAL pass 80% of the 5Gi claim, each with promtool cases. Grafana provisions the upstream
CloudNativePG dashboard for both CloudNativePG Clusters, and the chart's unused copy in
cnpg-system turns off. The gateway deletes spend logs older than 30 days.

The dashboard linter reads a target of the expression datasource by its expression, so the
upstream dashboard lints clean.

Refs #4994
@dan-petty dan-petty added type/feature Type feature: a new function scope/monitoring Grafana, Prometheus, Loki, alerts and dashboards labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Evidence for this pull request.

Fail-to-pass (uv run devops ci fail-to-pass --base origin/main, run on the head before the archive commit):

  • 7 tests fail on the base and pass on the head: test_an_expression_target_is_checked_by_its_expression[filled], test_cloudnative_pg_values, test_the_gateway_database_rules_watch_the_exporter_the_connections_and_the_claim, test_the_baseline_rule_set, test_the_promtool_files_of_a_group_test_every_alert_of_the_group[llm-gateway-db], test_each_unit_tested_rule_fires_on_a_sample_and_stays_quiet_on_a_normal_series[llm_gateway_db_tests], test_the_generator_provisions_all_dashboards_under_todays_configmap_names.
  • k8s gate row: 4 of 109 cases fail on the base, 0 of 109 on the head (check_the_gateway_keeps_its_spend_logs_for_30_days, check_alloy_scrapes_the_exporter_of_the_database_through_a_pod_monitor, check_only_the_gateway_reaches_the_database_and_the_database_calls_only_dns_and_the_api, check_argo_cd_and_deploy_stack_both_apply_the_database_and_the_operator_comes_first).

Local checks on the head (scoped, the host is loaded):

  • uv run devops ci --check --only lint,format,docs,constructs,openspec,test-tree: pass.
  • uv run devops ci --check --only k8s: 109 cases, 0 failed.
  • pytest, 0 failed: tests/prometheus/test_k8s_monitoring_alerting.py (with promtool 3.15.1), tests/prometheus/test_k8s_monitoring_dashboards.py, tests/prometheus/test_dashboard_queries.py, tests/grafana/test_grafana_dashboards.py, tests/commands/test_grafana.py, tests/commands/k8s/test_stack_dashboards.py, tests/commands/k8s/test_k8s_mattermost.py, tests/commands/k8s/test_k8s.py, tests/invariants/test_k8s_*.py, tests/telemetry/test_telemetry_instruments.py and the other tests that read the changed files.
  • uv run mypy on the changed modules: no issues.
  • uv run devops grafana dashboards lint k8s/monitoring/dashboards: 16 dashboards, 0 errors.
  • The PodMonitor validates against the monitoring.coreos.com/v1 PodMonitor JSON schema of the CRDs catalog. The local kubeconform is a stub script (see fix(tests): test helpers write to the real home outside pytest #4739), so CI runs kubeconform.

Cluster facts (read only): CloudNativePG 1.30.1 (chart 0.29.1); LiteLLM v1.103.10; pod llm-gateway-db-1 has container port metrics 9187; Prometheus has the five cnpg_* series of the rules for mattermost-db, each with namespace and pod; the claim llm-gateway-db-1 is 5,368,709,120 bytes. At LiteLLM v1.103.10, proxy_server.py schedules the spend-log cleanup when maximum_spend_logs_retention_period is set, with no license check.

After the merge (Argo CD): cnpg_collector_up{namespace="llm"} appears, the dashboard CloudNativePG lists llm and mattermost in its namespace variable, and Argo CD prunes ConfigMap cnpg-grafana-dashboard in cnpg-system. The gateway pod restarts once for the changed config.

@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 11:58
@dan-petty
dan-petty merged commit 65473bc into main Nov 12, 2026
24 checks passed
@dan-petty
dan-petty deleted the feat/4994-gateway-database-observability branch November 12, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/monitoring Grafana, Prometheus, Loki, alerts and dashboards type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(monitoring): scrape the gateway database and alert on its size

1 participant