From 2185f841e5f1681f6c757dd26af79ce71cec41a4 Mon Sep 17 00:00:00 2001 From: Jon Kartago Lamida Date: Tue, 28 Jan 2025 00:21:00 +0800 Subject: [PATCH] Add more time tests Signed-off-by: Jon Kartago Lamida --- .../testdata/ours/functions.test | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/streamingpromql/testdata/ours/functions.test b/pkg/streamingpromql/testdata/ours/functions.test index ef1ada5e28..88dbc02516 100644 --- a/pkg/streamingpromql/testdata/ours/functions.test +++ b/pkg/streamingpromql/testdata/ours/functions.test @@ -693,24 +693,28 @@ eval range from 0 to 7m step 1m year() eval range from 0 to 7m step 1m time() {} 0 60 120 180 240 300 360 420 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m year(vector(1136239445)) {} 2006 2006 2006 2006 2006 2006 2006 2006 eval range from 0 to 7m step 1m month() {} 1 1 1 1 1 1 1 1 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m month(vector(1136239445)) {} 1 1 1 1 1 1 1 1 eval range from 0 to 7m step 1m day_of_month() {} 1 1 1 1 1 1 1 1 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m day_of_month(vector(1136239445)) {} 2 2 2 2 2 2 2 2 eval range from 0 to 7m step 1m day_of_year() {} 1 1 1 1 1 1 1 1 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m day_of_year(vector(1136239445)) {} 2 2 2 2 2 2 2 2 @@ -718,18 +722,21 @@ eval range from 0 to 7m step 1m day_of_year(vector(1136239445)) eval range from 0 to 7m step 1m day_of_week() {} 4 4 4 4 4 4 4 4 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m day_of_week(vector(1136239445)) {} 1 1 1 1 1 1 1 1 eval range from 0 to 7m step 1m hour() {} 0 0 0 0 0 0 0 0 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m hour(vector(1136239445)) {} 22 22 22 22 22 22 22 22 eval range from 0 to 7m step 1m minute() {} 0 1 2 3 4 5 6 7 +# 2006-01-02 22:04:05 eval range from 0 to 7m step 1m minute(vector(1136239445)) {} 4 4 4 4 4 4 4 4 @@ -783,3 +790,35 @@ eval range from 0 to 7m step 1m month(histogram_sample) eval range from 0 to 7m step 1m year(histogram_sample) clear + +# Test time with custom metric +# 1136239445: 2006-01-02 22:04:05 +# 1485907200: February 1st 2017 not in leap year. +# 1672493820: 2022-12-31 13:37:00 365th day in non-leap year. +load 1m + some_metric{case="series1"} 0+1136239445x7 + another_metric{case="series1"} 0+536254375x7 + some_metric{case="series2"} 0+1672493820x7 + some_metric{case="gap1"} _ 1136239445 _ 1485907200 _ 1672493820 + some_metric{case="gap2"} 1136239445 _ _ 1485907200 _ _ 1672493820 + some_metric{case="histogram-gap"} _ {{count:5}} _ {{count:5}} + some_metric{case="histogram-float"} 1136239445x7 {{count:5}} 1485907200 {{count:5}} + +eval range from 0 to 7m step 1m year(some_metric) + {case="gap1"} _ 2006 2006 2017 2017 2022 2022 2022 + {case="gap2"} 2006 2006 2006 2017 2017 2017 2022 2022 + {case="histogram-float"} 2006 2006 2006 2006 2006 2006 2006 2006 + {case="series1"} 1970 2006 2042 2078 2114 2150 2186 2222 + {case="series2"} 1970 2022 2075 2128 2181 2234 2287 2340 + +eval range from 0 to 7m step 1m month(some_metric) + {case="gap1"} _ 1 1 2 2 12 12 12 + {case="gap2"} 1 1 1 2 2 2 12 12 + {case="histogram-float"} 1 1 1 1 1 1 1 1 + {case="series1"} 1 1 1 1 1 1 1 1 + {case="series2"} 1 12 12 12 12 12 12 12 + +eval range from 0 to 7m step 1m year(some_metric{case="series1"} + another_metric{case="series1"}) + {case="series1"} 1970 2022 2075 2128 2181 2234 2287 2340 + +clear