-
Notifications
You must be signed in to change notification settings - Fork 684
Deduplicate identical series labels and track their memory consumption in QueryLimiter.AddSeries #13806
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
base: main
Are you sure you want to change the base?
Deduplicate identical series labels and track their memory consumption in QueryLimiter.AddSeries #13806
Changes from all commits
702052b
c13a469
a09dc6e
af8d7a1
5e28f24
996cf95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -74,17 +74,18 @@ func QueryLimiterFromContextWithFallback(ctx context.Context) *QueryLimiter { | |||||
| } | ||||||
|
|
||||||
| // AddSeries adds the input series and returns an error if the limit is reached. | ||||||
| func (ql *QueryLimiter) AddSeries(seriesLabels labels.Labels) validation.LimitError { | ||||||
| func (ql *QueryLimiter) AddSeries(seriesLabels labels.Labels) (bool, validation.LimitError) { | ||||||
| // If the max series is unlimited just return without managing map | ||||||
| if ql.maxSeriesPerQuery == 0 { | ||||||
| return nil | ||||||
| return false, nil | ||||||
| } | ||||||
| fingerprint := seriesLabels.Hash() | ||||||
|
|
||||||
| ql.uniqueSeriesMx.Lock() | ||||||
| defer ql.uniqueSeriesMx.Unlock() | ||||||
|
|
||||||
| uniqueSeriesBefore := len(ql.uniqueSeries) | ||||||
| _, duplicated := ql.uniqueSeries[fingerprint] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other thing we should do here: we'll need to handle hash collisions. |
||||||
| ql.uniqueSeries[fingerprint] = struct{}{} | ||||||
| uniqueSeriesAfter := len(ql.uniqueSeries) | ||||||
|
|
||||||
|
|
@@ -94,9 +95,9 @@ func (ql *QueryLimiter) AddSeries(seriesLabels labels.Labels) validation.LimitEr | |||||
| ql.queryMetrics.QueriesRejectedTotal.WithLabelValues(stats.RejectReasonMaxSeries).Inc() | ||||||
| } | ||||||
|
|
||||||
| return NewMaxSeriesHitLimitError(uint64(ql.maxSeriesPerQuery)) | ||||||
| return duplicated, NewMaxSeriesHitLimitError(uint64(ql.maxSeriesPerQuery)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| return nil | ||||||
| return duplicated, nil | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| // uniqueSeriesCount returns the count of unique series seen by this query limiter. | ||||||
|
|
||||||
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.