diff --git a/internal/metrics/otelmetrics/factory.go b/internal/metrics/otelmetrics/factory.go index 5d3f2b68ac8..17adec85a04 100644 --- a/internal/metrics/otelmetrics/factory.go +++ b/internal/metrics/otelmetrics/factory.go @@ -32,7 +32,7 @@ func NewFactory(meterProvider metric.MeterProvider) metrics.Factory { } func (f *otelFactory) Counter(opts metrics.Options) metrics.Counter { - name := counterNamingConvention(f.subScope(opts.Name)) + name := CounterNamingConvention(f.subScope(opts.Name)) counter, err := f.meter.Int64Counter(name) if err != nil { log.Printf("Error creating OTEL counter: %v", err) @@ -132,7 +132,7 @@ func attributeSetOption(tags map[string]string) metric.MeasurementOption { return metric.WithAttributes(attributes...) } -func counterNamingConvention(name string) string { +func CounterNamingConvention(name string) string { if !strings.HasSuffix(name, "_total") { name += "_total" } diff --git a/internal/metrics/otelmetrics/factory_test.go b/internal/metrics/otelmetrics/factory_test.go index ade7cbf8064..e9e3b9ee318 100644 --- a/internal/metrics/otelmetrics/factory_test.go +++ b/internal/metrics/otelmetrics/factory_test.go @@ -104,6 +104,18 @@ func TestCounter(t *testing.T) { assert.Equal(t, expectedLabels, promLabelsToMap(metrics[0].GetLabel())) } +func TestCounterNamingConvention(t *testing.T) { + input := "test_counter" + expected := "test_counter_total" + + result := otelmetrics.CounterNamingConvention(input) + + if result != expected { + t.Errorf("Expected %s, but got %s", expected, result) + } +} + + func TestGauge(t *testing.T) { registry := promReg.NewPedanticRegistry() factory := newTestFactory(t, registry)