Repository navigation
Run the usage collector daily and show its results in Grafana - #1878
Merged
Merged
Conversation
One setting, mcp-registry:usageCollector, puts a daily CronJob in the monitoring namespace, a database of its own on grafana-pg with confined roles, a read-only Grafana data source, the Registry usage and Registry publishing dashboards and, where alerting is configured, two alert rules. It is on in staging. Production is unchanged until it is set there. "false" retires it: the workload goes and Grafana deletes the data source, the dashboards and the rules, which it would otherwise keep. The stored history stays. The collector gets an image of its own, built by the workflows that build the registry's. Co-authored-by: Copilot App <[email protected]>
The dashboard is provisioned in staging as well as production. The README now also says what the registry read role can create, as checked on both live databases. Co-authored-by: Copilot App <[email protected]>
grafana-pg is a single instance, so its disk was the only copy of the history. A daily CronJob now archives the registry_usage database and stores it with Restic, as the registry's backup does, in a bucket of its own. The archive is made by the role that owns that database, which cannot read Grafana's own; the bucket is reached with the collector's existing Google key, which is granted that bucket and no other. The bucket and its snapshots are kept when the collector is retired, and are never deleted by Pulumi. The README has the restore procedure. Co-authored-by: Copilot App <[email protected]>
The collector now names the client that asked for a server most only when every day in the range agrees on it, and leaves the name and its share empty otherwise. The panel's description said nothing about the blank cells that result. Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Dashboard queries overcount publications and daily servers, webhook-gated provisioning can leave stale failing alerts, and the restore instructions allow active collectors to keep writing during restoration.
4 open issues
What changed in this PR
Integrates the existing hosted usage collector with Pulumi and Grafana, enabling daily collection in staging without changing production configuration.
Changes:
- Provisions the collector, database roles, credentials, cache storage, and retained history backups.
- Adds usage and publishing dashboards, conditional alerts, and retirement cleanup.
- Publishes collector images and adds deployment tests and operator documentation.
| File | Description |
|---|---|
deploy/README.md |
Documents setup, operation, backups, restore, and retirement. |
deploy/Pulumi.gcpStaging.yaml |
Enables collection in staging. |
deploy/pkg/usagecollector/usagecollector.go |
Defines shared settings, validation, and resource identifiers. |
deploy/pkg/usagecollector/usagecollector_test.go |
Tests settings and encrypted alias validation. |
deploy/pkg/providers/types.go |
Carries the collector’s Google credential. |
deploy/pkg/providers/gcp/usage_collector.go |
Provisions Google access and retained backup storage. |
deploy/pkg/providers/gcp/usage_collector_test.go |
Tests access scope and backup retention. |
deploy/pkg/providers/gcp/provider.go |
Connects collector access to cluster provisioning. |
deploy/pkg/k8s/usage/dashboards/registry-usage.json |
Adds usage, client, and lookup visualizations. |
deploy/pkg/k8s/usage/dashboards/registry-publishing.json |
Adds publishing and catalogue visualizations. |
deploy/pkg/k8s/usage/alerting/rules.yaml |
Defines missed-day and estimate-drift alerts. |
deploy/pkg/k8s/usage/alerting/retired.yaml |
Defines explicit deletion of usage alerts. |
deploy/pkg/k8s/usage_grafana.go |
Provisions the data source, dashboards, and restart triggers. |
deploy/pkg/k8s/usage_collector.go |
Creates database resources and the daily collector workload. |
deploy/pkg/k8s/usage_collector_test.go |
Tests workloads, credentials, Grafana integration, and retirement. |
deploy/pkg/k8s/usage_backup.go |
Schedules database archives and Restic backups. |
deploy/pkg/k8s/monitoring.go |
Integrates collection into the monitoring deployment. |
deploy/pkg/k8s/grafana_alerting.go |
Accepts additional alert files and preserves annotations. |
deploy/pkg/k8s/grafana_alerting_test.go |
Updates the Grafana deployment test call. |
deploy/pkg/k8s/deploy.go |
Passes the registry database to monitoring. |
deploy/main.go |
Validates collector configuration before provisioning. |
deploy/go.sum |
Records checksums for the random provider dependency. |
deploy/go.mod |
Adds the random provider for generated passwords. |
.ko.yaml |
Configures the collector image build. |
.github/workflows/release.yml |
Publishes release-tagged collector images. |
.github/workflows/deploy-staging.yml |
Builds staging collector images independently of deployment. |
Review effort: Balanced
Retiring the collector now deletes its two alert rules even where the webhook has been removed first or at the same time. Rules and the contact point still need the webhook; a file that only deletes does not. "Servers ever published" no longer counts first versions published after the end of the selected range in its last week or month. "Servers looked up per day" and the network count in "Names seen per day" now average over every stored day, counting a day without rows as zero and leaving out a day stored without the catalogue or the network-owner table. The restore steps now have the operator stop or wait for collector runs that are already going, which suspending the CronJob does not do. Runs carry a label so that they can be found. Co-authored-by: Copilot App <[email protected]>
rdimitrov
added a commit
that referenced
this pull request
Nov 20, 2026
…ls in Secret data (#1880) The staging deploy that followed #1878 failed while applying its saved plan (`apply-failed-plan-constraint,resource-secret`), and that blocks every later staging deploy. This fixes it. ## Cause `deploy/scripts/deploy_stack.py` runs `pulumi preview --save-plan` and then `pulumi up --plan`. The Kubernetes provider moves a Secret's `stringData` into `data` once it knows the values. Four of the usage collector's Secrets took values that are random passwords, unknown at preview: - the three `registry-usage-*-password` Secrets (role name and generated password) - `registry-usage-collector` (the two database addresses, which contain those passwords) For those, the plan recorded `stringData` and the apply presented `data` instead, so Pulumi rejected the resource: ``` kubernetes:core/v1:Secret::registry-usage-collector-password violates plan: properties changed: +-stringData[...], =+data[...] ``` The repository's older Secrets that use `stringData` take values known at preview (configuration), so they are not affected. `registry-usage-collector-gcp` already used `data`, which is why it was created. ## Fix Those four Secrets now supply base64 values in `data` directly, which has the same shape at preview and at apply. Values remain Pulumi secrets; nothing moves into chart values, ConfigMaps or logs. A test asserts that no usage Secret uses `stringData`. ## How it was checked Nothing was run against the staging or production stack. Everything below used Pulumi CLI 3.188.0 (the version CI pins), a local file backend and the Kubernetes provider rendering manifests to a directory. 1. **Small programs with the Secret shapes.** `stringData` with a value unknown at preview fails in every variant tried: mixed with a known value, alone, the whole map as one output, wrapped as a secret, with and without the optional aliases. `data` passes in each. This rules out the CLI version, the random provider and the mixed map as causes. 2. **The real program** (`k8s.DeployMonitoringStack` with staging's configuration, and a stand-in for the Google key): | Step | Program | Result | | --- | --- | --- | | 1 | main before the fix, flag unset | applied | | 2 | main before the fix, flag `"true"` | preview lists 18 creates and 2 updates; apply fails on `registry-usage-collector-password` with the message above, leaving a partial state like staging's | | 3 | this branch, flag `"true"`, on that partial state | preview lists 10 creates and 1 update (the Grafana Deployment, in place); apply succeeds | | 4 | this branch again | no changes | No resource was replaced or deleted in step 3, and the stand-in key kept its id and creation time. The rendered Secrets hold the role names, 32-character passwords and the two addresses under `data`; Grafana reads its password through `secretKeyRef`. `go -C deploy test ./...` and the script tests pass. ## What the next staging deploy does It creates what the failed apply did not reach: the four Secrets, the three `DatabaseRole` objects, the `Database`, and both CronJobs, and it updates Grafana. Resources that already exist (bucket, service account key, IAM grant, `registry-usage-collector-gcp`, PVC, PriorityClass, the two dashboard ConfigMaps) have unchanged inputs and are left as they are. The service account key is not recreated. The local reproduction stops at the first failing resource, as staging did, so this deploy is the first time the CNPG objects, the CronJobs and the Grafana update are applied to a real cluster. A server-side dry run of the four CNPG objects was accepted in staging earlier. ## Not changed `deploy/pkg/providers/gcp/provider.go` has an older Secret (`AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` from an HMAC key) with the same pattern. It exists in both stacks and deploys today; it would hit this error only if its key were created or replaced in a planned deployment. Left for a separate change. The manual steps after a successful deploy are unchanged from #1878: make the `registry-usage-collector` image package public, then start the first run by hand. 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.


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.yamlis untouched.The setting
"true""false"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
registry-usage-collectorinmonitoring, 01:15 UTC. A run collects every missing day of the last 13, so a missed run heals itself.registry_usageon the existinggrafana-pgcluster, kept indefinitely.DatabaseRoleobjects with generated passwords. Neither CNPGClusterobject is modified.registry_usage_collectorowns the usage database.registry_usage_grafanacan only read what the dashboards query.registry_usage_readerreads the registry database throughpg_read_all_dataand can write nothing. Today that database holdsserversandschema_migrations.roles/logging.viewerand a key for the existingregistry-usage-readerservice account. The account itself is not managed.mcp-registry:alertDiscordWebhookis set too. Staging does not have it, so staging gets no rules yet.ghcr.io/modelcontextprotocol/registry-usage-collector, built indeploy-staging.ymlin a job of its own, which the deploy does not wait for, and inrelease.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.mdhas a new "Usage collector" section covering all of this.Backup of the history, and its restore
grafana-pgis a single instance, so CronJobregistry-usage-history-backuparchives 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.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.registry_usage_collectorin read-only transactions. No credential of Grafana's own database is used.pg_restore --cleanintoregistry_usageas 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
registry-usage-collectorpublic. A new package is private and the clusters pull without credentials. Until then the daily job cannot start; nothing else is affected.kubectl -n monitoring create job --from=cronjob/registry-usage-collector usage-first-run. It takes about an hour.mcp-registry:usageCollectorOrganizationAliasesas 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:
randomprovider 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.roles/storage.admin.Already checked against staging: a server-side dry run of the three
DatabaseRoleobjects and theDatabasewas 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.DatabaseRolecreates them, the collector's code as merged in Add usage collector for the hosted registry #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."false"removes the data source, both dashboards and both rules and nothing else.What only staging can show
DatabaseRoleandDatabaseobjects, including a password change and retirement.pg_dumpfrom the job's pod.grafana-pgis rebuilt, which the restore relies on.