mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
test: PromQL: stop using internal fields of engine
* set enablePerStepStats and lookback duration via `NewTestEngine` parameters. * check maxSamples by recreating query engine * check lookback without modifying internals Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
0dbfd20b69
commit
786e0e706c
|
@ -1289,13 +1289,10 @@ load 10s
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
engine := newTestEngine()
|
|
||||||
engine.enablePerStepStats = true
|
|
||||||
origMaxSamples := engine.maxSamplesPerQuery
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.Query, func(t *testing.T) {
|
t.Run(c.Query, func(t *testing.T) {
|
||||||
opts := promql.NewPrometheusQueryOpts(true, 0)
|
opts := promql.NewPrometheusQueryOpts(true, 0)
|
||||||
engine.maxSamplesPerQuery = origMaxSamples
|
engine := promqltest.NewTestEngine(true, 0, promqltest.DefaultMaxSamplesPerQuery)
|
||||||
|
|
||||||
runQuery := func(expErr error) *stats.Statistics {
|
runQuery := func(expErr error) *stats.Statistics {
|
||||||
var err error
|
var err error
|
||||||
|
@ -1322,7 +1319,7 @@ load 10s
|
||||||
if c.SkipMaxCheck {
|
if c.SkipMaxCheck {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
engine.maxSamplesPerQuery = stats.Samples.PeakSamples - 1
|
engine = promqltest.NewTestEngine(true, 0, stats.Samples.PeakSamples-1)
|
||||||
runQuery(promql.ErrTooManySamples(env))
|
runQuery(promql.ErrTooManySamples(env))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1496,11 +1493,11 @@ load 10s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Within limit.
|
// Within limit.
|
||||||
engine.maxSamplesPerQuery = c.MaxSamples
|
engine = promqltest.NewTestEngine(false, 0, c.MaxSamples)
|
||||||
testFunc(nil)
|
testFunc(nil)
|
||||||
|
|
||||||
// Exceeding limit.
|
// Exceeding limit.
|
||||||
engine.maxSamplesPerQuery = c.MaxSamples - 1
|
engine = promqltest.NewTestEngine(false, 0, c.MaxSamples-1)
|
||||||
testFunc(promql.ErrTooManySamples(env))
|
testFunc(promql.ErrTooManySamples(env))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4956,13 +4953,10 @@ metric 0 1 2
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
c := c
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
engine := newTestEngine()
|
engine := promqltest.NewTestEngine(false, c.engineLookback, promqltest.DefaultMaxSamplesPerQuery)
|
||||||
storage := promqltest.LoadedStorage(t, load)
|
storage := promqltest.LoadedStorage(t, load)
|
||||||
t.Cleanup(func() { storage.Close() })
|
t.Cleanup(func() { storage.Close() })
|
||||||
|
|
||||||
if c.engineLookback != 0 {
|
|
||||||
engine.lookbackDelta = c.engineLookback
|
|
||||||
}
|
|
||||||
opts := promql.NewPrometheusQueryOpts(false, c.queryLookback)
|
opts := promql.NewPrometheusQueryOpts(false, c.queryLookback)
|
||||||
qry, err := engine.NewInstantQuery(context.Background(), storage, opts, query, c.ts)
|
qry, err := engine.NewInstantQuery(context.Background(), storage, opts, query, c.ts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func newTestEngine() *promql.Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvaluations(t *testing.T) {
|
func TestEvaluations(t *testing.T) {
|
||||||
RunBuiltinTests(t, newTestEngine())
|
promqltest.RunBuiltinTests(t, newTestEngine())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run a lot of queries at the same time, to check for race conditions.
|
// Run a lot of queries at the same time, to check for race conditions.
|
||||||
|
|
|
@ -76,7 +76,7 @@ func NewTestEngine(enablePerStepStats bool, lookbackDelta time.Duration, maxSamp
|
||||||
return promql.NewEngine(promql.EngineOpts{
|
return promql.NewEngine(promql.EngineOpts{
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
Reg: nil,
|
Reg: nil,
|
||||||
MaxSamples: DefaultMaxSamplesPerQuery,
|
MaxSamples: maxSamples,
|
||||||
Timeout: 100 * time.Second,
|
Timeout: 100 * time.Second,
|
||||||
NoStepSubqueryIntervalFn: func(int64) int64 { return durationMilliseconds(1 * time.Minute) },
|
NoStepSubqueryIntervalFn: func(int64) int64 { return durationMilliseconds(1 * time.Minute) },
|
||||||
EnableAtModifier: true,
|
EnableAtModifier: true,
|
||||||
|
|
Loading…
Reference in a new issue