Documentation
¶
Index ¶
- Constants
- func GetBuiltInExprs() ([]string, error)
- func HistogramTestExpression(h *histogram.FloatHistogram) string
- func LoadedStorage(t testing.TB, input string) *teststorage.TestStorage
- func MigrateTestData(mode, dir string) error
- func NewTestEngine(tb testing.TB, enablePerStepStats bool, lookbackDelta time.Duration, ...) *promql.Engine
- func NewTestEngineWithOpts(tb testing.TB, opts promql.EngineOpts) *promql.Engine
- func RunBuiltinTests(t TBRun, engine promql.QueryEngine)
- func RunBuiltinTestsWithStorage(t TBRun, engine promql.QueryEngine, ...)
- func RunTest(t testing.TB, input string, engine promql.QueryEngine)
- func RunTestWithStorage(t testing.TB, input string, engine promql.QueryEngine, ...)
- type LazyLoader
- func (ll *LazyLoader) Close() error
- func (ll *LazyLoader) Context() context.Context
- func (ll *LazyLoader) QueryEngine() *promql.Engine
- func (ll *LazyLoader) Queryable() storage.Queryable
- func (ll *LazyLoader) Storage() storage.Storage
- func (ll *LazyLoader) WithSamplesTill(ts time.Time, fn func(error))
- type LazyLoaderOpts
- type MigrateMode
- type TBRun
Constants ¶
const ( Ordered expectCmdType = iota Fail Warn NoWarn Info NoInfo )
const (
DefaultMaxSamplesPerQuery = 10000
)
Variables ¶
This section is empty.
Functions ¶
func GetBuiltInExprs ¶ added in v0.310.0
GetBuiltInExprs returns all the eval statement expressions from the built-in test files.
func HistogramTestExpression ¶
func HistogramTestExpression(h *histogram.FloatHistogram) string
HistogramTestExpression returns TestExpression() for the given histogram or "" if the histogram is nil.
func LoadedStorage ¶
func LoadedStorage(t testing.TB, input string) *teststorage.TestStorage
LoadedStorage returns storage with generated data using the provided load statements. Non-load statements will cause test errors.
func MigrateTestData ¶ added in v0.305.0
MigrateTestData migrates all PromQL test files to the new syntax format. It applies annotation rules based on the provided migration mode ("strict", "basic", or "tolerant"). The function parses each .test file, converts it to the new syntax and overwrites the file.
func NewTestEngine ¶
func NewTestEngine(tb testing.TB, enablePerStepStats bool, lookbackDelta time.Duration, maxSamples int) *promql.Engine
NewTestEngine creates a promql.Engine with enablePerStepStats, lookbackDelta and maxSamples, and returns it.
func NewTestEngineWithOpts ¶ added in v0.55.0
NewTestEngineWithOpts creates a promql.Engine with opts and returns it.
func RunBuiltinTests ¶
func RunBuiltinTests(t TBRun, engine promql.QueryEngine)
RunBuiltinTests runs an acceptance test suite against the provided engine.
func RunBuiltinTestsWithStorage ¶ added in v0.301.0
func RunBuiltinTestsWithStorage(t TBRun, engine promql.QueryEngine, newStorage func(testing.TB) storage.Storage)
RunBuiltinTestsWithStorage runs an acceptance test suite against the provided engine and storage.
Types ¶
type LazyLoader ¶
LazyLoader lazily loads samples into storage. This is specifically implemented for unit testing of rules.
func NewLazyLoader ¶
func NewLazyLoader(input string, opts LazyLoaderOpts) (*LazyLoader, error)
NewLazyLoader returns an initialized empty LazyLoader.
func (*LazyLoader) Close ¶
func (ll *LazyLoader) Close() error
Close closes resources associated with the LazyLoader.
func (*LazyLoader) Context ¶
func (ll *LazyLoader) Context() context.Context
Context returns the LazyLoader's context.
func (*LazyLoader) QueryEngine ¶
func (ll *LazyLoader) QueryEngine() *promql.Engine
QueryEngine returns the LazyLoader's query engine.
func (*LazyLoader) Queryable ¶
func (ll *LazyLoader) Queryable() storage.Queryable
Queryable allows querying the LazyLoader's data. Note: only the samples till the max timestamp used in `WithSamplesTill` can be queried.
func (*LazyLoader) Storage ¶
func (ll *LazyLoader) Storage() storage.Storage
Storage returns the LazyLoader's storage.
func (*LazyLoader) WithSamplesTill ¶
func (ll *LazyLoader) WithSamplesTill(ts time.Time, fn func(error))
WithSamplesTill loads the samples till given timestamp and executes the given function.
type LazyLoaderOpts ¶
type LazyLoaderOpts struct {
// Both of these must be set to true for regular PromQL (as of
// Prometheus v2.33). They can still be disabled here for legacy and
// other uses.
EnableAtModifier, EnableNegativeOffset bool
// Currently defaults to false, matches the "promql-delayed-name-removal"
// feature flag.
EnableDelayedNameRemoval bool
// StartTime is the start time for the test. If zero, defaults to Unix epoch.
StartTime time.Time
}
LazyLoaderOpts are options for the lazy loader.
type MigrateMode ¶ added in v0.305.0
type MigrateMode int
const ( MigrateStrict MigrateMode = iota MigrateBasic MigrateTolerant )
func ParseMigrateMode ¶ added in v0.305.0
func ParseMigrateMode(s string) (MigrateMode, error)