Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ type HistogramSnapshot interface {

// Durations returns the sample values by upper bound for a durationHistogram
Durations() map[time.Duration]int64

// NumValues returns the number of values which were emitted by this metric
NumValues() int64

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with doing this is HistogramSnapshot is an interface... i.e. adding a method to an interface is a breaking version change.

This is one of the things about our current Tally API - we expose everything via interfaces, which is a right PITA. We can't land this like this.

We can make a better testing story in the current version tho. Lets chat offline once


// NumDurations returns the number of values which were emitted by this metric
NumDurations() int64
}

// mergeRightTags merges 2 sets of tags with the tags from tagsRight overriding values from tagsLeft
Expand Down Expand Up @@ -792,3 +798,19 @@ func (s *histogramSnapshot) Values() map[float64]int64 {
func (s *histogramSnapshot) Durations() map[time.Duration]int64 {
return s.durations
}

func (s *histogramSnapshot) NumValues() int64 {
valCounter := 0
for _, val := range s.values {
valCounter += int(val)
}
return int64(valCounter)
}

func (s *histogramSnapshot) NumDurations() int64 {
durationCounter := 0
for _, val := range s.durations {
durationCounter += int(val)
}
return int64(durationCounter)
}
2 changes: 2 additions & 0 deletions scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,8 @@ func TestSnapshot(t *testing.T) {
)
assert.EqualValues(t, map[time.Duration]int64(nil), histograms["foo.fizz+env=test"].Durations())
assert.EqualValues(t, commonTags, histograms["foo.fizz+env=test"].Tags())
assert.Equal(t, histograms["foo.fizz+env=test"].NumValues(), int64(2))
fmt.Println(histograms["foo.fizz+env=test"].NumDurations())

assert.EqualValues(t, map[float64]int64(nil), histograms["foo.buzz+env=test"].Values())
assert.EqualValues(
Expand Down