Skip to content

fix: trim csListDay instead of csListHour in statsItem.samplingInHour - #1242

Open
wang-jiahua wants to merge 1 commit into
apache:masterfrom
wang-jiahua:fix/statistics-samplinginhour-wrong-list
Open

wang-jiahua wants to merge 1 commit into
apache:masterfrom
wang-jiahua:fix/statistics-samplinginhour-wrong-list

Conversation

@wang-jiahua

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #1241

Brief Description

samplingInHour() pushes each snapshot into csListDay but trims csListHour. Since container/list.Remove is a no-op for an element that belongs to another list, csListDay is never trimmed: it grows by one snapshot per hour per statsItem forever (slow leak), and getStatsDataInDay() ends up computing over an ever-growing window instead of the intended ~25-hour one. The sibling methods samplingInSeconds/samplingInMinutes push and trim the same list, so this is a one-line copy-paste slip: csListHour → csListDay.

How Did You Test This Change?

  • New regression test TestSamplingInHourTrimsDayList: 30 calls on a fresh statsItem — unfixed yields csListDay.Len()==30 (never trimmed, FAIL), fixed yields 25 (PASS).
  • Existing consumer statistics tests (PullRT/PullTPS/ConsumeOKTPS/ConsumeFailedTPS/GetConsumeStatus and the stats-manager soak) all pass; gofmt -l clean; go vet reports nothing new on the touched files.

Copilot AI lite review requested due to automatic review settings September 3, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Fixes a leak/logic bug in samplingInHour() where snapshots were appended to csListDay but trimming was mistakenly applied to csListHour, allowing the day list to grow unbounded and skew day-window stats.

Changes:

  • Fix samplingInHour() to trim csListDay (the list it appends to) when exceeding 25 entries.
  • Add a regression test ensuring csListDay is capped at 25 after repeated hourly samples.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
consumer/statistics.go Corrects list trimming to bound the day snapshot list.
consumer/statistics_test.go Adds regression test to prevent reintroduction of the trimming bug.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +238 to +241
for i := 0; i < 30; i++ {
si.samplingInHour()
}
if got := si.csListDay.Len(); got != 25 {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] statsItem.samplingInHour trims the wrong list, so csListDay grows without bound and day-level stats use an ever-growing window

2 participants