Skip to content

Commit 7ea9f17

Browse files
authored
fix: drop negative counter inc (#336)
1 parent 89b6e59 commit 7ea9f17

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

unleash-yggdrasil/src/impact_metrics/counter.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ impl Counter {
3131
}
3232

3333
fn inc_internal(&self, value: i64, labels: Option<&MetricLabels>) {
34+
if value <= 0 {
35+
return;
36+
}
3437
let key = get_label_key(labels);
3538
self.values
3639
.entry(key)

unleash-yggdrasil/src/impact_metrics/registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ mod tests {
225225
let lbls = labels(&[("foo", "bar")]);
226226
registry.inc_counter_with_labels("labeled_counter", 3, &lbls);
227227
registry.inc_counter_with_labels("labeled_counter", 2, &lbls);
228+
registry.inc_counter_with_labels("labeled_counter", -1, &lbls); // dropped
228229

229230
let metrics = registry.collect();
230231
let expected = CollectedMetric::new_counter(

0 commit comments

Comments
 (0)