fix(coderd): add organization_name label to insights Prometheus metrics#22296
Merged
fix(coderd): add organization_name label to insights Prometheus metrics#22296
Conversation
When multiple organizations have templates with the same name, the Prometheus /metrics endpoint returns HTTP 500 because duplicate label combinations are emitted for coderd_insights_* metrics. Adding organization_name as a label to all three insight metric descriptors disambiguates templates across organizations. Fixes #21748
Contributor
Documentation CheckUpdates Needed
Automated review via Coder Tasks |
johnstcn
approved these changes
Feb 25, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
When multiple organizations have templates with the same name, the Prometheus
/metricsendpoint returns HTTP 500 because Prometheus rejects duplicate label combinations. The threecoderd_insights_*metrics (coderd_insights_templates_active_users,coderd_insights_applications_usage_seconds,coderd_insights_parameters) used onlytemplate_nameas a distinguishing label, so two templates named e.g."openstack-v1"in different orgs would produce duplicate metric series.This adds
organization_nameas a label to all three insight metric descriptors to disambiguate templates across organizations.Changes
coderd/prometheusmetrics/insights/metricscollector.go:organization_namelabel to all three metric descriptorsorganizationNamesfield (template ID → org name) to theinsightsDatastructdoTick: after fetching templates, collect unique org IDs, fetch organizations viaGetOrganizations, and build a template-ID-to-org-name mappingCollect(): pass the organization name as an additional label value in everyMustNewConstMetriccallcoderd/prometheusmetrics/insights/testdata/insights-metrics.json: Updated golden file to includeorganization_name=coderin all metric label keys.Fixes #21748