diff --git a/promutils/scope.go b/promutils/scope.go index 4d29902f2e..326094f3ae 100644 --- a/promutils/scope.go +++ b/promutils/scope.go @@ -23,7 +23,7 @@ func panicIfError(err error) { } } -// A Simple StopWatch that works with prometheus summary +// StopWatch implements a stopwatch style interface that works with prometheus summary // It will scale the output to match the expected time scale (milliseconds, seconds etc) // NOTE: Do not create a StopWatch object by hand, use a Scope to get a new instance of the StopWatch object type StopWatch struct { @@ -46,7 +46,7 @@ func (s StopWatch) Start() Timer { } } -// Observes specified duration between the start and end time +// Observe records a specified duration between the start and end time func (s StopWatch) Observe(start, end time.Time) { observed := end.Sub(start).Nanoseconds() outputScaleDuration := s.outputScale.Nanoseconds() @@ -58,7 +58,7 @@ func (s StopWatch) Observe(start, end time.Time) { s.Observer.Observe(scaled) } -// Observes/records the time to execute the given function synchronously +// Time Observes/records the time to execute the given function synchronously func (s StopWatch) Time(f func()) { t := s.Start() f() @@ -435,7 +435,7 @@ func NewScope(name string) Scope { } return metricsScope{ - scope: name, + scope: SanitizeMetricName(name), } } diff --git a/promutils/scope_test.go b/promutils/scope_test.go index 610f29f2e4..b27c3b8df8 100644 --- a/promutils/scope_test.go +++ b/promutils/scope_test.go @@ -37,6 +37,7 @@ func TestNewScope(t *testing.T) { assert.Equal(t, "test:timer_x", s.NewScopedMetricName("timer_x")) assert.Equal(t, "test:hello:timer:", s.NewSubScope("hello").NewSubScope("timer").CurrentScope()) assert.Equal(t, "test:hello:timer:", s.NewSubScope("hello").NewSubScope("timer:").CurrentScope()) + assert.Equal(t, "test:k8s_array:test_1:", s.NewSubScope("k8s-array").NewSubScope("test-1:").CurrentScope()) } func TestMetricsScope(t *testing.T) {