-
Notifications
You must be signed in to change notification settings - Fork 804
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
Implement max bucket limit and automatic resolution reduction #6104
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -52,6 +52,9 @@ const ( | |
exemplarLabelsTooLong = "exemplar_labels_too_long" | ||
exemplarTimestampInvalid = "exemplar_timestamp_invalid" | ||
|
||
// Native Histogram specific validation reasons | ||
nativeHistogramBucketsExceeded = "native_histogram_buckets_exceeded" | ||
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. Can we make the error more specific like 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. Addressed in latest commit. |
||
|
||
// RateLimited is one of the values for the reason to discard samples. | ||
// Declared here to avoid duplication in ingester and distributor. | ||
RateLimited = "rate_limited" | ||
|
@@ -262,6 +265,59 @@ func ValidateMetadata(validateMetrics *ValidateMetrics, cfg *Limits, userID stri | |
return nil | ||
} | ||
|
||
func ValidateNativeHistogram(validateMetrics *ValidateMetrics, limits *Limits, userID string, ls []cortexpb.LabelAdapter, histogram cortexpb.Histogram) (cortexpb.Histogram, error) { | ||
if limits.MaxNativeHistogramBuckets == 0 { | ||
return histogram, nil | ||
} | ||
|
||
var ( | ||
exceedLimit bool | ||
) | ||
if histogram.IsFloatHistogram() { | ||
// Initial check to see if the bucket limit is exceeded or not. If not, we can avoid type casting. | ||
exceedLimit = len(histogram.PositiveCounts)+len(histogram.NegativeCounts) > limits.MaxNativeHistogramBuckets | ||
if !exceedLimit { | ||
return histogram, nil | ||
} | ||
// Exceed limit. | ||
if histogram.Schema <= cortexpb.ExponentialSchemaMin { | ||
validateMetrics.DiscardedSamples.WithLabelValues(nativeHistogramBucketsExceeded, userID).Inc() | ||
return cortexpb.Histogram{}, newHistogramBucketLimitExceededError(ls, limits.MaxNativeHistogramBuckets) | ||
} | ||
fh := cortexpb.FloatHistogramProtoToFloatHistogram(histogram) | ||
for len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > limits.MaxNativeHistogramBuckets { | ||
if fh.Schema <= cortexpb.ExponentialSchemaMin { | ||
validateMetrics.DiscardedSamples.WithLabelValues(nativeHistogramBucketsExceeded, userID).Inc() | ||
return cortexpb.Histogram{}, newHistogramBucketLimitExceededError(ls, limits.MaxNativeHistogramBuckets) | ||
} | ||
fh = fh.ReduceResolution(fh.Schema - 1) | ||
} | ||
// If resolution reduced, convert new float histogram to protobuf type again. | ||
return cortexpb.FloatHistogramToHistogramProto(histogram.TimestampMs, fh), nil | ||
} | ||
|
||
// Initial check to see if bucket limit is exceeded or not. If not, we can avoid type casting. | ||
exceedLimit = len(histogram.PositiveDeltas)+len(histogram.NegativeDeltas) > limits.MaxNativeHistogramBuckets | ||
if !exceedLimit { | ||
return histogram, nil | ||
} | ||
// Exceed limit. | ||
if histogram.Schema <= cortexpb.ExponentialSchemaMin { | ||
validateMetrics.DiscardedSamples.WithLabelValues(nativeHistogramBucketsExceeded, userID).Inc() | ||
return cortexpb.Histogram{}, newHistogramBucketLimitExceededError(ls, limits.MaxNativeHistogramBuckets) | ||
} | ||
h := cortexpb.HistogramProtoToHistogram(histogram) | ||
for len(h.PositiveBuckets)+len(h.NegativeBuckets) > limits.MaxNativeHistogramBuckets { | ||
if h.Schema <= cortexpb.ExponentialSchemaMin { | ||
validateMetrics.DiscardedSamples.WithLabelValues(nativeHistogramBucketsExceeded, userID).Inc() | ||
return cortexpb.Histogram{}, newHistogramBucketLimitExceededError(ls, limits.MaxNativeHistogramBuckets) | ||
} | ||
h = h.ReduceResolution(h.Schema - 1) | ||
} | ||
// If resolution reduced, convert new histogram to protobuf type again. | ||
return cortexpb.HistogramToHistogramProto(histogram.TimestampMs, h), nil | ||
} | ||
|
||
func DeletePerUserValidationMetrics(validateMetrics *ValidateMetrics, userID string, log log.Logger) { | ||
filter := map[string]string{"user": userID} | ||
|
||
|
This file contains 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
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.
nit: Can we add comment on what this function is doing?
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.
Addressed in latest commit.