From 44c4aad58fd10986c5054708351ca47a9f0edb26 Mon Sep 17 00:00:00 2001 From: lueurxax Date: Tue, 30 Apr 2024 11:14:17 +0200 Subject: [PATCH] Add new alert for no heap allocations 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. --- row/row_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/row/row_test.go b/row/row_test.go index 2bad20a7..65a52a71 100644 --- a/row/row_test.go +++ b/row/row_test.go @@ -69,12 +69,20 @@ func TestRowsCanHaveGraphsAndAlert(t *testing.T) { ), alert.If(alert.Avg, "A", alert.IsAbove(3)), ), + graph.Alert( + "No heap allocations", + alert.WithPrometheusQuery( + "A", + "sum(go_memstats_heap_alloc_bytes{app!=\"\"}) by (app)", + ), + alert.If(alert.Avg, "A", alert.IsBelow(0.01)), + ), ), ) req.NoError(err) req.Len(panel.builder.Panels, 1) - req.Len(panel.Alerts(), 1) + req.Len(panel.Alerts(), 2) req.Equal("Prometheus", panel.Alerts()[0].Datasource) } @@ -107,12 +115,20 @@ func TestRowsCanHaveTimeSeriesAndAlert(t *testing.T) { ), alert.If(alert.Avg, "A", alert.IsAbove(3)), ), + timeseries.Alert( + "No heap allocations", + alert.WithPrometheusQuery( + "A", + "sum(go_memstats_heap_alloc_bytes{app!=\"\"}) by (app)", + ), + alert.If(alert.Avg, "A", alert.IsBelow(0.01)), + ), ), ) req.NoError(err) req.Len(panel.builder.Panels, 1) - req.Len(panel.Alerts(), 1) + req.Len(panel.Alerts(), 2) req.Equal("Prometheus", panel.Alerts()[0].Datasource) }