From dbd7a7400e403296ca260bbce8b2bb79ec5364dc Mon Sep 17 00:00:00 2001 From: Yao Zengzeng Date: Mon, 6 May 2019 15:02:40 +0800 Subject: [PATCH] some minor fixes: (#5535) 1. If alerts is empty after `relabelAlerts`, just return to avoid subsequent unnecessary operations 2. minor fix in notifier's test case 3. minor fix in comment Signed-off-by: YaoZengzeng --- notifier/notifier.go | 5 ++++- notifier/notifier_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/notifier/notifier.go b/notifier/notifier.go index f9c83e324..499ee4e77 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -364,6 +364,9 @@ func (n *Manager) Send(alerts ...*Alert) { } alerts = n.relabelAlerts(alerts) + if len(alerts) == 0 { + return + } // Queue capacity should be significantly larger than a single alert // batch could be. @@ -615,7 +618,7 @@ func postPath(pre string) string { return path.Join("/", pre, alertPushEndpoint) } -// alertmanagersFromGroup extracts a list of alertmanagers from a target group +// alertmanagerFromGroup extracts a list of alertmanagers from a target group // and an associated AlertmanagerConfig. func alertmanagerFromGroup(tg *targetgroup.Group, cfg *config.AlertmanagerConfig) ([]alertmanager, []alertmanager, error) { var res []alertmanager diff --git a/notifier/notifier_test.go b/notifier/notifier_test.go index 1502dfda1..0269590fa 100644 --- a/notifier/notifier_test.go +++ b/notifier/notifier_test.go @@ -385,7 +385,7 @@ func TestHandlerQueueing(t *testing.T) { expected = alerts[:maxBatchSize] unblock <- struct{}{} - for i := 2; i < 4; i++ { + for i := 2; i < 5; i++ { select { case <-called: expected = alerts[i*maxBatchSize : (i+1)*maxBatchSize]