Skip to content

Commit 6f7c3aa

Browse files
Fix Prometheus metric naming: use WithoutUnits, WithoutCounterSuffixes, WithoutScopeInfo
OpenTelemetry's Prometheus exporter adds suffixes by default: - "_ratio" suffix for gauges with unit "1" - "_total" suffix for counters - "otel_scope_*" labels to all metrics These changes broke backward compatibility with existing metric names. Adding these options preserves the original metric names: - problem_gauge (not problem_gauge_ratio) - problem_counter (not problem_counter_total) Co-authored-by: MartinForReal <[email protected]>
1 parent 4a5e215 commit 6f7c3aa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/exporters/prometheusexporter/prometheus_exporter.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ func NewExporterOrDie(npdo *options.NodeProblemDetectorOptions) types.Exporter {
3939
}
4040

4141
addr := net.JoinHostPort(npdo.PrometheusServerAddress, strconv.Itoa(npdo.PrometheusServerPort))
42-
exporter, err := prometheus.New()
42+
// Use options to prevent OpenTelemetry from modifying metric names:
43+
// - WithoutUnits: prevents adding unit suffixes like "_ratio" to metric names
44+
// - WithoutCounterSuffixes: prevents adding "_total" suffix to counters
45+
// - WithoutScopeInfo: prevents adding otel_scope_* labels to metrics
46+
// This ensures backward compatibility with existing metric names.
47+
exporter, err := prometheus.New(
48+
prometheus.WithoutUnits(),
49+
prometheus.WithoutCounterSuffixes(),
50+
prometheus.WithoutScopeInfo(),
51+
)
4352
if err != nil {
4453
klog.Fatalf("Failed to create Prometheus exporter: %v", err)
4554
}

0 commit comments

Comments
 (0)