Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Calculate IntervalDelta correctly if there are no changes to the counter #128

Merged
merged 1 commit into from
Mar 15, 2021
Merged
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
2 changes: 1 addition & 1 deletion metrics/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *Counter) Value() int64 {

// IntervalValue allows to get last interval value for counter.
func (c *Counter) IntervalValue() int64 {
if c.lastIntervalDelta == 0 {
if c.lastIntervalValue == 0 {
return c.Value()
}
return atomic.LoadInt64(&c.lastIntervalDelta)
Expand Down
6 changes: 6 additions & 0 deletions metrics/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ func TestCounter(t *testing.T) {
cnt.Inc()
assert.Equal(t, int64(1501), cnt.Value())
assert.Equal(t, int64(1500), cnt.IntervalValue())
cnt.UpdateDelta()
assert.Equal(t, int64(1501), cnt.Value())
assert.Equal(t, int64(1), cnt.IntervalValue())
cnt.UpdateDelta()
assert.Equal(t, int64(1501), cnt.Value())
assert.Equal(t, int64(0), cnt.IntervalValue())
}