Skip to content

Add new limit: max_series_label_size_bytes #4848

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

Conversation

harry671003
Copy link
Contributor

Signed-off-by: 🌲 Harry 🌊 John 🏔 [email protected]

What this PR does:
This PR introduces a new limit max_series_label_size_bytes.
Currently, it is possible for users of Cortex to OOM kill distributors and ingesters by increasing the size of each label and label value. For instance, a user can send 1 million series with each series having 30 labels of maximum size. 1 million * 30 labels * 3 KB per label = 85 GB.

This new limit can prevent this from happening by rejecting series that have a combined label size greater than this limit.
Example: if the max_series_label_size_bytes is set to 10 KB, any series that exceed will be rejected. 1 million active series for a user will consume 1 million * 10 KB = 9 GB.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@harry671003 harry671003 force-pushed the new_limit_series_bytes branch 2 times, most recently from 8f0f943 to 4c38c22 Compare September 1, 2022 18:52
Comment on lines 241 to 249
maxSeriesLabelSizeBytesMutex.Lock()
defer maxSeriesLabelSizeBytesMutex.Unlock()
if prev, ok := maxSeriesLabelSizeBytesMap[userID]; ok {
if prev > maxSeriesLabelSizeBytes {
maxSeriesLabelSizeBytesMap[userID] = maxSeriesLabelSizeBytes
MaxSeriesLabelSizeBytesPerUser.WithLabelValues(userID).Set(float64(maxSeriesLabelSizeBytes))
}
} else {
maxSeriesLabelSizeBytesMap[userID] = maxSeriesLabelSizeBytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im worried about this lock here!

Could we do this not on the hot path? Maybe use a defer or even do it on compactor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the use case for these metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we can enable this, we need to make sure existing users are not impacted. This metrics provide a way to monitor the current largest series in terms of total bytes that each user have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this metric for now. The plan is to add it later in the private repo and not upstream.

# Maximum combined size in bytes of all labels and label values accepted for a
# series. 0 to disable the limit.
# CLI flag: -validation.max-series-label-size-bytes
[max_series_label_size_bytes: <int> | default = 0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be in consistent naming with other label limits and have the config name to be max_labels_size_bytes

Copy link
Contributor Author

@harry671003 harry671003 Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the flag and config to max_labels_size_bytes

@harry671003 harry671003 force-pushed the new_limit_series_bytes branch from 4c38c22 to 343aff9 Compare September 2, 2022 16:35
@pull-request-size pull-request-size bot added size/M and removed size/L labels Sep 2, 2022
@harry671003 harry671003 force-pushed the new_limit_series_bytes branch from 343aff9 to 2016332 Compare September 2, 2022 16:41
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
@harry671003 harry671003 force-pushed the new_limit_series_bytes branch from 2016332 to 8f55ff9 Compare September 2, 2022 16:44
@alvinlin123 alvinlin123 merged commit a27f06b into cortexproject:master Sep 2, 2022
@alvinlin123
Copy link
Contributor

Thanks for the contribution @harry671003 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants