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
2 changes: 1 addition & 1 deletion consumer/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (si *statsItem) samplingInHour() {
value: atomic.LoadInt64(&si.value),
})
if si.csListDay.Len() > 25 {
si.csListHour.Remove(si.csListDay.Front())
si.csListDay.Remove(si.csListDay.Front())
}
}

Expand Down
16 changes: 16 additions & 0 deletions consumer/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,19 @@ func TestNewStatsManager(t *testing.T) {
}
stats.ShutDownStat()
}

// TestSamplingInHourTrimsDayList verifies that samplingInHour keeps the day
// snapshot list bounded. samplingInHour appends to csListDay, so it must also
// trim csListDay once it grows beyond 25 entries. A copy-paste slip that trimmed
// csListHour instead is a no-op (the removed element does not belong to
// csListHour), which lets csListDay grow without bound and corrupts the
// day-window statistics.
func TestSamplingInHourTrimsDayList(t *testing.T) {
si := newStatsItem("test", "key")
for i := 0; i < 30; i++ {
si.samplingInHour()
}
if got := si.csListDay.Len(); got != 25 {
Comment on lines +238 to +241
t.Errorf("csListDay should be capped at 25 after 30 samples, got=%d", got)
}
}