Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Wise-Wizard <[email protected]>
  • Loading branch information
Wise-Wizard committed Aug 7, 2024
1 parent 39fedc4 commit 3746a07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/metrics/otelmetrics/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
Expand Down
12 changes: 12 additions & 0 deletions internal/metrics/otelmetrics/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3746a07

Please sign in to comment.