-
Notifications
You must be signed in to change notification settings - Fork 79
Add maxSamples limit #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add maxSamples limit #663
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c169c9
max samples limit
PaurushGarg 8098487
Update max_samples tracking to selector operators
PaurushGarg 1fc6e89
Update to check maxSamples more frequently
PaurushGarg 734630c
Updating maxSample check interval steps
PaurushGarg 1a7cf64
Add unit tests for max_samples
PaurushGarg 975cce8
Apply linter formatting
PaurushGarg 8945224
Update SubQuery Sample tracker to inner loop and remove update matrix…
PaurushGarg 418afb2
Remove Checking when delta is negative in matrix_selector
PaurushGarg 639ec0f
convert SampleTracker to interface with nop implementation
PaurushGarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) The Thanos Community Authors. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| package query | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sync/atomic" | ||
| ) | ||
|
|
||
| type SampleTracker struct { | ||
| current atomic.Int64 | ||
| limit int64 | ||
| } | ||
|
|
||
| func NewSampleTracker(maxSamples int) *SampleTracker { | ||
| return &SampleTracker{ | ||
| limit: int64(maxSamples), | ||
| } | ||
| } | ||
|
|
||
| func (st *SampleTracker) Add(count int) { | ||
| st.current.Add(int64(count)) | ||
| } | ||
|
|
||
| func (st *SampleTracker) Remove(count int) { | ||
| st.current.Add(-int64(count)) | ||
| } | ||
|
|
||
| func (st *SampleTracker) CheckLimit() error { | ||
| if st.limit <= 0 { | ||
| return nil | ||
| } | ||
| current := st.current.Load() | ||
| if current > st.limit { | ||
| return ErrMaxSamplesExceeded{Current: current, Limit: st.limit} | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (st *SampleTracker) Limit() int64 { | ||
| return st.limit | ||
| } | ||
|
|
||
| type ErrMaxSamplesExceeded struct { | ||
| Current int64 | ||
| Limit int64 | ||
| } | ||
|
|
||
| func (e ErrMaxSamplesExceeded) Error() string { | ||
| return fmt.Sprintf("query processing would load too many samples into memory: current=%d, limit=%d", e.Current, e.Limit) | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it strange that we apply this limit in subqueries. They operate on existing samples and do not produce new ones.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selectors reuse the same buffer each next, while subqueries accumulate samples in ring buffers that persist across the evaluation window.
For rate(http_requests[10m])[2d:1m], the inner selector loads samples and releases them, but the subquery keeps accumulating those in buffers for the full 2d window.