Skip to content

promtool test rules ignores --enable-feature flags when loading rule files #18093

Description

@aknuds1

What happened

After the parser refactoring in #17977, promtool test rules no longer respects --enable-feature flags when loading rule files containing experimental PromQL syntax.

Root cause

In cmd/promtool/unittest.go, the testGroup.test() method creates a rules.ManagerOptions without setting the Parser field:

// cmd/promtool/unittest.go:252-258
opts := &rules.ManagerOptions{
    QueryFunc:  rules.EngineQueryFunc(suite.QueryEngine(), suite.Storage()),
    Appendable: suite.Storage(),
    Context:    context.Background(),
    NotifyFunc: func(context.Context, string, ...*rules.Alert) {},
    Logger:     promslog.NewNopLogger(),
    // Parser field is missing
}

The rules.NewManager then falls back to parser.NewParser(parser.Options{}), which has no experimental features enabled. Meanwhile, tg.parser (which does have the correct features) is only used for parsing expected samples (lines 485, 489) but not for loading the actual rule files.

Before #17977, the global parser.EnableExperimentalFunctions (etc.) was set in main() and respected by all parser.ParseExpr calls, including those inside the rules manager.

Expected behavior

promtool test rules --enable-feature=promql-experimental-functions test.yml should load rule files that use experimental PromQL functions.

Actual behavior

Rule files using experimental PromQL functions fail to load with parse errors.

Fix

Add Parser: tg.parser to the rules.ManagerOptions struct initialization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions