Skip to content

Commit a904d7d

Browse files
Fix deprecation warning: use WithTranslationStrategy instead of deprecated options
Replace deprecated prometheus.WithoutUnits() and prometheus.WithoutCounterSuffixes() with prometheus.WithTranslationStrategy(otlptranslator.UnderscoreEscapingWithoutSuffixes) as recommended by the linter. The UnderscoreEscapingWithoutSuffixes strategy: - Translates metric/label name characters to underscores (standard Prometheus behavior) - Does NOT append suffixes like "_total" for counters or "_ratio" for gauges This maintains the same behavior while using the non-deprecated API. Co-authored-by: MartinForReal <[email protected]>
1 parent 6f7c3aa commit a904d7d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/exporters/prometheusexporter/prometheus_exporter.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strconv"
2323

2424
"github.com/prometheus/client_golang/prometheus/promhttp"
25+
"github.com/prometheus/otlptranslator"
2526
"go.opentelemetry.io/otel/exporters/prometheus"
2627
"k8s.io/klog/v2"
2728

@@ -39,14 +40,13 @@ func NewExporterOrDie(npdo *options.NodeProblemDetectorOptions) types.Exporter {
3940
}
4041

4142
addr := net.JoinHostPort(npdo.PrometheusServerAddress, strconv.Itoa(npdo.PrometheusServerPort))
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
43+
// Use UnderscoreEscapingWithoutSuffixes translation strategy to:
44+
// - Translate metric/label name characters to underscores (standard Prometheus behavior)
45+
// - NOT append suffixes like "_total" for counters or "_ratio" for gauges
46+
// Also disable scope info to prevent adding otel_scope_* labels to metrics.
4647
// This ensures backward compatibility with existing metric names.
4748
exporter, err := prometheus.New(
48-
prometheus.WithoutUnits(),
49-
prometheus.WithoutCounterSuffixes(),
49+
prometheus.WithTranslationStrategy(otlptranslator.UnderscoreEscapingWithoutSuffixes),
5050
prometheus.WithoutScopeInfo(),
5151
)
5252
if err != nil {

0 commit comments

Comments
 (0)