apache / apache/rocketmq-client-go
[Bug] statsItem.samplingInHour trims the wrong list, so csListDay grows without bound and day-level stats use an ever-growing window
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 445
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
`statsItem.samplingInHour()` in `consumer/statistics.go` appends a snapshot to `csListDay` but trims `csListHour`:
```go
si.csListDay.PushBack(callSnapshot{...})
if si.csListDay.Len() > 25 {
si.csListHour.Remove(si.csListDay.Front()) // wrong list
}
```
`container/list.Remove(e)` is a no-op when `e` does not belong to that list, so nothing is ever removed: `csListDay` grows by one snapshot per hour per statsItem forever. The sibling methods `samplingInSeconds`/`samplingInMinutes` push and trim the same list, which shows this is a copy-paste slip.
### Steps to Reproduce
Call `samplingInHour()` 30 times on a fresh `statsItem`; `csListDay.Len()` is 30 instead of the intended cap 25.
### What Did You Expect to See?
`csListDay` capped at 25 entries (a ~25-hour sliding window for the day-level stats).
### What Did You See Instead?
Unbounded growth (slow memory leak, one snapshot per hour per topic/group statsItem), and `getStatsDataInDay()` computes over an ever-growing window instead of the intended ~25-hour one, skewing day-level TPS/AVGPT.
### Additional Context
Fix incoming: `si.csListDay.Remove(si.csListDay.Front())`, aligning with the sibling sampling methods; includes a regression test.
Contributor guide
Research direction
Start in consumer/statistics.go at statsItem.samplingInHour(), then compare its list handling with samplingInSeconds and samplingInMinutes. Reproduce 30 hourly samples on a fresh statsItem and add the regression test; done means csListDay remains capped at 25 and day-level statistics use that bounded window.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100