Skip to content

fix(coderd): add organization_name label to insights Prometheus metrics#22296

Merged
f0ssel merged 3 commits intomainfrom
fix/insights-metrics-org-label
Feb 25, 2026
Merged

fix(coderd): add organization_name label to insights Prometheus metrics#22296
f0ssel merged 3 commits intomainfrom
fix/insights-metrics-org-label

Conversation

@f0ssel
Copy link
Copy Markdown
Collaborator

@f0ssel f0ssel commented Feb 25, 2026

Description

When multiple organizations have templates with the same name, the Prometheus /metrics endpoint returns HTTP 500 because Prometheus rejects duplicate label combinations. The three coderd_insights_* metrics (coderd_insights_templates_active_users, coderd_insights_applications_usage_seconds, coderd_insights_parameters) used only template_name as a distinguishing label, so two templates named e.g. "openstack-v1" in different orgs would produce duplicate metric series.

This adds organization_name as a label to all three insight metric descriptors to disambiguate templates across organizations.

Changes

coderd/prometheusmetrics/insights/metricscollector.go:

  • Added organization_name label to all three metric descriptors
  • Added organizationNames field (template ID → org name) to the insightsData struct
  • In doTick: after fetching templates, collect unique org IDs, fetch organizations via GetOrganizations, and build a template-ID-to-org-name mapping
  • In Collect(): pass the organization name as an additional label value in every MustNewConstMetric call

coderd/prometheusmetrics/insights/testdata/insights-metrics.json: Updated golden file to include organization_name=coder in all metric label keys.

Fixes #21748

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
@coder-tasks
Copy link
Copy Markdown
Contributor

coder-tasks bot commented Feb 25, 2026

Documentation Check

Updates Needed

  • docs/admin/integrations/prometheus.md - The label columns for the three affected metrics need organization_name added:
    • coderd_insights_applications_usage_seconds: labels now documented as application_name organization_name slug template_name
    • coderd_insights_parameters: labels now documented as organization_name parameter_name parameter_type parameter_value template_name
    • coderd_insights_templates_active_users: labels now documented as organization_name template_name

Automated review via Coder Tasks

@f0ssel f0ssel requested a review from johnstcn February 25, 2026 01:06
@f0ssel f0ssel enabled auto-merge (squash) February 25, 2026 01:16
@f0ssel f0ssel merged commit 4057363 into main Feb 25, 2026
29 checks passed
@f0ssel f0ssel deleted the fix/insights-metrics-org-label branch February 25, 2026 08:58
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prometheus insights metrics fail when multiple organizations have templates with the same name

2 participants