Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
santize all scope names and metric names (#115)
Browse files Browse the repository at this point in the history
Signed-off-by: Ketan Umare <[email protected]>
  • Loading branch information
kumare3 authored Feb 9, 2022
1 parent 63db7a6 commit 9f812e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions promutils/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -435,7 +435,7 @@ func NewScope(name string) Scope {
}

return metricsScope{
scope: name,
scope: SanitizeMetricName(name),
}
}

Expand Down
1 change: 1 addition & 0 deletions promutils/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9f812e9

Please sign in to comment.