mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Convert range query test cases to test scripting language
Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
parent
4c1e71fa0b
commit
987fa5c6a2
|
@ -3061,167 +3061,6 @@ func TestEngineOptsValidation(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRangeQuery(t *testing.T) {
|
||||
cases := []struct {
|
||||
Name string
|
||||
Load string
|
||||
Query string
|
||||
Result parser.Value
|
||||
Start time.Time
|
||||
End time.Time
|
||||
Interval time.Duration
|
||||
}{
|
||||
{
|
||||
Name: "sum_over_time with all values",
|
||||
Load: `load 30s
|
||||
bar 0 1 10 100 1000`,
|
||||
Query: "sum_over_time(bar[30s])",
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 0, T: 0}, {F: 11, T: 60000}, {F: 1100, T: 120000}},
|
||||
Metric: labels.EmptyLabels(),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(120, 0),
|
||||
Interval: 60 * time.Second,
|
||||
},
|
||||
{
|
||||
Name: "sum_over_time with trailing values",
|
||||
Load: `load 30s
|
||||
bar 0 1 10 100 1000 0 0 0 0`,
|
||||
Query: "sum_over_time(bar[30s])",
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 0, T: 0}, {F: 11, T: 60000}, {F: 1100, T: 120000}},
|
||||
Metric: labels.EmptyLabels(),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(120, 0),
|
||||
Interval: 60 * time.Second,
|
||||
},
|
||||
{
|
||||
Name: "sum_over_time with all values long",
|
||||
Load: `load 30s
|
||||
bar 0 1 10 100 1000 10000 100000 1000000 10000000`,
|
||||
Query: "sum_over_time(bar[30s])",
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 0, T: 0}, {F: 11, T: 60000}, {F: 1100, T: 120000}, {F: 110000, T: 180000}, {F: 11000000, T: 240000}},
|
||||
Metric: labels.EmptyLabels(),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(240, 0),
|
||||
Interval: 60 * time.Second,
|
||||
},
|
||||
{
|
||||
Name: "sum_over_time with all values random",
|
||||
Load: `load 30s
|
||||
bar 5 17 42 2 7 905 51`,
|
||||
Query: "sum_over_time(bar[30s])",
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 5, T: 0}, {F: 59, T: 60000}, {F: 9, T: 120000}, {F: 956, T: 180000}},
|
||||
Metric: labels.EmptyLabels(),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(180, 0),
|
||||
Interval: 60 * time.Second,
|
||||
},
|
||||
{
|
||||
Name: "metric query",
|
||||
Load: `load 30s
|
||||
metric 1+1x4`,
|
||||
Query: "metric",
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 1, T: 0}, {F: 3, T: 60000}, {F: 5, T: 120000}},
|
||||
Metric: labels.FromStrings("__name__", "metric"),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(120, 0),
|
||||
Interval: 1 * time.Minute,
|
||||
},
|
||||
{
|
||||
Name: "metric query with trailing values",
|
||||
Load: `load 30s
|
||||
metric 1+1x8`,
|
||||
Query: "metric",
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 1, T: 0}, {F: 3, T: 60000}, {F: 5, T: 120000}},
|
||||
Metric: labels.FromStrings("__name__", "metric"),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(120, 0),
|
||||
Interval: 1 * time.Minute,
|
||||
},
|
||||
{
|
||||
Name: "short-circuit",
|
||||
Load: `load 30s
|
||||
foo{job="1"} 1+1x4
|
||||
bar{job="2"} 1+1x4`,
|
||||
Query: `foo > 2 or bar`,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 1, T: 0}, {F: 3, T: 60000}, {F: 5, T: 120000}},
|
||||
Metric: labels.FromStrings(
|
||||
"__name__", "bar",
|
||||
"job", "2",
|
||||
),
|
||||
},
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 3, T: 60000}, {F: 5, T: 120000}},
|
||||
Metric: labels.FromStrings(
|
||||
"__name__", "foo",
|
||||
"job", "1",
|
||||
),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(120, 0),
|
||||
Interval: 1 * time.Minute,
|
||||
},
|
||||
{
|
||||
Name: "drop-metric-name",
|
||||
Load: `load 30s
|
||||
requests{job="1", __address__="bar"} 100`,
|
||||
Query: `requests * 2`,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
Floats: []promql.FPoint{{F: 200, T: 0}, {F: 200, T: 60000}, {F: 200, T: 120000}},
|
||||
Metric: labels.FromStrings(
|
||||
"__address__", "bar",
|
||||
"job", "1",
|
||||
),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(120, 0),
|
||||
Interval: 1 * time.Minute,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.Name, func(t *testing.T) {
|
||||
engine := newTestEngine()
|
||||
storage := promqltest.LoadedStorage(t, c.Load)
|
||||
t.Cleanup(func() { storage.Close() })
|
||||
|
||||
qry, err := engine.NewRangeQuery(context.Background(), storage, nil, c.Query, c.Start, c.End, c.Interval)
|
||||
require.NoError(t, err)
|
||||
|
||||
res := qry.Exec(context.Background())
|
||||
require.NoError(t, res.Err)
|
||||
testutil.RequireEqual(t, c.Result, res.Value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstantQueryWithRangeVectorSelector(t *testing.T) {
|
||||
engine := newTestEngine()
|
||||
|
||||
|
|
73
promql/promqltest/testdata/range_queries.test
vendored
Normal file
73
promql/promqltest/testdata/range_queries.test
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
# sum_over_time with all values
|
||||
load 30s
|
||||
bar 0 1 10 100 1000
|
||||
|
||||
eval range from 0 to 2m step 1m sum_over_time(bar[30s])
|
||||
{} 0 11 1100
|
||||
|
||||
clear
|
||||
|
||||
# sum_over_time with trailing values
|
||||
load 30s
|
||||
bar 0 1 10 100 1000 0 0 0 0
|
||||
|
||||
eval range from 0 to 2m step 1m sum_over_time(bar[30s])
|
||||
{} 0 11 1100
|
||||
|
||||
clear
|
||||
|
||||
# sum_over_time with all values long
|
||||
load 30s
|
||||
bar 0 1 10 100 1000 10000 100000 1000000 10000000
|
||||
|
||||
eval range from 0 to 4m step 1m sum_over_time(bar[30s])
|
||||
{} 0 11 1100 110000 11000000
|
||||
|
||||
clear
|
||||
|
||||
# sum_over_time with all values random
|
||||
load 30s
|
||||
bar 5 17 42 2 7 905 51
|
||||
|
||||
eval range from 0 to 3m step 1m sum_over_time(bar[30s])
|
||||
{} 5 59 9 956
|
||||
|
||||
clear
|
||||
|
||||
# metric query
|
||||
load 30s
|
||||
metric 1+1x4
|
||||
|
||||
eval range from 0 to 2m step 1m metric
|
||||
metric 1 3 5
|
||||
|
||||
clear
|
||||
|
||||
# metric query with trailing values
|
||||
load 30s
|
||||
metric 1+1x8
|
||||
|
||||
eval range from 0 to 2m step 1m metric
|
||||
metric 1 3 5
|
||||
|
||||
clear
|
||||
|
||||
# short-circuit
|
||||
load 30s
|
||||
foo{job="1"} 1+1x4
|
||||
bar{job="2"} 1+1x4
|
||||
|
||||
eval range from 0 to 2m step 1m foo > 2 or bar
|
||||
foo{job="1"} _ 3 5
|
||||
bar{job="2"} 1 3 5
|
||||
|
||||
clear
|
||||
|
||||
# Drop metric name
|
||||
load 30s
|
||||
requests{job="1", __address__="bar"} 100
|
||||
|
||||
eval range from 0 to 2m step 1m requests * 2
|
||||
{job="1", __address__="bar"} 200 200 200
|
||||
|
||||
clear
|
Loading…
Reference in a new issue