Skip to content

Commit

Permalink
fix(metrics): use f64::MAX as histogram bound to display +Inf properly (
Browse files Browse the repository at this point in the history
#16701)

* use f64::MAX as histogram bound

* add test
  • Loading branch information
flaneur2020 authored Oct 29, 2024
1 parent c44ea20 commit 00393c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/base/src/runtime/metrics/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ use crate::runtime::metrics::process_collector::ProcessCollector;
use crate::runtime::metrics::sample::MetricSample;
use crate::runtime::ThreadTracker;

pub const MIN_HISTOGRAM_BOUND: f64 = i64::MIN as f64;
pub const MAX_HISTOGRAM_BOUND: f64 = i64::MAX as f64;
pub const MIN_HISTOGRAM_BOUND: f64 = f64::MIN;
pub const MAX_HISTOGRAM_BOUND: f64 = f64::MAX;

pub static GLOBAL_METRICS_REGISTRY: LazyLock<GlobalRegistry> =
LazyLock::new(GlobalRegistry::create);
Expand Down
13 changes: 13 additions & 0 deletions src/common/base/tests/it/metrics/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ fn test_tracking_scoped_histogram_in_milliseconds_metrics() -> Result<()> {
Ok(())
}

#[test]
fn test_tracking_histogram_inf() -> Result<()> {
let uniq_metric_name = GlobalUniqName::unique();
let histogram = register_histogram_in_seconds(&uniq_metric_name);
// observe a value that exceed the max bucket of the histogram
histogram.observe(3600.0 * 355.0);

let output = GLOBAL_METRICS_REGISTRY.render_metrics()?;
let expected = format!("{}_bucket{{le=\"+Inf\"}} 1", uniq_metric_name);
assert!(output.contains(&expected));
Ok(())
}

#[test]
fn test_tracking_scoped_family_counter_metrics() -> Result<()> {
let uniq_metric_name = GlobalUniqName::unique();
Expand Down

0 comments on commit 00393c6

Please sign in to comment.