Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

lueurxax
Copy link

The previous implementation only supported a single alert per Graph and TimeSeries. The current changes introduce the ability to configure multiple alerts per panel.

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.
@lueurxax lueurxax marked this pull request as draft April 30, 2024 09:29
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.
@lueurxax lueurxax marked this pull request as ready for review April 30, 2024 17:01
}

// 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.

Copy link
Author

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

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.

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 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.
@lueurxax lueurxax requested a review from malekvictor May 1, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants