Skip to content

Extract Prometheus metric label names into constants #4777

@dejanzele

Description

@dejanzele

Is your feature request related to a problem? Please describe.

Prometheus metric label names are repeated as string literals across internal/common/metrics/scheduler_metrics.go. If someone introduces a typo (e.g., "queu" instead of "queue"), Prometheus silently creates a new metric series instead of erroring. This kind of bug is hard to catch in review and hard to debug in production.

Describe the solution you'd like

Define label name constants at the top of the file and use them in metric definitions instead of raw strings.

File to change

internal/common/metrics/scheduler_metrics.go (lines 35-175). Label names like "pool", "queue", "priorityClass", "resourceType", "nodeType", "cluster", "phase", "accounting_role", "reservation", "physical_pool", "priceBand" are each repeated across many metric definitions in this file.

Example

// Before (same strings repeated across many definitions)
prometheus.NewDesc(MetricPrefix+"queue_resource_queued", "...",
    []string{"pool", "priorityClass", "queueName", "queue", "priceBand", "resourceType", "accounting_role"}, nil)

// After
const (
    labelPool           = "pool"
    labelQueue          = "queue"
    labelQueueName      = "queueName"
    labelPriorityClass  = "priorityClass"
    labelPriceBand      = "priceBand"
    labelResourceType   = "resourceType"
    labelAccountingRole = "accounting_role"
    // ...
)

prometheus.NewDesc(MetricPrefix+"queue_resource_queued", "...",
    []string{labelPool, labelPriorityClass, labelQueueName, labelQueue, labelPriceBand, labelResourceType, labelAccountingRole}, nil)

Use unexported constants (lowercase) since they're only needed within the package.

Acceptance criteria

  • Repeated label name strings replaced with constants in scheduler_metrics.go
  • No behavioral change - metric names must stay exactly the same
  • go test ./internal/common/metrics/... passes
  • golangci-lint run ./internal/common/metrics/... passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions