Repository navigation
Conversation
The discarded series trackers started a goroutine updating the cortex_discarded_series and cortex_discarded_series_per_labelset metrics which was never stopped, because it ranged over a ticker forever. Make the trackers stoppable, add ValidateMetrics.Stop() and call it when the distributor and the ingester stop. Stop the validate metrics in tests that create them directly or never start the ingester. This removes about 2500 goroutines leaked by the distributor, ingester and validation tests. Ref cortexproject#3962 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d Signed-off-by: Andrey Osipov <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d Signed-off-by: Andrey Osipov <[email protected]>
This branch has not been deployed
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.
What this PR does:
Stops the goroutines updating the
cortex_discarded_seriesandcortex_discarded_series_per_labelsetmetrics.DiscardedSeriesTrackerandDiscardedSeriesPerLabelsetTrackerstarted them withfor range ticker.C, so they ran forever, including after the distributor or ingester owning them stopped.metricsVendorwhich runs the update loop and exposesStop().Stop()waits for the goroutine to exit, and is safe to call more than once or when the goroutine was never started.ValidateMetrics.Stop()stops both trackers. The distributor and the ingester call it from their stopping functions.ValidateMetricsdirectly, or create an ingester without running its stopping function, now stop them.Running the
pkg/distributor,pkg/ingesterandpkg/util/validationtests withgoleak.VerifyTestMainreported about 2500 leaked tracker goroutines before this change (2044 in the distributor, 384 in the ingester, 82 in validation) and none after.As with #7977, the stopping function doesn't run when the distributor or ingester fails to start, so the goroutines are still left running in that case. A failed start ends the process in production, so I kept this out of scope.
Which issue(s) this PR fixes:
Part of #3962
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flagsAI disclosure: per GENAI_POLICY.md, the leak survey, the fix and the tests were prepared with Claude Code. I reviewed and verified the changes.
🤖 Generated with Claude Code