-
Notifications
You must be signed in to change notification settings - Fork 692
Adds push limits on profiles data #2157
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fcf2381
Adds push limits on profiles data
cyriltovena c6d5234
generate cmd help
cyriltovena fa9636f
Merge remote-tracking branch 'origin/next' into feat/push-limits
cyriltovena 11d2050
make reference-help
cyriltovena 9c3446d
Tweak default based on review feedback
cyriltovena b7f97b1
Tweak default based on review feedback
cyriltovena 1581b48
regenerate the doc
cyriltovena c372dd2
Merge remote-tracking branch 'origin/next' into feat/push-limits
cyriltovena 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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/common/model" | ||
|
||
googlev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1" | ||
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1" | ||
phlaremodel "github.com/grafana/pyroscope/pkg/model" | ||
"github.com/grafana/pyroscope/pkg/util" | ||
|
@@ -42,8 +43,9 @@ const ( | |
DuplicateLabelNames Reason = "duplicate_label_names" | ||
// SeriesLimit is a reason for discarding lines when we can't create a new stream | ||
// because the limit of active streams has been reached. | ||
SeriesLimit Reason = "series_limit" | ||
QueryLimit Reason = "query_limit" | ||
SeriesLimit Reason = "series_limit" | ||
QueryLimit Reason = "query_limit" | ||
InvalidProfile Reason = "invalid_profile" | ||
|
||
SeriesLimitErrorMsg = "Maximum active series limit exceeded (%d/%d), reduce the number of active streams (reduce labels or reduce label values), or contact your administrator to see if the limit can be increased" | ||
MissingLabelsErrorMsg = "error at least one label pair is required per profile" | ||
|
@@ -53,6 +55,9 @@ const ( | |
LabelValueTooLongErrorMsg = "profile with labels '%s' has label value too long: '%s'" | ||
DuplicateLabelNamesErrorMsg = "profile with labels '%s' has duplicate label name: '%s'" | ||
QueryTooLongErrorMsg = "the query time range exceeds the limit (query length: %s, limit: %s)" | ||
ProfileTooBigErrorMsg = "the profile with labels '%s' size exceeds the limit (profile size: %d, limit: %d)" | ||
ProfileTooManySamplesErrorMsg = "the profile with labels '%s' size exceeds the samples limit (actual: %d, limit: %d)" | ||
ProfileTooManyLabelsErrorMsg = "the profile with labels '%s' size exceeds the sample labels limit (actual: %d, limit: %d)" | ||
) | ||
|
||
var ( | ||
|
@@ -122,6 +127,47 @@ func ValidateLabels(limits LabelValidationLimits, userID string, ls []*typesv1.L | |
return nil | ||
} | ||
|
||
type ProfileValidationLimits interface { | ||
MaxProfileSizeBytes(userID string) int | ||
MaxProfileStacktraceSamples(userID string) int | ||
MaxProfileStacktraceSampleLabels(userID string) int | ||
MaxProfileStacktraceDepth(userID string) int | ||
MaxProfileSymbolValueLength(userID string) int | ||
} | ||
|
||
func ValidateProfile(limits ProfileValidationLimits, userID string, prof *googlev1.Profile, uncompressedSize int, ls phlaremodel.Labels) error { | ||
if prof == nil { | ||
return nil | ||
} | ||
if limit := limits.MaxProfileSizeBytes(userID); limit != 0 && uncompressedSize > limit { | ||
return NewErrorf(InvalidProfile, ProfileTooBigErrorMsg, phlaremodel.LabelPairsString(ls), uncompressedSize, limit) | ||
} | ||
if limit, size := limits.MaxProfileStacktraceSamples(userID), len(prof.Sample); limit != 0 && size > limit { | ||
return NewErrorf(InvalidProfile, ProfileTooManySamplesErrorMsg, phlaremodel.LabelPairsString(ls), size, limit) | ||
} | ||
var ( | ||
depthLimit = limits.MaxProfileStacktraceDepth(userID) | ||
labelsLimit = limits.MaxProfileStacktraceSampleLabels(userID) | ||
symbolLengthLimit = limits.MaxProfileSymbolValueLength(userID) | ||
) | ||
for _, s := range prof.Sample { | ||
|
||
if depthLimit != 0 && len(s.LocationId) > depthLimit { | ||
// truncate the deepest frames | ||
s.LocationId = s.LocationId[:depthLimit] | ||
} | ||
Comment on lines
+155
to
+158
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. It would be nice to have a stub like "other" – I think it could be a separate PR |
||
if labelsLimit != 0 && len(s.Label) > labelsLimit { | ||
return NewErrorf(InvalidProfile, ProfileTooManyLabelsErrorMsg, phlaremodel.LabelPairsString(ls), len(s.Label), labelsLimit) | ||
} | ||
} | ||
for i := range prof.StringTable { | ||
if symbolLengthLimit != 0 && len(prof.StringTable[i]) > symbolLengthLimit { | ||
prof.StringTable[i] = prof.StringTable[i][len(prof.StringTable[i])-symbolLengthLimit:] | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func isValidServiceName(serviceNameValue string) bool { | ||
return serviceNameValue != "" | ||
} | ||
|
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
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 just have realised that this truncates parent locations... This may make the flamegraph unreadable. I guess we could achieve better results with cutting the stack tip:
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.
Yeah that wasn't intentional, let's fix it.