Repository navigation
Provision the Grafana alert rules and Discord contact point from the repository - #1876
Merged
Merged
Conversation
…repository Production's four alert rules and the "Registry Dev" Discord contact point were built in the Grafana UI and live only in Grafana's database. Define them as alerting provisioning files, exported unchanged from a Grafana 12.4.14 instance holding the same rules, and mount them into Grafana. The Discord webhook is a credential and this repository is public. It comes from the new encrypted config key mcp-registry:alertDiscordWebhook, is stored in a Kubernetes Secret and reaches Grafana as an environment variable that the contact point file refers to. Where the key is not set, no alerting resource is created and the Grafana chart values are unchanged, so production stays as it is until the webhook is set and no environment gets rules that notify a contact point it does not have. A deployment refuses a webhook that is stored unencrypted or is not an https URL, without printing it. Grafana reads alerting files only when it starts, and ConfigMaps are updated in place, so a pod annotation restarts Grafana when a file or the webhook changes. The notification policy tree is left to Grafana: provisioning it replaces the whole tree, and these rules name their contact point directly. Rehearsed on Grafana 12.4.14 with PostgreSQL before proposing this: - Rules and the contact point created the way the UI does are adopted by uid. Every stored rule column matches production afterwards except the position within the group, which file provisioning does not carry; the displayed order is unchanged. - Replacing a running Grafana with one that has the files sent nothing while every rule was Normal, and sent the same notifications at the same times as a replacement without the files while a rule was firing. - Adopted objects become read-only in the UI. Removing the files deletes nothing and leaves them read-only; only a deleteRules or deleteContactPoints entry removes them. - A file that cannot be provisioned stops Grafana from starting, so a rolling update keeps the running pod. Co-authored-by: Copilot App <[email protected]>
Separate from the adoption so that it can be accepted or dropped on its
own. Only the query of rule bexrhynsud6gwa changes.
The rule fired when max(mcp_registry_service_up{}) was below 1, but the
health handler is the only place that records that metric and it always
records 1, so the threshold could never be met. When the registry is
down the series goes missing instead, and the rule reports that through
its no-data state: Discord receives "DatasourceNoData" with the rule's
name in parentheses rather than "Registry Service Down".
Query max(up{job="mcp-registry"}) or vector(0) instead, the same
expression the dashboard panel this rule links to now uses. It is 1
while any registry target is scraped successfully and 0 when none is.
The pending period stays at 0. Today the rule already notifies at the
first evaluation that finds no series, from the same scrape targets, so
this keeps both the timing and the exposure to a gap in scraping and
changes only what the notification says. A pending period would delay
every real outage by one five-minute evaluation.
Checked read-only against production: over the 14 days VictoriaMetrics
retains, the new expression never read 0 at one-minute steps, raw
samples had no gap longer than 90 seconds, and the rule would not have
fired with a pending period of 0 or of 5 minutes at any evaluation
alignment. That window held one fast VictoriaMetrics restart, so it
says nothing about a slow one: an evaluation that lands after a long
VictoriaMetrics outage and before the first scrape could read 0 once,
where today it would report no data once.
Rehearsed on Grafana 12.4.14: adopting production's rule with this
query sent nothing while the registry was up; an outage produced
"[FIRING:1] Registry Service Down" at the next evaluation, and recovery
produced "[RESOLVED]" at the one after.
Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Irreversible Grafana alerting adoption requires deployment validation with CI’s pinned Pulumi and the actual Helm chart, including staging compatibility, subsequent file edits, and webhook rotation, beyond the reported Grafana-only rehearsal.
No open issues 🎉
What changed in this PR
Extends the dashboard provisioning work from #1875 to manage Grafana alert rules and the Discord contact point in the repository. Provisioning is opt-in through an encrypted webhook setting; environments without it remain unchanged.
Changes:
- Adds four alert rules and the existing Discord contact point, with the service-down query updated to detect unavailable scrape targets.
- Wires Pulumi provisioning to a Kubernetes Secret, alert-file ConfigMap, and restart trigger for file or webhook changes.
- Documents activation, editing, and one-way adoption, with tests for provisioning safeguards and secret handling.
| File | Description |
|---|---|
deploy/README.md |
Documents webhook setup, alert management, adoption, and deletion behavior. |
deploy/pkg/k8s/monitoring.go |
Integrates optional alert provisioning into Grafana chart values. |
deploy/pkg/k8s/grafana_alerting.go |
Validates the webhook and creates resources, mounts, and restart annotations. |
deploy/pkg/k8s/grafana_alerting_test.go |
Tests alert references, opt-in behavior, webhook guards, and secret handling. |
deploy/pkg/k8s/alerting/rules.yaml |
Defines four alert rules, including the updated service-down query. |
deploy/pkg/k8s/alerting/contact-points.yaml |
Defines the Discord contact point using an environment-provided webhook. |
Review effort: Balanced
rdimitrov
added a commit
that referenced
this pull request
Nov 20, 2026
Runs the usage collector (#1877) once a day in the hosted clusters and shows what it records in Grafana, on top of the dashboards (#1875) and alert rules (#1876) that are now provisioned from this repository. Everything is created by Pulumi behind one setting, `mcp-registry:usageCollector`. This pull request sets it to `"true"` in staging, so **merging deploys all of it to staging**. Production has no setting and is not changed; `deploy/Pulumi.gcpProd.yaml` is untouched. ## The setting | Value | Effect | |---|---| | not set | Nothing is created and nothing changes. Production today. | | `"true"` | Everything in the next section. | | `"false"` | Retired: the workload is removed and Grafana deletes the data source, dashboards and alert rules, which it would otherwise keep. The stored history and its backups stay. | It is only accepted on the hosted stacks with the standalone Gateway, which produces the request counters the collector scales by. ## What staging gets on merge - **Daily run:** CronJob `registry-usage-collector` in `monitoring`, 01:15 UTC. A run collects every missing day of the last 13, so a missed run heals itself. - **History:** database `registry_usage` on the existing `grafana-pg` cluster, kept indefinitely. - **Three confined database roles**, as CNPG `DatabaseRole` objects with generated passwords. Neither CNPG `Cluster` object is modified. - `registry_usage_collector` owns the usage database. - `registry_usage_grafana` can only read what the dashboards query. - `registry_usage_reader` reads the registry database through `pg_read_all_data` and can write nothing. Today that database holds `servers` and `schema_migrations`. - **Google access:** `roles/logging.viewer` and a key for the existing `registry-usage-reader` service account. The account itself is not managed. - **Grafana:** a read-only PostgreSQL data source and the "Registry usage" and "Registry publishing" dashboards. Grafana restarts once to read them. - **Two alert rules** (a missed day; the log-based estimate drifting more than 10% from the gateway counters), only where `mcp-registry:alertDiscordWebhook` is set too. Staging does not have it, so staging gets no rules yet. - **Backup:** see below. - **Image:** `ghcr.io/modelcontextprotocol/registry-usage-collector`, built in `deploy-staging.yml` in a job of its own, which the deploy does not wait for, and in `release.yml`. A run cannot hold up a deployment or the registry. Pulumi waits for none of the jobs, the volume or the database objects. The pod has small requests, hard limits and a priority below every other workload. It reads the registry database over one connection in short read-only transactions. `deploy/README.md` has a new "Usage collector" section covering all of this. ## Backup of the history, and its restore `grafana-pg` is a single instance, so CronJob `registry-usage-history-backup` archives the usage database every day at 03:30 UTC, the same way the registry's backup works: `pg_dump`, read back and checksummed, then Restic with 28 daily snapshots. - It goes to a bucket of its own, `mcp-registry-<environment>-usage-backups`. The collector's service account is granted that bucket and no other, so it cannot reach the registry's backups. - The archive is made by `registry_usage_collector` in read-only transactions. No credential of Grafana's own database is used. - Retiring the collector keeps the bucket and its snapshots, and Pulumi never deletes the bucket. - The Restic password is a fixed, documented string, not a secret: a generated one would be lost with the Pulumi state that held it. The job creates its repository if there is none. A failed backup is not alerted on. - **Restore:** fetch the archive with Restic, then `pg_restore --clean` into `registry_usage` as its owner. It works on an empty database and on one the collector has written to since. The collector then collects whatever of the last 13 days is missing. The commands are in the README under "Restoring the history". ## Steps by hand 1. After the first staging build, make the GHCR package `registry-usage-collector` public. A new package is private and the clusters pull without credentials. Until then the daily job cannot start; nothing else is affected. 2. After the deploy, start the first run instead of waiting for 01:15 UTC: `kubectl -n monitoring create job --from=cronjob/registry-usage-collector usage-first-run`. It takes about an hour. 3. Optional: set `mcp-registry:usageCollectorOrganizationAliases` as an encrypted secret. ## Where the staging deploy itself could fail A failed Pulumi run in staging blocks later staging deploys, so these are the points I could not rule out locally: - **Grafana must become ready.** Pulumi waits for the chart's Deployment. The data source and dashboard provider files load on Grafana 12.4.14 locally, but with SQLite as Grafana's own database; staging's uses PostgreSQL. - **The `random` provider plugin.** Pulumi fetched it on demand locally with 3.272. CI uses 3.188.0, which obtains the gcp and kubernetes plugins the same way. - **Applying a saved plan with values unknown at preview** (three passwords and the key). The staging restore's key-to-Secret flow has the same shape and works. - **The new bucket.** Its name is free today, and the deploy account holds `roles/storage.admin`. Already checked against staging: a server-side dry run of the three `DatabaseRole` objects and the `Database` was accepted, with nothing persisted. Not waited for, so they cannot fail the deploy: the two CronJobs, the cache volume and CNPG's reconciliation. If the organization does not let Actions create a new package, the image job fails and the deploy still runs. ## How it was checked - `go -C deploy test ./...`, with new tests for all three states of the setting, credential handling, role confinement and the backup; the deploy script tests; the collector's tests. - On a local PostgreSQL 17, with the roles shaped as `DatabaseRole` creates them, the collector's code as merged in #1877 created its schema, read a registry database through the read-only role and stored 13 days from its synthetic fixtures. 35 checks confirm what each role can and cannot do. - Grafana 12.4.14 was started with the files this code generates. All 52 panel queries run as the read-only role for day, week and month; both rules evaluate correctly for fresh, stale, drifted, empty and missing-table data; `"false"` removes the data source, both dashboards and both rules and nothing else. - The backup's two scripts ran against that database. A snapshot restored into an empty database was identical to the original, and the dashboards and the collector worked on it. - The generated objects pass strict schema validation against both clusters' published schemas. - The collector image builds with ko for amd64 and arm64. ## What only staging can show - How the CNPG operator reconciles the `DatabaseRole` and `Database` objects, including a password change and retirement. - Key creation, the IAM grant, the new bucket and its grants with the real deploy account. - The collector in the cluster: image pull, egress to Google and the two public reference sites, the cache volume, memory on real data. - Restic against Google Cloud Storage with the service account key, and `pg_dump` from the job's pod. - Whether CNPG recreates the database and roles after `grafana-pg` is rebuilt, which the restore relies on. - The real one-hour and two-hour alert timings. --------- Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #1875, which did the same for dashboards. Production's four alert rules and the "Registry Dev" Discord contact point exist only in Grafana's database; this defines them in the repository and has Pulumi provision them.
Merging this changes nothing by itself
Alerting is provisioned only where the new encrypted config key
mcp-registry:alertDiscordWebhookis set. It is not set in any stack file here, so after merge:The webhook is a credential and this repository is public. It is stored only as a Pulumi secret, reaches Grafana as an environment variable from a Kubernetes Secret, and never enters a file, a ConfigMap or the chart values. A deployment refuses a value that is unencrypted or not an
https://URL, without printing it. Setting it is described in the README ("Grafana Alerts" → "Setting the webhook"); the README recommends staging first, with a test channel of its own.Adoption is a one-way lock
Once Grafana has provisioned or adopted a rule or contact point, it can only be changed through this repository. The UI and the API refuse to edit or delete it, and removing the files, or the webhook, neither unlocks nor deletes it. Deleting takes a
deleteRules/deleteContactPointsentry. Reverting this PR after the webhook has been set therefore does not restore UI editing.Two commits, the second is optional
mcp_registry_service_upis only ever recorded as 1, so an outage reaches Discord as "DatasourceNoData". It now queriesmax(up{job="mcp-registry"}) or vector(0), the expression the linked dashboard panel uses since Provision the UI-built Grafana dashboards from the repository #1875. The pending period stays at 0; the commit message explains why and gives the 14-day backtest and its limits.If this is squash-merged the two land as one change, so drop the second commit before merging if it is not wanted.
Rehearsed on Grafana 12.4.14 with PostgreSQL
Production's alerting state was recreated through the endpoints the UI uses (every stored rule column compared equal to production's), then the files were applied.
Not rehearsed or verified
podAnnotations.Not identical after adoption
Testing
go -C deploy test ./...and thedeploy/scriptsunit tests pass on each commit. The new tests cover the file invariants (production uids, folder and group; contact point, data source and dashboard panel exist; no webhook or notification policy in a file), the gating through the Grafana chart values, the webhook guards, and that no stack file holds the webhook unencrypted. Each was confirmed to fail for the mistake it guards.