Skip to content

Commit

Permalink
Optimize handling of alert panel names and panel alerts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lueurxax committed May 1, 2024
1 parent ccb6596 commit 155d6a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (client *Client) UpsertDashboard(ctx context.Context, folder *Folder, build
return nil, err
}

alertPanelNames := make(map[string]struct{})
alertPanelNames := make(map[string]struct{}, len(alerts))
for _, al := range alerts {
alertPanelNames[al.PanelName] = struct{}{}
}
Expand Down
4 changes: 2 additions & 2 deletions row/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func WithGraph(title string, options ...graph.Option) Option {

row.builder.Add(panel.Builder)

if panel.Alerts == nil || len(panel.Alerts) == 0 {
if len(panel.Alerts) == 0 {
return nil
}

Expand All @@ -84,7 +84,7 @@ func WithTimeSeries(title string, options ...timeseries.Option) Option {

row.builder.Add(panel.Builder)

if panel.Alerts == nil || len(panel.Alerts) == 0 {
if len(panel.Alerts) == 0 {
return nil
}

Expand Down

0 comments on commit 155d6a5

Please sign in to comment.