mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
bd2a37429c
vmalert: support option to blackhole alerting notifications https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4122 --------- Co-authored-by: Rao, B V Chalapathi <b_v_chalapathi.rao@nokia.com>
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package notifier
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
metricset "github.com/VictoriaMetrics/metrics"
|
|
)
|
|
|
|
func TestBlackHoleNotifier_Send(t *testing.T) {
|
|
bh := NewBlackHoleNotifier()
|
|
|
|
if err := bh.Send(context.Background(), []Alert{{
|
|
GroupID: 0,
|
|
Name: "alert0",
|
|
Start: time.Now().UTC(),
|
|
End: time.Now().UTC(),
|
|
Annotations: map[string]string{"a": "b", "c": "d", "e": "f"},
|
|
}}, nil); err != nil {
|
|
t.Errorf("unexpected error %s", err)
|
|
}
|
|
alertCount := bh.metrics.alertsSent.Get()
|
|
|
|
if alertCount != 1 {
|
|
t.Errorf("expect value 1; instead got %d", alertCount)
|
|
}
|
|
}
|
|
|
|
func TestBlackHoleNotifier_Close(t *testing.T) {
|
|
bh := NewBlackHoleNotifier()
|
|
|
|
if err := bh.Send(context.Background(), []Alert{{
|
|
GroupID: 0,
|
|
Name: "alert0",
|
|
Start: time.Now().UTC(),
|
|
End: time.Now().UTC(),
|
|
Annotations: map[string]string{"a": "b", "c": "d", "e": "f"},
|
|
}}, nil); err != nil {
|
|
t.Errorf("unexpected error %s", err)
|
|
}
|
|
|
|
bh.Close()
|
|
|
|
defaultMetrics := metricset.GetDefaultSet()
|
|
alertMetricName := "vmalert_alerts_sent_total{addr=\"blackhole\"}"
|
|
for _, name := range defaultMetrics.ListMetricNames() {
|
|
if name == alertMetricName {
|
|
t.Errorf("Metric name should have unregistered.But still present")
|
|
}
|
|
|
|
}
|
|
}
|