-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
Alerting: Support recording rule struct in provisioning API #87849
base: main
Are you sure you want to change the base?
Conversation
685cfd5
to
5bb8638
Compare
pkg/services/ngalert/api/compat.go
Outdated
@@ -456,7 +456,17 @@ func NotificationSettingsFromAlertRuleNotificationSettings(ns *definitions.Alert | |||
} | |||
} | |||
|
|||
func ApiRecordFromModelRecord(r *models.Record) *definitions.Record { | |||
func AlertRuleRecordFromRecord(r *definitions.Record) *models.Record { |
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.
Looks like we both wrote the same conversion func :D
I think this can be dropped (or can replace) ModelRecordFromApiRecord
below
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.
Just dropped this, prefer your naming scheme there 👍
@@ -477,6 +477,18 @@ type AlertRuleNotificationSettings struct { | |||
MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"` | |||
} | |||
|
|||
// swagger:model | |||
type Record struct { |
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 think my PR also introduced this type in this file - but your version is better because of the doc comments and examples. I think you'll need to delete mine? It's called the same thing.
"", | ||
) | ||
} | ||
|
||
provenance := determineProvenance(c) | ||
createdAlertRule, err := srv.alertRules.CreateAlertRule(c.Req.Context(), c.SignedInUser, upstreamModel, alerting_models.Provenance(provenance)) |
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.
Sadly I think we'll need to duplicate much of the validation code, inside the AlertRuleService too. The main API validation can't be reused by provisioning because of how that whole validation flow is architected (it mixes type conversions, that are specific to the main API, alongside validation - this is true for validation of all provisioning fields).
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.
This can ofc be saved for a future PR - but if we decide to do so, let's make sure we add a checkbox to the tasklist to remember it. We'll at least need to copy some validation logic, at most need to separate validation in a way that's reusable.
What is this feature?
Adds support for creating recording rules in the main API.
Recording rules have a new field,
Record
, and lack several of the other "statefulness" fields that only make sense for alerting rules.Why do we need this feature?
Allows users to provision recording rules.
Which issue(s) does this PR fix?:
N/A
Special notes for your reviewer:
Please check that: