mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-26 21:56:17 +00:00
fix(promql): preserve ordinary NaN samples (#8494)
* fix(promql): distinguish stale markers from NaN Signed-off-by: discord9 <discord9@163.com> * fix(promql): preserve ordinary NaN samples Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
@@ -17,6 +17,7 @@ pub mod error;
|
||||
pub mod logical_plan;
|
||||
pub mod native_histogram;
|
||||
pub mod prelude;
|
||||
pub mod prometheus;
|
||||
pub mod request;
|
||||
pub mod stream;
|
||||
#[cfg(any(test, feature = "testing"))]
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2023 Greptime Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// Canonical Prometheus stale-marker NaN bit pattern.
|
||||
pub const PROMETHEUS_STALE_NAN_BITS: u64 = 0x7ff0_0000_0000_0002;
|
||||
|
||||
/// Returns whether `value` is the canonical Prometheus stale-marker NaN.
|
||||
#[inline]
|
||||
pub fn is_prometheus_stale_nan(value: f64) -> bool {
|
||||
value.to_bits() == PROMETHEUS_STALE_NAN_BITS
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn recognizes_only_the_canonical_stale_marker() {
|
||||
assert!(is_prometheus_stale_nan(f64::from_bits(
|
||||
0x7ff0_0000_0000_0002
|
||||
)));
|
||||
assert!(!is_prometheus_stale_nan(f64::from_bits(
|
||||
0x7ff8_0000_0000_0000
|
||||
)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user