Skip to content

Commit ff9ad8b

Browse files
authored
fix(project-config): Only report error if processing enabled (#5436)
1 parent 7fb64fe commit ff9ad8b

File tree

5 files changed

+39
-32
lines changed

5 files changed

+39
-32
lines changed

relay-dynamic-config/src/project.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ pub struct ProjectConfig {
100100

101101
impl ProjectConfig {
102102
/// Validates fields in this project config and removes values that are partially invalid.
103-
pub fn sanitize(&mut self) {
104-
self.remove_invalid_quotas();
103+
pub fn sanitize(&mut self, report_errors: bool) {
104+
self.remove_invalid_quotas(report_errors);
105105

106106
metrics::convert_conditional_tagging(self);
107107
defaults::add_span_metrics(self);
@@ -113,34 +113,37 @@ impl ProjectConfig {
113113
for flag in GRADUATED_FEATURE_FLAGS {
114114
self.features.0.insert(*flag);
115115
}
116+
}
116117

117-
// Check if indexed and non-indexed are double-counting towards the same ID.
118-
// This is probably not intended behavior.
119-
for quota in &self.quotas {
120-
if let Some(id) = quota.id.as_deref() {
121-
for category in &*quota.categories {
122-
if let Some(indexed) = category.index_category()
123-
&& quota.categories.contains(&indexed)
124-
{
125-
relay_log::error!(
126-
tags.id = id,
127-
"Categories {category} and {indexed} share the same quota ID. This will double-count items.",
128-
);
118+
fn remove_invalid_quotas(&mut self, report_errors: bool) {
119+
let invalid_quotas: Vec<_> = self.quotas.extract_if(.., |q| !q.is_valid()).collect();
120+
if report_errors {
121+
if !invalid_quotas.is_empty() {
122+
{
123+
relay_log::warn!(
124+
invalid_quotas = ?invalid_quotas,
125+
"Found an invalid quota definition",
126+
);
127+
}
128+
}
129+
// Check if indexed and non-indexed are double-counting towards the same ID.
130+
// This is probably not intended behavior.
131+
for quota in &self.quotas {
132+
if let Some(id) = quota.id.as_deref() {
133+
for category in &*quota.categories {
134+
if let Some(indexed) = category.index_category()
135+
&& quota.categories.contains(&indexed)
136+
{
137+
relay_log::error!(
138+
tags.id = id,
139+
"Categories {category} and {indexed} share the same quota ID. This will double-count items.",
140+
);
141+
}
129142
}
130143
}
131144
}
132145
}
133146
}
134-
135-
fn remove_invalid_quotas(&mut self) {
136-
let invalid_quotas: Vec<_> = self.quotas.extract_if(.., |q| !q.is_valid()).collect();
137-
if !invalid_quotas.is_empty() {
138-
relay_log::warn!(
139-
invalid_quotas = ?invalid_quotas,
140-
"Found an invalid quota definition",
141-
);
142-
}
143-
}
144147
}
145148

146149
impl Default for ProjectConfig {
@@ -284,7 +287,7 @@ mod tests {
284287
fn graduated_feature_flag_gets_inserted() {
285288
let mut project_config = ProjectConfig::default();
286289
assert!(!project_config.features.has(Feature::UserReportV2Ingest));
287-
project_config.sanitize();
290+
project_config.sanitize(false);
288291
assert!(project_config.features.has(Feature::UserReportV2Ingest));
289292
}
290293
}

relay-server/src/metrics_extraction/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ mod tests {
196196
metric_extraction: metric_extraction.map(ErrorBoundary::Ok).unwrap_or_default(),
197197
..ProjectConfig::default()
198198
};
199-
project.sanitize(); // enables metrics extraction rules
199+
project.sanitize(false); // enables metrics extraction rules
200200
let project = project.metric_extraction.ok().unwrap();
201201

202202
OwnedConfig { global, project }

relay-server/src/services/projects/project/info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ impl ProjectInfo {
284284
}
285285

286286
/// Validates data in this project state and removes values that are partially invalid.
287-
pub fn sanitized(mut self) -> Self {
287+
pub fn sanitized(mut self, report_errors: bool) -> Self {
288288
relay_log::with_scope(
289289
|scope| scope.set_tag("project_id", self.project_id.map_or(0, ProjectId::value)),
290290
|| {
291-
self.config.sanitize();
291+
self.config.sanitize(report_errors);
292292
},
293293
);
294294
self

relay-server/src/services/projects/project/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ impl ProjectState {
4444
}
4545

4646
/// Runs a post-deserialization step to normalize the project config (e.g. legacy fields).
47-
pub fn sanitized(self) -> Self {
47+
pub fn sanitized(self, is_processing: bool) -> Self {
4848
match self {
49-
Self::Enabled(state) => Self::Enabled(Arc::new(state.as_ref().clone().sanitized())),
49+
Self::Enabled(state) => {
50+
Self::Enabled(Arc::new(state.as_ref().clone().sanitized(is_processing)))
51+
}
5052
Self::Disabled => Self::Disabled,
5153
Self::Pending => Self::Pending,
5254
}

relay-server/src/services/projects/source/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl ProjectSource {
7878
//
7979
// If it is pending, we must fallback to fetching from the upstream.
8080
Ok(SourceProjectState::New(state)) => {
81-
let state = state.sanitized();
81+
let state = state.sanitized(self.config.processing_enabled());
8282
if !state.is_pending() {
8383
return Ok(state.into());
8484
}
@@ -105,7 +105,9 @@ impl ProjectSource {
105105
.await?;
106106

107107
Ok(match state {
108-
SourceProjectState::New(state) => SourceProjectState::New(state.sanitized()),
108+
SourceProjectState::New(state) => {
109+
SourceProjectState::New(state.sanitized(self.config.processing_enabled()))
110+
}
109111
SourceProjectState::NotModified => SourceProjectState::NotModified,
110112
})
111113
}

0 commit comments

Comments
 (0)