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

ruler: add metric thanos alert sent by alert name #5368

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pkg/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ type Sender struct {
alertmanagers []*Alertmanager
versions []APIVersion

sent *prometheus.CounterVec
errs *prometheus.CounterVec
dropped prometheus.Counter
latency *prometheus.HistogramVec
sent *prometheus.CounterVec
sentByAlertName *prometheus.CounterVec
errs *prometheus.CounterVec
dropped prometheus.Counter
latency *prometheus.HistogramVec
}

// NewSender returns a new sender. On each call to Send the entire alert batch is sent
Expand Down Expand Up @@ -265,6 +266,11 @@ func NewSender(
Help: "Total number of alerts sent by alertmanager.",
}, []string{"alertmanager"}),

sentByAlertName: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "thanos_alert_sender_alerts_sent_by_alertname_total",
Help: "Total number of alerts sent by alertmanager and alert name.",
}, []string{"alertmanager", "alertname"}),

errs: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "thanos_alert_sender_errors_total",
Help: "Total number of errors while sending alerts to alertmanager.",
Expand Down Expand Up @@ -360,6 +366,10 @@ func (s *Sender) Send(ctx context.Context, alerts []*notifier.Alert) {
s.latency.WithLabelValues(u.Host).Observe(time.Since(start).Seconds())
s.sent.WithLabelValues(u.Host).Add(float64(len(alerts)))

for _, alert := range alerts {
s.sentByAlertName.WithLabelValues(u.Host, alert.Name()).Inc()
}

numSuccess.Inc()
})
}(am, *u)
Expand Down
8 changes: 7 additions & 1 deletion pkg/alert/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ func TestSenderSendsOk(t *testing.T) {
}
s := NewSender(nil, nil, []*Alertmanager{NewAlertmanager(nil, poster, time.Minute, APIv1)})

s.Send(context.Background(), []*notifier.Alert{{}, {}})
s.Send(context.Background(), []*notifier.Alert{
{Labels: labels.FromStrings("alertname", "test")}, {
Labels: labels.FromStrings("alertname", "test"),
}})

assertSameHosts(t, poster.urls, poster.seen)

Expand All @@ -166,6 +169,9 @@ func TestSenderSendsOk(t *testing.T) {
testutil.Equals(t, 2, int(promtestutil.ToFloat64(s.sent.WithLabelValues(poster.urls[1].Host))))
testutil.Equals(t, 0, int(promtestutil.ToFloat64(s.errs.WithLabelValues(poster.urls[1].Host))))
testutil.Equals(t, 0, int(promtestutil.ToFloat64(s.dropped)))

testutil.Equals(t, 2, int(promtestutil.ToFloat64(s.sentByAlertName.WithLabelValues(poster.urls[0].Host, "test"))))
testutil.Equals(t, 2, int(promtestutil.ToFloat64(s.sentByAlertName.WithLabelValues(poster.urls[1].Host, "test"))))
}

func TestSenderSendsOneFails(t *testing.T) {
Expand Down