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.
What happened
After the parser refactoring in #17977,
promtool test rulesno longer respects--enable-featureflags when loading rule files containing experimental PromQL syntax.Root cause
In
cmd/promtool/unittest.go, thetestGroup.test()method creates arules.ManagerOptionswithout setting theParserfield:The
rules.NewManagerthen falls back toparser.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 inmain()and respected by allparser.ParseExprcalls, including those inside the rules manager.Expected behavior
promtool test rules --enable-feature=promql-experimental-functions test.ymlshould 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.parserto therules.ManagerOptionsstruct initialization.