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

Do not suppress 0 values #11

Open
wants to merge 1 commit into
base: main
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
13 changes: 8 additions & 5 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ impl StatsdBuilder {
///
/// Refer to the documentation for [`MetricKindMask`](metrics_util::MetricKindMask) for more
/// information on defining a metric kind mask.
///
/// When a metric is rendered its value is replaced with a "zero-value" for that `MetricKind`
/// however any metric with a state "zero-value" will not be rendered and will be cleaned up
/// when its corresponding idle timeout expires.
#[must_use]
pub fn idle_timeout(mut self, mask: MetricKindMask, timeout: Option<Duration>) -> Self {
self.idle_timeout = timeout;
Expand Down Expand Up @@ -614,7 +610,12 @@ mod tests {
gauge1.set(-3.44);
let rendered = handle.render();
// each render call will reset the value of the counter
let expected_gauge = "basic.gauge:-3.44|g|#wutang:forever\n\n";
let expected_gauge = concat!(
"basic.counter:0|c\n",
"\n",
"basic.gauge:-3.44|g|#wutang:forever\n",
"\n",
);
assert_eq!(rendered, expected_gauge);

let key = Key::from_name("basic.histogram");
Expand All @@ -623,6 +624,8 @@ mod tests {
let rendered = handle.render();

let histogram_data = concat!(
"basic.counter:0|c\n\n",
"basic.gauge:-3.44|g|#wutang:forever\n\n",
"basic.histogram.min:12|g\n",
"basic.histogram.max:12|g\n",
"basic.histogram.avg:12|g\n",
Expand Down
14 changes: 1 addition & 13 deletions src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Inner {
}

let (name, labels) = key_to_parts(&key, Some(&self.global_tags));
let value = f64::from_bits(gauge.get_inner().swap(0, Ordering::Acquire));
let value = f64::from_bits(gauge.get_inner().load(Ordering::Acquire));
let entry = gauges
.entry(name)
.or_insert_with(HashMap::new)
Expand Down Expand Up @@ -103,9 +103,6 @@ impl Inner {
for (name, mut by_labels) in counters.drain() {
let mut wrote = false;
for (labels, value) in by_labels.drain() {
if value == 0 {
continue;
}
wrote = true;
write_metric_line::<&str, u64>(
&mut output,
Expand All @@ -128,9 +125,6 @@ impl Inner {
for (name, mut by_labels) in gauges.drain() {
let mut wrote = false;
for (labels, value) in by_labels.drain() {
if value == 0.0 {
continue;
}
wrote = true;
write_metric_line::<&str, f64>(
&mut output,
Expand All @@ -156,9 +150,6 @@ impl Inner {
let (sum, count) = match distribution {
Distribution::Summary(summary, quantiles, sum) => {
let count = summary.count();
if count == 0 {
continue;
}
wrote = true;
let snapshot = summary.snapshot(Instant::now());
for quantile in quantiles.iter() {
Expand Down Expand Up @@ -192,9 +183,6 @@ impl Inner {
}
Distribution::Histogram(histogram) => {
let count = histogram.count();
if count == 0 {
continue;
}
wrote = true;
for (le, count) in histogram.buckets() {
write_metric_line(
Expand Down