Skip to content

Commit

Permalink
Ignore metrics read over prometheus with NaN value (#1231)
Browse files Browse the repository at this point in the history
* Skip reading counters and gauges with NaN value.

Signed-off-by: Caleb Metz <[email protected]>

* Spelling

Signed-off-by: Caleb Metz <[email protected]>

* Adds changelog entry

---------

Signed-off-by: Caleb Metz <[email protected]>
Co-authored-by: Scott Opell <[email protected]>
  • Loading branch information
cmetz100 and scottopell authored Feb 6, 2025
1 parent b06706c commit b7b446f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Introduced the ability for users to configure lading's sample rate,
configuration option `sample_period_milliseconds` in `lading.yaml`.
- Users can now configure expvar scraping on https endpoints, skipping certificate validation.
- Fixes issue when parsing `NaN` values from a prometheus endpoint

## [0.25.4]
## Changed
Expand Down
10 changes: 10 additions & 0 deletions lading/src/target_metrics/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ pub(crate) async fn scrape_metrics(
}
};

if value.is_nan() {
warn!("Skipping NaN gauge value");
continue;
}

gauge!(format!("target/{name}"), &all_labels.unwrap_or_default()).set(value);
}
Some(MetricType::Counter) => {
Expand All @@ -287,6 +292,11 @@ pub(crate) async fn scrape_metrics(
}
};

if value.is_nan() {
warn!("Skipping NaN counter value");
continue;
}

let value = if value < 0.0 {
warn!("Negative counter value unhandled");
continue;
Expand Down

0 comments on commit b7b446f

Please sign in to comment.