mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-14 06:46:56 +00:00
fix(promql): drop metadata labels from date function results
Prometheus dateWrapper drops __type__ and __unit__ with __name__. Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -72,7 +72,7 @@ pub fn map_date(
|
||||
));
|
||||
};
|
||||
let mut metric = series.metric.clone();
|
||||
metric.remove("__name__");
|
||||
metric.remove_all(&METADATA_LABELS);
|
||||
let map = |seconds: f64| function.apply(go_int64(seconds));
|
||||
|
||||
let all_floats = series.fields.iter().all(|samples| {
|
||||
@@ -145,6 +145,9 @@ fn go_int64(value: f64) -> i64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Prometheus `schema.IsMetadataLabel`: the labels removed with the metric name.
|
||||
const METADATA_LABELS: [&str; 3] = ["__name__", "__type__", "__unit__"];
|
||||
|
||||
const SECONDS_PER_DAY: u64 = 86_400;
|
||||
const MARCH_THRU_DECEMBER: u32 = 306;
|
||||
const ABSOLUTE_YEARS: u64 = 292_277_022_400;
|
||||
|
||||
@@ -25,7 +25,7 @@ use datatypes::series::time::{EvalGrid, GridRange, GridSpec, TimeAxis};
|
||||
use super::{DateFunction, date_of_eval_time, map_date, time};
|
||||
use crate::grid_series::merge_same_labelset;
|
||||
use crate::grid_series::reference::{
|
||||
canonical_bits, golden_cases, labels_of, metric_of, points_of, series_of,
|
||||
Labels, canonical_bits, golden_cases, labels_of, metric_of, points_of, series_of,
|
||||
};
|
||||
|
||||
fn schema(grid: Arc<EvalGrid>) -> Arc<SeriesSchema> {
|
||||
@@ -108,9 +108,14 @@ fn map_date_drops_histograms_and_maps_chunks() {
|
||||
Series::try_new(
|
||||
&schema,
|
||||
metric_of(
|
||||
&[("__name__", "m"), ("host", "a")]
|
||||
.map(|(n, v)| (n.into(), v.into()))
|
||||
.into(),
|
||||
&[
|
||||
("__name__", "m"),
|
||||
("__type__", "gauge"),
|
||||
("__unit__", "seconds"),
|
||||
("host", "a"),
|
||||
]
|
||||
.map(|(n, v)| (n.into(), v.into()))
|
||||
.into(),
|
||||
),
|
||||
TimeAxis::Grid(range.clone()),
|
||||
SeriesFields::one(fields),
|
||||
@@ -150,7 +155,10 @@ fn map_date_drops_histograms_and_maps_chunks() {
|
||||
points_of(&hours),
|
||||
BTreeMap::from([(2, 1f64.to_bits()), (3, 2f64.to_bits())])
|
||||
);
|
||||
assert_eq!(hours.metric.name(), None);
|
||||
assert_eq!(
|
||||
labels_of(&hours.metric),
|
||||
Labels::from([("host".into(), "a".into())])
|
||||
);
|
||||
|
||||
let chunked = Samples::try_from_chunks(vec![floats(&[60.0]), floats(&[120.0, 180.0])]).unwrap();
|
||||
let minutes = map_date(DateFunction::Minute, &schema, &series(chunked))
|
||||
|
||||
Reference in New Issue
Block a user