From a44c449155038bc5d42d6337480c597b85e4975e Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 27 Nov 2024 13:08:34 +0100 Subject: [PATCH] promql: Add NaN tests for avg and avg_over_time Signed-off-by: beorn7 --- promql/promqltest/testdata/aggregators.test | 5 +++++ promql/promqltest/testdata/functions.test | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/promql/promqltest/testdata/aggregators.test b/promql/promqltest/testdata/aggregators.test index 244e69273..7479d2c3d 100644 --- a/promql/promqltest/testdata/aggregators.test +++ b/promql/promqltest/testdata/aggregators.test @@ -543,6 +543,7 @@ load 10s data{test="bigzero",point="b"} -9.988465674311579e+307 data{test="bigzero",point="c"} 9.988465674311579e+307 data{test="bigzero",point="d"} 9.988465674311579e+307 + data{test="value is nan"} NaN eval instant at 1m avg(data{test="ten"}) {} 10 @@ -577,6 +578,10 @@ eval instant at 1m avg(data{test="-big"}) eval instant at 1m avg(data{test="bigzero"}) {} 0 +# If NaN is in the mix, the result is NaN. +eval instant at 1m avg(data) + {} NaN + # Test summing and averaging extreme values. clear diff --git a/promql/promqltest/testdata/functions.test b/promql/promqltest/testdata/functions.test index e4caf0e36..1c832c89d 100644 --- a/promql/promqltest/testdata/functions.test +++ b/promql/promqltest/testdata/functions.test @@ -713,6 +713,7 @@ load 10s metric8 9.988465674311579e+307 9.988465674311579e+307 metric9 -9.988465674311579e+307 -9.988465674311579e+307 -9.988465674311579e+307 metric10 -9.988465674311579e+307 9.988465674311579e+307 + metric11 1 2 3 NaN NaN eval instant at 55s avg_over_time(metric[1m]) {} 3 @@ -806,6 +807,19 @@ eval instant at 45s sum_over_time(metric10[1m])/count_over_time(metric10[1m]) eval instant at 1m sum_over_time(metric10[2m])/count_over_time(metric10[2m]) {} 0 +# NaN behavior. +eval instant at 20s avg_over_time(metric11[1m]) + {} 2 + +eval instant at 30s avg_over_time(metric11[1m]) + {} NaN + +eval instant at 1m avg_over_time(metric11[1m]) + {} NaN + +eval instant at 1m sum_over_time(metric11[1m])/count_over_time(metric11[1m]) + {} NaN + # Test if very big intermediate values cause loss of detail. clear load 10s