Repository navigation
fix: trim csListDay instead of csListHour in statsItem.samplingInHour - #1242
Open
wang-jiahua wants to merge 1 commit into
Open
wang-jiahua wants to merge 1 commit into
wang-jiahua wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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 trimcsListDay(the list it appends to) when exceeding 25 entries. - Add a regression test ensuring
csListDayis 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
Fixes #1241
Brief Description
samplingInHour()pushes each snapshot intocsListDaybut trimscsListHour. Sincecontainer/list.Removeis a no-op for an element that belongs to another list,csListDayis never trimmed: it grows by one snapshot per hour per statsItem forever (slow leak), andgetStatsDataInDay()ends up computing over an ever-growing window instead of the intended ~25-hour one. The sibling methodssamplingInSeconds/samplingInMinutespush and trim the same list, so this is a one-line copy-paste slip:csListHour→csListDay.How Did You Test This Change?
TestSamplingInHourTrimsDayList: 30 calls on a fresh statsItem — unfixed yieldscsListDay.Len()==30(never trimmed, FAIL), fixed yields 25 (PASS).gofmt -lclean;go vetreports nothing new on the touched files.