From bb5804eca90051d7d9f896e47717f3ebef0cee51 Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Fri, 25 Nov 2022 13:14:55 -0600 Subject: [PATCH 1/7] Change truncation log level to warn Signed-off-by: Alex Weaver --- notify/opsgenie/opsgenie.go | 2 +- notify/pagerduty/pagerduty.go | 4 ++-- notify/pushover/pushover.go | 6 +++--- notify/slack/slack.go | 2 +- notify/telegram/telegram.go | 2 +- notify/victorops/victorops.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index 522ec4e4f7..b363599400 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -174,7 +174,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h // https://docs.opsgenie.com/docs/alert-api - 130 characters meaning runes. message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 130) if truncated { - level.Debug(n.logger).Log("msg", "truncated message", "truncated_message", message, "alert", key) + level.Warn(n.logger).Log("msg", "truncated message", "truncated_message", message, "alert", key) } createEndpointURL := n.conf.APIURL.Copy() diff --git a/notify/pagerduty/pagerduty.go b/notify/pagerduty/pagerduty.go index c95f7e10fb..6e1e5c0f11 100644 --- a/notify/pagerduty/pagerduty.go +++ b/notify/pagerduty/pagerduty.go @@ -152,7 +152,7 @@ func (n *Notifier) notifyV1( // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) if truncated { - level.Debug(n.logger).Log("msg", "Truncated description", "description", description, "key", key) + level.Warn(n.logger).Log("msg", "Truncated description", "description", description, "key", key) } serviceKey := string(n.conf.ServiceKey) @@ -218,7 +218,7 @@ func (n *Notifier) notifyV2( // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) if truncated { - level.Debug(n.logger).Log("msg", "Truncated summary", "summary", summary, "key", key) + level.Warn(n.logger).Log("msg", "Truncated summary", "summary", summary, "key", key) } routingKey := string(n.conf.RoutingKey) diff --git a/notify/pushover/pushover.go b/notify/pushover/pushover.go index 33a0d281fd..396cd40c41 100644 --- a/notify/pushover/pushover.go +++ b/notify/pushover/pushover.go @@ -81,7 +81,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) // https://pushover.net/api#limits - 250 characters or runes. title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), 250) if truncated { - level.Debug(n.logger).Log("msg", "Truncated title", "truncated_title", title, "incident", key) + level.Warn(n.logger).Log("msg", "Truncated title", "truncated_title", title, "incident", key) } parameters.Add("title", title) @@ -95,7 +95,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) // https://pushover.net/api#limits - 1024 characters or runes. message, truncated = notify.TruncateInRunes(message, 1024) if truncated { - level.Debug(n.logger).Log("msg", "Truncated message", "truncated_message", message, "incident", key) + level.Warn(n.logger).Log("msg", "Truncated message", "truncated_message", message, "incident", key) } message = strings.TrimSpace(message) if message == "" { @@ -107,7 +107,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) // https://pushover.net/api#limits - 512 characters or runes. supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), 512) if truncated { - level.Debug(n.logger).Log("msg", "Truncated URL", "truncated_url", supplementaryURL, "incident", key) + level.Warn(n.logger).Log("msg", "Truncated URL", "truncated_url", supplementaryURL, "incident", key) } parameters.Add("url", supplementaryURL) parameters.Add("url_title", tmpl(n.conf.URLTitle)) diff --git a/notify/slack/slack.go b/notify/slack/slack.go index 5f506f7feb..cbc464cf64 100644 --- a/notify/slack/slack.go +++ b/notify/slack/slack.go @@ -106,7 +106,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) if err != nil { return false, err } - level.Debug(n.logger).Log("msg", "Truncated title", "text", title, "key", key) + level.Warn(n.logger).Log("msg", "Truncated title", "text", title, "key", key) } att := &attachment{ Title: title, diff --git a/notify/telegram/telegram.go b/notify/telegram/telegram.go index 7dfc22eec1..03decb01df 100644 --- a/notify/telegram/telegram.go +++ b/notify/telegram/telegram.go @@ -68,7 +68,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err // Telegram supports 4096 chars max - from https://limits.tginfo.me/en. messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 4096) if truncated { - level.Debug(n.logger).Log("msg", "truncated message", "truncated_message", messageText) + level.Warn(n.logger).Log("msg", "truncated message", "truncated_message", messageText) } message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{ diff --git a/notify/victorops/victorops.go b/notify/victorops/victorops.go index 0da5db816c..a0c7d350b2 100644 --- a/notify/victorops/victorops.go +++ b/notify/victorops/victorops.go @@ -137,7 +137,7 @@ func (n *Notifier) createVictorOpsPayload(ctx context.Context, as ...*types.Aler // https://help.victorops.com/knowledge-base/incident-fields-glossary/ - 20480 characters. stateMessage, truncated := notify.TruncateInRunes(stateMessage, 20480) if truncated { - level.Debug(n.logger).Log("msg", "truncated stateMessage", "truncated_state_message", stateMessage, "incident", key) + level.Warn(n.logger).Log("msg", "truncated stateMessage", "truncated_state_message", stateMessage, "incident", key) } msg := map[string]string{ From ed3cfbb124bb520770ee840128ad3cb56958c333 Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Fri, 25 Nov 2022 13:23:20 -0600 Subject: [PATCH 2/7] Avoid logging the entire message after truncation Signed-off-by: Alex Weaver --- notify/opsgenie/opsgenie.go | 2 +- notify/pagerduty/pagerduty.go | 4 ++-- notify/pushover/pushover.go | 6 +++--- notify/slack/slack.go | 2 +- notify/telegram/telegram.go | 2 +- notify/victorops/victorops.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index b363599400..627e8095ed 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -174,7 +174,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h // https://docs.opsgenie.com/docs/alert-api - 130 characters meaning runes. message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 130) if truncated { - level.Warn(n.logger).Log("msg", "truncated message", "truncated_message", message, "alert", key) + level.Debug(n.logger).Log("msg", "Truncated message", "alert", key) } createEndpointURL := n.conf.APIURL.Copy() diff --git a/notify/pagerduty/pagerduty.go b/notify/pagerduty/pagerduty.go index 6e1e5c0f11..6d87132520 100644 --- a/notify/pagerduty/pagerduty.go +++ b/notify/pagerduty/pagerduty.go @@ -152,7 +152,7 @@ func (n *Notifier) notifyV1( // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) if truncated { - level.Warn(n.logger).Log("msg", "Truncated description", "description", description, "key", key) + level.Warn(n.logger).Log("msg", "Truncated description", "key", key) } serviceKey := string(n.conf.ServiceKey) @@ -218,7 +218,7 @@ func (n *Notifier) notifyV2( // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) if truncated { - level.Warn(n.logger).Log("msg", "Truncated summary", "summary", summary, "key", key) + level.Warn(n.logger).Log("msg", "Truncated summary", "key", key) } routingKey := string(n.conf.RoutingKey) diff --git a/notify/pushover/pushover.go b/notify/pushover/pushover.go index 396cd40c41..fa67a11e2a 100644 --- a/notify/pushover/pushover.go +++ b/notify/pushover/pushover.go @@ -81,7 +81,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) // https://pushover.net/api#limits - 250 characters or runes. title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), 250) if truncated { - level.Warn(n.logger).Log("msg", "Truncated title", "truncated_title", title, "incident", key) + level.Warn(n.logger).Log("msg", "Truncated title", "incident", key) } parameters.Add("title", title) @@ -95,7 +95,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) // https://pushover.net/api#limits - 1024 characters or runes. message, truncated = notify.TruncateInRunes(message, 1024) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "truncated_message", message, "incident", key) + level.Warn(n.logger).Log("msg", "Truncated message", "incident", key) } message = strings.TrimSpace(message) if message == "" { @@ -107,7 +107,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) // https://pushover.net/api#limits - 512 characters or runes. supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), 512) if truncated { - level.Warn(n.logger).Log("msg", "Truncated URL", "truncated_url", supplementaryURL, "incident", key) + level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key) } parameters.Add("url", supplementaryURL) parameters.Add("url_title", tmpl(n.conf.URLTitle)) diff --git a/notify/slack/slack.go b/notify/slack/slack.go index cbc464cf64..4622950cf4 100644 --- a/notify/slack/slack.go +++ b/notify/slack/slack.go @@ -106,7 +106,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) if err != nil { return false, err } - level.Warn(n.logger).Log("msg", "Truncated title", "text", title, "key", key) + level.Warn(n.logger).Log("msg", "Truncated title", "key", key) } att := &attachment{ Title: title, diff --git a/notify/telegram/telegram.go b/notify/telegram/telegram.go index 03decb01df..84b1ba7a45 100644 --- a/notify/telegram/telegram.go +++ b/notify/telegram/telegram.go @@ -68,7 +68,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err // Telegram supports 4096 chars max - from https://limits.tginfo.me/en. messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 4096) if truncated { - level.Warn(n.logger).Log("msg", "truncated message", "truncated_message", messageText) + level.Warn(n.logger).Log("msg", "Truncated message") } message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{ diff --git a/notify/victorops/victorops.go b/notify/victorops/victorops.go index a0c7d350b2..774a0e1ca8 100644 --- a/notify/victorops/victorops.go +++ b/notify/victorops/victorops.go @@ -137,7 +137,7 @@ func (n *Notifier) createVictorOpsPayload(ctx context.Context, as ...*types.Aler // https://help.victorops.com/knowledge-base/incident-fields-glossary/ - 20480 characters. stateMessage, truncated := notify.TruncateInRunes(stateMessage, 20480) if truncated { - level.Warn(n.logger).Log("msg", "truncated stateMessage", "truncated_state_message", stateMessage, "incident", key) + level.Warn(n.logger).Log("msg", "truncated stateMessage", "incident", key) } msg := map[string]string{ From 7a420fec35f6c3d69c1a4ccf8292993eab7c04ae Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Fri, 25 Nov 2022 13:23:54 -0600 Subject: [PATCH 3/7] Adjust degenerate log message in telegram notifier Signed-off-by: Alex Weaver --- notify/telegram/telegram.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/notify/telegram/telegram.go b/notify/telegram/telegram.go index 84b1ba7a45..fbb26d5c41 100644 --- a/notify/telegram/telegram.go +++ b/notify/telegram/telegram.go @@ -15,6 +15,7 @@ package telegram import ( "context" + "fmt" "net/http" "github.com/go-kit/log" @@ -65,10 +66,15 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err tmpl = notify.TmplText(n.tmpl, data, &err) ) + key, ok := notify.GroupKey(ctx) + if !ok { + return false, fmt.Errorf("group key missing") + } + // Telegram supports 4096 chars max - from https://limits.tginfo.me/en. messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 4096) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message") + level.Warn(n.logger).Log("msg", "Truncated message", "alert", key) } message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{ From 42dcba213f8c313ffa15bf7576a81737ddf606bb Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Fri, 25 Nov 2022 13:47:20 -0600 Subject: [PATCH 4/7] Also log the length that values were truncated to Signed-off-by: Alex Weaver --- notify/opsgenie/opsgenie.go | 8 +++++--- notify/pagerduty/pagerduty.go | 18 +++++++++++------- notify/pushover/pushover.go | 24 +++++++++++++++--------- notify/slack/slack.go | 9 ++++++--- notify/telegram/telegram.go | 8 +++++--- notify/victorops/victorops.go | 8 +++++--- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index 627e8095ed..fc74f05e60 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -34,6 +34,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// https://docs.opsgenie.com/docs/alert-api - 130 characters meaning runes. +const maxMessageLenRunes = 130 + // Notifier implements a Notifier for OpsGenie notifications. type Notifier struct { conf *config.OpsGenieConfig @@ -171,10 +174,9 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h } requests = append(requests, req.WithContext(ctx)) default: - // https://docs.opsgenie.com/docs/alert-api - 130 characters meaning runes. - message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 130) + message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Debug(n.logger).Log("msg", "Truncated message", "alert", key) + level.Debug(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) } createEndpointURL := n.conf.APIURL.Copy() diff --git a/notify/pagerduty/pagerduty.go b/notify/pagerduty/pagerduty.go index 6d87132520..1e549db8f3 100644 --- a/notify/pagerduty/pagerduty.go +++ b/notify/pagerduty/pagerduty.go @@ -36,7 +36,13 @@ import ( "github.com/prometheus/alertmanager/types" ) -const maxEventSize int = 512000 +const ( + maxEventSize int = 512000 + // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTc4-send-a-v1-event - 1024 characters or runes. + maxV1DescriptionLenRunes = 1024 + // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1024 characters or runes. + maxV2SummaryLenRunes = 1024 +) // Notifier implements a Notifier for PagerDuty notifications. type Notifier struct { @@ -149,10 +155,9 @@ func (n *Notifier) notifyV1( var tmplErr error tmpl := notify.TmplText(n.tmpl, data, &tmplErr) - // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. - description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) + description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), maxV1DescriptionLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated description", "key", key) + level.Warn(n.logger).Log("msg", "Truncated description", "key", key, "runes", maxV1DescriptionLenRunes) } serviceKey := string(n.conf.ServiceKey) @@ -215,10 +220,9 @@ func (n *Notifier) notifyV2( n.conf.Severity = "error" } - // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. - summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) + summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), maxV2SummaryLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated summary", "key", key) + level.Warn(n.logger).Log("msg", "Truncated summary", "key", key, "runes", maxV2SummaryLenRunes) } routingKey := string(n.conf.RoutingKey) diff --git a/notify/pushover/pushover.go b/notify/pushover/pushover.go index fa67a11e2a..3a3361a039 100644 --- a/notify/pushover/pushover.go +++ b/notify/pushover/pushover.go @@ -31,6 +31,15 @@ import ( "github.com/prometheus/alertmanager/types" ) +const ( + // https://pushover.net/api#limits - 250 characters or runes. + maxTitleLenRunes = 250 + // https://pushover.net/api#limits - 1024 characters or runes. + maxMessageLenRunes = 1024 + // https://pushover.net/api#limits - 512 characters or runes. + maxURLLenRunes = 512 +) + // Notifier implements a Notifier for Pushover notifications. type Notifier struct { conf *config.PushoverConfig @@ -78,10 +87,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) parameters.Add("token", tmpl(string(n.conf.Token))) parameters.Add("user", tmpl(string(n.conf.UserKey))) - // https://pushover.net/api#limits - 250 characters or runes. - title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), 250) + title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), maxTitleLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated title", "incident", key) + level.Warn(n.logger).Log("msg", "Truncated title", "incident", key, "runes", maxTitleLenRunes) } parameters.Add("title", title) @@ -92,10 +100,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) message = tmpl(n.conf.Message) } - // https://pushover.net/api#limits - 1024 characters or runes. - message, truncated = notify.TruncateInRunes(message, 1024) + message, truncated = notify.TruncateInRunes(message, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "incident", key) + level.Warn(n.logger).Log("msg", "Truncated message", "incident", key, "runes", maxMessageLenRunes) } message = strings.TrimSpace(message) if message == "" { @@ -104,10 +111,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) } parameters.Add("message", message) - // https://pushover.net/api#limits - 512 characters or runes. - supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), 512) + supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), maxURLLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key) + level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key, "runes", maxURLLenRunes) } parameters.Add("url", supplementaryURL) parameters.Add("url_title", tmpl(n.conf.URLTitle)) diff --git a/notify/slack/slack.go b/notify/slack/slack.go index 4622950cf4..428519397a 100644 --- a/notify/slack/slack.go +++ b/notify/slack/slack.go @@ -33,6 +33,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// https://api.slack.com/reference/messaging/attachments#legacy_fields - 1024, no units given, assuming runes or characters. +const maxTitleLenRunes = 1024 + // Notifier implements a Notifier for Slack notifications. type Notifier struct { conf *config.SlackConfig @@ -99,14 +102,14 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) } else { markdownIn = n.conf.MrkdwnIn } - // No reference in https://api.slack.com/reference/messaging/attachments#legacy_fields - assuming runes or characters. - title, truncated := notify.TruncateInRunes(tmplText(n.conf.Title), 1024) + + title, truncated := notify.TruncateInRunes(tmplText(n.conf.Title), maxTitleLenRunes) if truncated { key, err := notify.ExtractGroupKey(ctx) if err != nil { return false, err } - level.Warn(n.logger).Log("msg", "Truncated title", "key", key) + level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "runes", maxTitleLenRunes) } att := &attachment{ Title: title, diff --git a/notify/telegram/telegram.go b/notify/telegram/telegram.go index fbb26d5c41..f02b8bdb11 100644 --- a/notify/telegram/telegram.go +++ b/notify/telegram/telegram.go @@ -29,6 +29,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// Telegram supports 4096 chars max - from https://limits.tginfo.me/en. +const maxMessageLenRunes = 4096 + // Notifier implements a Notifier for telegram notifications. type Notifier struct { conf *config.TelegramConfig @@ -71,10 +74,9 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err return false, fmt.Errorf("group key missing") } - // Telegram supports 4096 chars max - from https://limits.tginfo.me/en. - messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 4096) + messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "alert", key) + level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) } message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{ diff --git a/notify/victorops/victorops.go b/notify/victorops/victorops.go index 774a0e1ca8..55f061f8ff 100644 --- a/notify/victorops/victorops.go +++ b/notify/victorops/victorops.go @@ -34,6 +34,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// https://help.victorops.com/knowledge-base/incident-fields-glossary/ - 20480 characters. +const maxMessageLenRunes = 20480 + // Notifier implements a Notifier for VictorOps notifications. type Notifier struct { conf *config.VictorOpsConfig @@ -134,10 +137,9 @@ func (n *Notifier) createVictorOpsPayload(ctx context.Context, as ...*types.Aler messageType = victorOpsEventResolve } - // https://help.victorops.com/knowledge-base/incident-fields-glossary/ - 20480 characters. - stateMessage, truncated := notify.TruncateInRunes(stateMessage, 20480) + stateMessage, truncated := notify.TruncateInRunes(stateMessage, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "truncated stateMessage", "incident", key) + level.Warn(n.logger).Log("msg", "truncated stateMessage", "incident", key, "runes", maxMessageLenRunes) } msg := map[string]string{ From 18181afb155c9f19c6d269064ab725bd6a7b891a Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Fri, 25 Nov 2022 14:03:33 -0600 Subject: [PATCH 5/7] Fix one last log level that I missed Signed-off-by: Alex Weaver --- notify/opsgenie/opsgenie.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index fc74f05e60..a3ba2f454e 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -176,7 +176,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h default: message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Debug(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) + level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) } createEndpointURL := n.conf.APIURL.Copy() From 9b9237cef10c20d065fa8ffcb787685f62b1760d Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Fri, 25 Nov 2022 15:10:14 -0600 Subject: [PATCH 6/7] Fix casing in victorops log message Signed-off-by: Alex Weaver --- notify/victorops/victorops.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify/victorops/victorops.go b/notify/victorops/victorops.go index 55f061f8ff..8111cc8ec4 100644 --- a/notify/victorops/victorops.go +++ b/notify/victorops/victorops.go @@ -139,7 +139,7 @@ func (n *Notifier) createVictorOpsPayload(ctx context.Context, as ...*types.Aler stateMessage, truncated := notify.TruncateInRunes(stateMessage, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "truncated stateMessage", "incident", key, "runes", maxMessageLenRunes) + level.Warn(n.logger).Log("msg", "Truncated state_message", "incident", key, "runes", maxMessageLenRunes) } msg := map[string]string{ From 0eee3ca9cb15995d593d84d311e60acc6d61e78e Mon Sep 17 00:00:00 2001 From: Alex Weaver Date: Tue, 13 Dec 2022 17:26:14 -0600 Subject: [PATCH 7/7] Rename key to max_runes Signed-off-by: Alex Weaver --- notify/opsgenie/opsgenie.go | 2 +- notify/pagerduty/pagerduty.go | 4 ++-- notify/pushover/pushover.go | 6 +++--- notify/slack/slack.go | 2 +- notify/telegram/telegram.go | 2 +- notify/victorops/victorops.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index a3ba2f454e..426734f275 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -176,7 +176,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h default: message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) + level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "max_runes", maxMessageLenRunes) } createEndpointURL := n.conf.APIURL.Copy() diff --git a/notify/pagerduty/pagerduty.go b/notify/pagerduty/pagerduty.go index 1e549db8f3..b6b816e039 100644 --- a/notify/pagerduty/pagerduty.go +++ b/notify/pagerduty/pagerduty.go @@ -157,7 +157,7 @@ func (n *Notifier) notifyV1( description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), maxV1DescriptionLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated description", "key", key, "runes", maxV1DescriptionLenRunes) + level.Warn(n.logger).Log("msg", "Truncated description", "key", key, "max_runes", maxV1DescriptionLenRunes) } serviceKey := string(n.conf.ServiceKey) @@ -222,7 +222,7 @@ func (n *Notifier) notifyV2( summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), maxV2SummaryLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated summary", "key", key, "runes", maxV2SummaryLenRunes) + level.Warn(n.logger).Log("msg", "Truncated summary", "key", key, "max_runes", maxV2SummaryLenRunes) } routingKey := string(n.conf.RoutingKey) diff --git a/notify/pushover/pushover.go b/notify/pushover/pushover.go index 3a3361a039..c5fc287a7b 100644 --- a/notify/pushover/pushover.go +++ b/notify/pushover/pushover.go @@ -89,7 +89,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), maxTitleLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated title", "incident", key, "runes", maxTitleLenRunes) + level.Warn(n.logger).Log("msg", "Truncated title", "incident", key, "max_runes", maxTitleLenRunes) } parameters.Add("title", title) @@ -102,7 +102,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) message, truncated = notify.TruncateInRunes(message, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "incident", key, "runes", maxMessageLenRunes) + level.Warn(n.logger).Log("msg", "Truncated message", "incident", key, "max_runes", maxMessageLenRunes) } message = strings.TrimSpace(message) if message == "" { @@ -113,7 +113,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), maxURLLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key, "runes", maxURLLenRunes) + level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key, "max_runes", maxURLLenRunes) } parameters.Add("url", supplementaryURL) parameters.Add("url_title", tmpl(n.conf.URLTitle)) diff --git a/notify/slack/slack.go b/notify/slack/slack.go index 428519397a..22bb30932e 100644 --- a/notify/slack/slack.go +++ b/notify/slack/slack.go @@ -109,7 +109,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) if err != nil { return false, err } - level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "runes", maxTitleLenRunes) + level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "max_runes", maxTitleLenRunes) } att := &attachment{ Title: title, diff --git a/notify/telegram/telegram.go b/notify/telegram/telegram.go index f02b8bdb11..90e0ca35af 100644 --- a/notify/telegram/telegram.go +++ b/notify/telegram/telegram.go @@ -76,7 +76,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) + level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "max_runes", maxMessageLenRunes) } message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{ diff --git a/notify/victorops/victorops.go b/notify/victorops/victorops.go index 8111cc8ec4..02c9362190 100644 --- a/notify/victorops/victorops.go +++ b/notify/victorops/victorops.go @@ -139,7 +139,7 @@ func (n *Notifier) createVictorOpsPayload(ctx context.Context, as ...*types.Aler stateMessage, truncated := notify.TruncateInRunes(stateMessage, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated state_message", "incident", key, "runes", maxMessageLenRunes) + level.Warn(n.logger).Log("msg", "Truncated state_message", "incident", key, "max_runes", maxMessageLenRunes) } msg := map[string]string{