Skip to content

Commit

Permalink
ref(statsd): Skip counter updates if the value is zero (#3747)
Browse files Browse the repository at this point in the history
No need to update a counter if the value is zero.
  • Loading branch information
Dav1dde authored Jun 19, 2024
1 parent cf3e3b1 commit 7043987
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion relay-server/src/services/processor/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub fn emit_feedback_metrics(envelope: &Envelope) {
_ => (),
}
}
if has_feedback && num_attachments > 0 {
if has_feedback {
metric!(counter(RelayCounters::FeedbackAttachments) += num_attachments);
}
}
Expand Down
38 changes: 24 additions & 14 deletions relay-statsd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,24 +529,34 @@ pub trait GaugeMetric {
macro_rules! metric {
// counter increment
(counter($id:expr) += $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
match $value {
value if value != 0 => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), value)
$(.with_tag(stringify!($k), $v))*
)
})
},
_ => {},
};
};

// counter decrement
(counter($id:expr) -= $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), -$value)
$(.with_tag(stringify!($k), $v))*
)
})
match $value {
value if value != 0 => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), -value)
$(.with_tag(stringify!($k), $v))*
)
})
},
_ => {},
};
};

// gauge set
Expand Down

0 comments on commit 7043987

Please sign in to comment.