Skip to content

Provision the UI-built Grafana dashboards from the repository - #1875

Merged
rdimitrov merged 2 commits into
mainfrom
rdimitrov-registry-usage-dashboard-preview
Nov 20, 2026
Merged

rdimitrov merged 2 commits into
mainfrom
rdimitrov-registry-usage-dashboard-preview

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What

Production Grafana has three dashboards. Only the gateway one is provisioned from this repository; the other two were built in the UI and live only in Grafana's database:

  • Registry Application Dashboard
  • Registry Deployment/Critical Issues

This exports both into deploy/pkg/k8s/dashboards/ and provisions every file in that folder into the General folder. After this, every dashboard is managed as code.

The first commit is the export with only the database id and version dropped. The second commit fixes three problems the review found in the application dashboard (see below), so that dashboard will look different after this deploys.

How it behaves

  • Grafana adopts an existing dashboard whose uid matches a provisioned file, so the two production dashboards keep their links and there is no duplicate.
  • Grafana then refuses to save them from the UI. Changes go through a pull request; deploy/README.md describes the export-then-PR workflow.
  • Staging, which only has the gateway dashboard today, gains both.
  • Adding the mounts restarts Grafana once.

Changes to the application dashboard

Panel Before After
Service Uptime Read mcp_registry_service_up, which the health handler only ever sets to 1, so it could not show an outage. Reads the scrape state of the mcp-registry job and shows 0 when no target reports.
Availability Showed no data whenever there were no 5xx responses, which is the normal case. Treats a missing error series as 0, the same way the alert rule does, so it shows 100%.
Availability, Client Side Errors, Server Side Errors, P95 By Endpoint Each had a saved "hide all series except one" selection, so only /v0/validate 422, /v0/servers 500 and /v0/publish were visible. All series are shown.

The Deployment/Critical Issues dashboard is unchanged from the export.

Before merging

  • This is one-way in practice. Removing the provider, including by reverting this change after it has deployed, makes Grafana delete the dashboards it manages. The JSON would still be in git.
  • Alert rules, contact points and notification policies are not covered and stay managed inside Grafana.
  • Staging picks this up on merge; production with the next production deployment.

How it was checked

  • go -C deploy test ./... passes. The new tests reject a changed production uid, a duplicate title, and a data source that is not provisioned.
  • The takeover was rehearsed on a local Grafana 12.4.14, the version production runs: a dashboard created the way the UI does was adopted under the same uid, with no duplicate, and then refused UI saves. The edited file also loads on that version.
  • The two changed queries were run read-only against production metrics: uptime returns 1 with all three targets up, and availability returns 100 where the old expression returned nothing.
  • Staging was checked for collisions: it has no dashboard with these titles and uses the same data source IDs as production.
  • The exported files contain only queries and layout: no URLs, addresses or secrets.

Production has two dashboards that were built in the Grafana UI and live
only in Grafana's database: Registry Application Dashboard and Registry
Deployment/Critical Issues. Export them unchanged, apart from the
database id and version, and provision them from files so every
dashboard is managed as code.

Grafana adopts an existing dashboard whose uid matches a provisioned
file, so the production dashboards keep their links. Staging gains both
dashboards.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Dashboard overrides hide relevant error and latency series, while availability and health queries fail to show 100% availability for error-free traffic or reliably surface outages.

5 open issues
What changed in this PR

Moves the two UI-built Registry dashboards into repository-managed Grafana provisioning alongside the existing gateway dashboard, preserving their production UIDs and links.

Changes:

  • Adds JSON exports for the application and deployment/critical-issues dashboards.
  • Creates dashboard ConfigMaps and mounts a General-folder provisioning provider in Grafana.
  • Adds validation tests and documents dashboard updates, deployment timing, and rollback behavior.
File Description
deploy/​README.md Documents repository-managed dashboards and the export-then-PR workflow.
deploy/​pkg/​k8s/​monitoring.go Connects the new dashboard mounts to Grafana deployment.
deploy/​pkg/​k8s/​grafana_dashboards.go Embeds dashboard files and creates provisioning ConfigMaps and mounts.
deploy/​pkg/​k8s/​grafana_dashboards_test.go Checks dashboard identity, data sources, and provisioning resources.
deploy/​pkg/​k8s/​dashboards/​registry-deployment-critical-issues.json Adds the deployment and infrastructure dashboard export.
deploy/​pkg/​k8s/​dashboards/​registry-application.json Adds the application health, errors, traffic, and latency dashboard export.

