mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 00:23:18 +00:00
Convert TestTimestampFunction_StepsMoreOftenThanSamples
Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
parent
987fa5c6a2
commit
aeec30f082
@ -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{}
|
||||
|
8
promql/promqltest/testdata/functions.test
vendored
8
promql/promqltest/testdata/functions.test
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user