-
Notifications
You must be signed in to change notification settings - Fork 120
ref(relay): Limit maximum number of logs produced by expansion #6263
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -4,7 +4,8 @@ use relay_quotas::DataCategory; | |
| use crate::envelope::{ContainerItems, EnvelopeHeaders, Item, WithHeader}; | ||
| use crate::integrations::{Integration, LogsIntegration}; | ||
| use crate::managed::RecordKeeper; | ||
| use crate::processing::logs::Settings; | ||
| use crate::processing::logs::Error::TooManyExpandedLogs; | ||
| use crate::processing::logs::{Result, Settings}; | ||
|
|
||
| mod nel; | ||
| mod otel; | ||
|
|
@@ -17,6 +18,7 @@ pub fn expand( | |
| item: Item, | ||
| records: &mut RecordKeeper<'_>, | ||
| headers: &EnvelopeHeaders, | ||
| max_expanded_log_count: usize, | ||
| ) -> Option<(Settings, ContainerItems<OurLog>)> { | ||
| let integration = match item.integration() { | ||
| Some(Integration::Logs(integration)) => integration, | ||
|
|
@@ -27,7 +29,7 @@ pub fn expand( | |
| }; | ||
|
|
||
| let mut logs = Vec::new(); | ||
| let produce = |log: OurLog| { | ||
| let produce = |log: OurLog| -> Result<()> { | ||
| let byte_size = relay_ourlogs::calculate_size(&log); | ||
|
|
||
| records.modify_by(DataCategory::LogItem, 1); | ||
|
|
@@ -40,6 +42,12 @@ pub fn expand( | |
| }), | ||
| value: log.into(), | ||
| }); | ||
|
|
||
| if logs.len() > max_expanded_log_count { | ||
| return Err(TooManyExpandedLogs); | ||
| } | ||
|
Comment on lines
+46
to
+48
Member
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. I think this check isn't enough, as we're already deserializing (either via
Contributor
Author
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. So, it's the entire array, but we've only expanded (with accompanying attributes)
Member
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. Parsing is already too much. The amplification of attributes is just a bigger multiplier. The |
||
|
|
||
| Ok(()) | ||
|
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. Debug quantity mismatch on limitMedium Severity When expansion hits Additional Locations (1)Reviewed by Cursor Bugbot for commit 409e55f. Configure here. |
||
| }; | ||
|
|
||
| let payload = item.payload(); | ||
|
|
||


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.
max_expanded_log_countis only enforced for integrations, not log containersThe new
max_expanded_log_countlimit only applies to log integrations (OTel, Vercel, NEL) and not toLogItems::Container. A container with many small logs bypasses the count cap entirely, causing unbounded per-request CPU and memory usage during normalization, filtering, and scrubbing.Evidence
relay-server/src/processing/logs/process.rs:expand()receivesmax_expanded_log_countbut only passes it tointegrations::expand()forLogItems::Integration.LogItems::Container, it callsexpand_log_container()with no count parameter, so the cap is never checked.max_container_size(default 12 MB), but with small logs that still allows tens or hundreds of thousands of items—far above themax_expanded_log_countdefault of 1000.validate::size,normalize,filter,scrub, andnormalize_derivedwith no early count-based rejection, unlike the integration path whereproduce()returnsErr(TooManyExpandedLogs)once the cap is exceeded.Identified by Warden · wrdn-dos-review · MG4-3M7