Skip to content

fix(aws_ecs_metrics source): skip over empty ECS metrics payloads #23151

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/skip_empty_ecs_metrics.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The `aws_ecs_metrics` source now skips over empty ECS metrics payloads. It previously failed to parse such payloads.

authors: tustvold
25 changes: 21 additions & 4 deletions src/sources/aws_ecs_metrics/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,27 @@ fn network_metrics(
.collect()
}

#[derive(Deserialize)]
#[serde(untagged, deny_unknown_fields)]
enum StatsPayload {
Container(ContainerStats),
Empty {},
Null,
}

pub(super) fn parse(
bytes: &[u8],
namespace: Option<String>,
) -> Result<Vec<Metric>, serde_json::Error> {
let mut metrics = Vec::new();
let parsed = serde_json::from_slice::<BTreeMap<String, ContainerStats>>(bytes)?;
let parsed = serde_json::from_slice::<BTreeMap<String, StatsPayload>>(bytes)?;

for (id, payload) in parsed {
let container = match payload {
StatsPayload::Container(container) => container,
_ => continue,
};

for (id, container) in parsed {
let mut tags = MetricTags::default();
tags.replace("container_id".into(), id);
if let Some(name) = container.name {
Expand Down Expand Up @@ -608,7 +621,9 @@ mod test {
"io_time_recursive": [],
"sectors_recursive": []
}
}
},
"123456789": {},
"123456789": null
}"#;

assert_event_data_eq!(
Expand Down Expand Up @@ -672,7 +687,9 @@ mod test {
"throttled_time": 0
}
}
}
},
"2344": {},
"test": null
}"#;

assert_event_data_eq!(
Expand Down
Loading