Skip to content

Commit

Permalink
feat: accept empty metrics (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin de Berk <kevin@Kevins-MacBook-Pro.local>
  • Loading branch information
kdeberk and Kevin de Berk committed Nov 16, 2023
1 parent dbc36a9 commit f0e58b7
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit f0e58b7

Please sign in to comment.