Review effort: Max

Address review feedback on the exported dashboard:

- Service Uptime read mcp_registry_service_up, which the health handler
  only ever sets to 1, so it could not show an outage. Use the scrape
  target state for the mcp-registry job and default to 0 when no target
  reports.
- Availability returned no data when there was no 5xx series, which is
  the normal case. Default the error rate to 0, as the alert rule does.
- Remove four saved hideSeriesFrom overrides that hid every series
  except one that happened to be selected when the dashboard was saved.

Co-authored-by: Copilot App <[email protected]>
@rdimitrov
rdimitrov merged commit addc901 into main Nov 20, 2026
18 checks passed
@rdimitrov
rdimitrov deleted the rdimitrov-registry-usage-dashboard-preview branch November 20, 2026 19:22
rdimitrov added a commit that referenced this pull request Nov 20, 2026
…repository (#1876)

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:alertDiscordWebhook` is set. It is not set in any stack
file here, so after merge:

- no Secret, ConfigMap, mount, variable or annotation is created, and
the Grafana chart values are identical to today's (covered by a test);
- production keeps its UI-built rules untouched until the webhook is
set, and no environment can get rules that notify a contact point it
does not have.

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` /
`deleteContactPoints` entry. Reverting this PR after the webhook has
been set therefore does not restore UI editing.

## Two commits, the second is optional

1. **Provision the Grafana alert rules and Discord contact point from
the repository.** The rules are byte-for-byte what Grafana 12.4.14
exports from a state matching production's, so behaviour is unchanged:
same uids, queries, thresholds, timings, no-data and error states,
annotations and routing. The notification policy tree is deliberately
not provisioned, because doing so replaces the whole tree and these
rules do not use it.
2. **Make "Registry Service Down" able to detect an outage.** Can be
dropped on its own; it changes one query. The rule can never fire today,
because `mcp_registry_service_up` is only ever recorded as 1, so an
outage reaches Discord as "DatasourceNoData". It now queries
`max(up{job="mcp-registry"}) or vector(0)`, the expression the linked
dashboard panel uses since #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.

- **Adoption:** rules and contact point are taken over under their
existing uids. No duplicates, folder reused, policy tree untouched. The
stored rules equal production's except their position index within the
group; the displayed order is unchanged.
- **Rolling replacement, every rule Normal (production's state):** 0
notifications, 0 state changes, all 10 alert instances kept, including
the seven on the P95 rule.
- **Rolling replacement, one rule firing:** the same notifications at
the same seconds as a control replacement without the files.
- **Second commit:** the takeover sent nothing while the registry was
up; an outage sent "[FIRING:1] Registry Service Down" at the next
evaluation and recovery sent "[RESOLVED]".
- **Removal:** dropping a rule from the file, or all the files, deletes
nothing and leaves everything working and locked.
- **Invalid input:** invalid YAML, an invalid rule, a rule naming a
missing contact point, or a missing webhook variable makes Grafana exit
in about a second without ever answering its health check, so a rolling
update keeps the running pod. A webhook that is not a URL does start,
which is why Pulumi rejects it first.
- **Webhook:** the configured value replaces the one Grafana had stored,
and it appeared in no Grafana log, including on a refused connection and
a 404.
- **File changes:** Grafana reads these files only at startup, so a pod
annotation restarts it when a file or the webhook changes. The
annotation is a 12-character hash prefix; it is the only value derived
from the webhook that leaves the Secret.

## Not rehearsed or verified

- The first real application of these files will be in whichever
environment gets the webhook first.
- CI's Pulumi CLI is 3.188.0; the "must be a secret" check was exercised
with the real CLI on 3.272.0 only.
- The Grafana chart was not rendered with Helm; its 9.4.4 templates were
read for `podAnnotations`.
- An alert that had been firing for a long time before the takeover.
Production has none firing.
- The README's **Export → With modifications** menu path comes from
Grafana's UI strings.

## Not identical after adoption

- Rules and contact point are read-only in the UI (the lock above).
- Each rule's stored position index becomes 0.
- Every Grafana start re-applies the files and raises each rule's
version by one.

## Testing

`go -C deploy test ./...` and the `deploy/scripts` unit 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.

---------

Co-authored-by: Copilot App <[email protected]>
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]>
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.

2 participants