-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Support multiple alerts in Graph and TimeSeries panels #260
base: master
Are you sure you want to change the base?
Conversation
The previous implementation only supported a single alert per Graph and TimeSeries. The current changes introduce the ability to configure multiple alerts per panel. Also, changes have been propagated to the corresponding tests in graph_test.go and timeseries_test.go to verify the new feature handling multiple alerts.
A new alert for "No heap allocations" has been incorporated into the row/row_test.go file. This alert uses a Prometheus query and triggers if the average is below 0.01. The test assertions are updated accordingly to check for two alerts rather than one.
Added PanelName as a field to the Alert structure. Updated related code to make use of this new field in alert creation and handling. The new field provides more specific information about the panel associated with the alert.
The alert constructor was changed to include 'panelTitle' as a formal argument. Consequently, all the places where the alert constructor, New, was used have been updated with this new argument. Changes were also made to the 'PanelName' property extraction in the 'dashboards.go' file. Furthermore, the alert test was adjusted to reflect changes in the alert constructor.
Removed the redundant line where alert name was being assigned with the Builder title in both graph.go and timeseries.go. Also updated the alert creation test in alert_test.go to reflect this change.
Removed the redundant line where alert name was being assigned with the Builder title in both graph.go and timeseries.go. Also updated the alert creation test in alert_test.go to reflect this change.
} | ||
|
||
// New creates a new alert. | ||
func New(name string, options ...Option) *Alert { | ||
func New(name, panelName string, options ...Option) *Alert { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
It's not optional parameter, without panel name we can't match alert with panel
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.
Ok, I leave it to the discretion of the owners
dashboards.go
Outdated
@@ -125,11 +125,24 @@ func (client *Client) UpsertDashboard(ctx context.Context, folder *Folder, build | |||
return nil, err | |||
} | |||
|
|||
alertPanelNames := make(map[string]struct{}) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
row/row.go
Outdated
@@ -58,15 +58,17 @@ func WithGraph(title string, options ...graph.Option) Option { | |||
|
|||
row.builder.Add(panel.Builder) | |||
|
|||
if panel.Alert == nil { | |||
if panel.Alerts == nil || len(panel.Alerts) == 0 { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This commit refactors how alert panel names and panel alerts are handled. For the alert panel names, allocation has been optimized by initializing the map with the size of the alerts array. Checking for panels with alerts has also been simplified to just check the length of alerts rather than checking for null and length simultaneously.
The previous implementation only supported a single alert per Graph and TimeSeries. The current changes introduce the ability to configure multiple alerts per panel.