From aeec30f082012b3f3445d51ecdc30dfb15790a45 Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Mon, 17 Jun 2024 16:56:56 +1000 Subject: [PATCH] Convert `TestTimestampFunction_StepsMoreOftenThanSamples` Signed-off-by: Charles Korn --- promql/engine_test.go | 41 ----------------------- promql/promqltest/testdata/functions.test | 8 +++++ 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/promql/engine_test.go b/promql/engine_test.go index 2d13500b1..4e321a6c3 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -2015,47 +2015,6 @@ func TestSubquerySelector(t *testing.T) { } } -func TestTimestampFunction_StepsMoreOftenThanSamples(t *testing.T) { - engine := newTestEngine() - storage := promqltest.LoadedStorage(t, ` -load 1m - metric 0+1x1000 -`) - t.Cleanup(func() { storage.Close() }) - - query := "timestamp(metric)" - start := time.Unix(0, 0) - end := time.Unix(61, 0) - interval := time.Second - - // We expect the value to be 0 for t=0s to t=59s (inclusive), then 60 for t=60s and t=61s. - expectedPoints := []promql.FPoint{} - - for t := 0; t <= 59; t++ { - expectedPoints = append(expectedPoints, promql.FPoint{F: 0, T: int64(t * 1000)}) - } - - expectedPoints = append( - expectedPoints, - promql.FPoint{F: 60, T: 60_000}, - promql.FPoint{F: 60, T: 61_000}, - ) - - expectedResult := promql.Matrix{ - promql.Series{ - Floats: expectedPoints, - Metric: labels.EmptyLabels(), - }, - } - - qry, err := engine.NewRangeQuery(context.Background(), storage, nil, query, start, end, interval) - require.NoError(t, err) - - res := qry.Exec(context.Background()) - require.NoError(t, res.Err) - testutil.RequireEqual(t, expectedResult, res.Value) -} - type FakeQueryLogger struct { closed bool logs []interface{} diff --git a/promql/promqltest/testdata/functions.test b/promql/promqltest/testdata/functions.test index 2c198374a..7e741e995 100644 --- a/promql/promqltest/testdata/functions.test +++ b/promql/promqltest/testdata/functions.test @@ -1213,3 +1213,11 @@ eval instant at 5m log10(exp_root_log - 20) {l="y"} -Inf clear + +# Test that timestamp() handles the scenario where there are more steps than samples. +load 1m + metric 0+1x1000 + +# We expect the value to be 0 for t=0s to t=59s (inclusive), then 60 for t=60s and t=61s. +eval range from 0 to 61s step 1s timestamp(metric) + {} 0x59 60 60