-
Notifications
You must be signed in to change notification settings - Fork 840
Adding parser for Xfunctions in Rule validation #7111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package ruler | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/prometheus/model/rulefmt" | ||
| ) | ||
|
|
||
| func TestValidateRuleGroup_AcceptsXFunctions(t *testing.T) { | ||
| manager := &DefaultMultiTenantManager{} | ||
|
|
||
| // Test rule with XFunction (should now pass) | ||
| ruleGroupWithXFunc := rulefmt.RuleGroup{ | ||
| Name: "test_group", | ||
| Rules: []rulefmt.Rule{ | ||
| { | ||
| Alert: "TestAlert", | ||
| Expr: "xrate(cpu_usage[5m]) > 0.8", // XFunction | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| errs := manager.ValidateRuleGroup(ruleGroupWithXFunc) | ||
|
|
||
| // Should have no validation errors now | ||
| if len(errs) != 0 { | ||
| t.Fatalf("Expected no validation errors for XFunction after fix, got: %v", errs) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateRuleGroup_AcceptsStandardFunctions(t *testing.T) { | ||
|
||
| manager := &DefaultMultiTenantManager{} | ||
|
|
||
| // Test rule with standard function (should pass) | ||
| ruleGroupStandard := rulefmt.RuleGroup{ | ||
| Name: "test_group", | ||
| Rules: []rulefmt.Rule{ | ||
| { | ||
| Alert: "TestAlert", | ||
| Expr: "rate(cpu_usage[5m]) > 0.8", // Standard function | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| errs := manager.ValidateRuleGroup(ruleGroupStandard) | ||
|
|
||
| // Should have no validation errors | ||
| if len(errs) != 0 { | ||
| t.Fatalf("Expected no validation errors for standard function, got: %v", errs) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move change log?
The changelog order is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it a bugfix instead of a feature. Ruler xfunction support was added in last release but it doesn't work because of this failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it seems a bug rather than feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have updated to bugfix.