Skip to content

Commit

Permalink
fix(metrics_summaries): Handle null values for optional fields (#6140)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Jul 24, 2024
1 parent 57f2059 commit 529d3ce
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions rust_snuba/src/processors/metrics_summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ pub fn process_message(
end_timestamp: from.end_timestamp as u64,
group,
is_segment: if from.is_segment { 1 } else { 0 },
max: from.max,
max: from.max.unwrap_or_default(),
metric_mri: from.mri,
min: from.min,
min: from.min.unwrap_or_default(),
project_id: from.project_id,
retention_days: enforce_retention(from.retention_days, &config.env_config),
segment_id,
span_id,
sum: from.sum,
sum: from.sum.unwrap_or_default(),
tag_keys,
tag_values,
trace_id: from.trace_id,
Expand All @@ -65,24 +65,23 @@ pub fn process_message(

#[derive(Debug, Default, Deserialize, JsonSchema)]
struct FromMetricsSummariesMessage<'a> {
#[serde(default)]
count: u64,
duration_ms: u32,
end_timestamp: f64,
group: &'a str,
is_segment: bool,
#[serde(default)]
max: f64,
max: Option<f64>,
#[serde(default)]
min: f64,
min: Option<f64>,
mri: &'a str,
project_id: u64,
received: f64,
retention_days: Option<u16>,
segment_id: &'a str,
span_id: &'a str,
#[serde(default)]
sum: f64,
sum: Option<f64>,
#[serde(default)]
tags: BTreeMap<String, String>,
trace_id: &'a str,
Expand Down Expand Up @@ -158,6 +157,42 @@ mod tests {
.expect("The message should be processed");
}

#[test]
fn test_summary_with_only_count() {
let summary = br#"{
"duration_ms": 1000,
"end_timestamp": 1691105878.72,
"group": "deadbeefdeadbeef",
"is_segment": false,
"mri": "c:sentry.events.outcomes@none",
"project_id": 1,
"received": 169110587919.123,
"retention_days": 90,
"segment_id": "deadbeefdeadbeef",
"span_id": "deadbeefdeadbeef",
"trace_id": "deadbeefdeadbeefdeadbeefdeadbeef",
"count": 1,
"tags": {
"category": "error",
"environment": "unknown",
"event_type": "error",
"outcome": "accepted",
"release": "backend@2af74c237fbd61489a1ccc46650f4f85befaf8b8",
"topic": "outcomes-billing",
"transaction": "sentry.tasks.store.save_event"
}
}"#;

let payload = KafkaPayload::new(None, None, Some(summary.to_vec()));
let meta = KafkaMessageMetadata {
partition: 0,
offset: 1,
timestamp: DateTime::from(SystemTime::now()),
};
process_message(payload, meta, &ProcessorConfig::default())
.expect("The message should be processed");
}

#[test]
fn schema() {
run_schema_type_test::<FromMetricsSummariesMessage>("snuba-metrics-summaries", None);
Expand Down

0 comments on commit 529d3ce

Please sign in to comment.