Skip to content
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

feat: accept empty metrics #30

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
10 changes: 9 additions & 1 deletion src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,20 @@ impl AggregationFamily {
)));
}

// Sometimes, either the family we set previously, or the family we're now merging with now only contain
// a #TYPE and #HELP line, but no actual metric values.
let new_is_empty = !new_family.iter_samples().any(|_| { true });
let old_is_empty = !self.base_family.iter_samples().any(|_| { true });

// We should clear the whole family if any of the samples has a clearmode="family" label
let should_clear_family = new_family.iter_samples().any(|metric| {
ClearMode::from_family(new_family.family_type.clone(), metric) == ClearMode::Family
});

if should_clear_family {
if new_is_empty {
return Ok(())
}
else if old_is_empty || should_clear_family {
self.base_family = new_family.without_label(CLEARMODE_LABEL_NAME).unwrap_or(new_family);
}
else {
Expand Down
Loading