Skip to content

Commit

Permalink
minor code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Kröger <l.kroeger01@gmail.com>
  • Loading branch information
LucaDev committed May 23, 2024
1 parent c5f7187 commit f2bd09e
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions notify/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,11 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}

author, truncated := notify.TruncateInRunes(tmpl(n.conf.BotUsername), maxEmbedAuthorNameLenRunes)
if err != nil {
return false, err
}
if truncated {
level.Warn(n.logger).Log("msg", "Truncated author name", "key", key, "max_runes", maxEmbedAuthorNameLenRunes)
}

alertsOmittedMessage, truncated := notify.TruncateInRunes(tmpl(n.conf.AlertsOmittedMessage), maxMessageContentLength)
if err != nil {
return false, err
}
if truncated {
level.Warn(n.logger).Log("msg", "Truncated alerts omitted message", "key", key, "max_message_length", maxMessageContentLength)
}
Expand All @@ -164,16 +158,11 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}

title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), maxTitleLenRunes)
if err != nil {
return false, err
}
if truncated {
level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "max_runes", maxTitleLenRunes)
}

description, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxDescriptionLenRunes)
if err != nil {
return false, err
}
if truncated {
level.Warn(n.logger).Log("msg", "Truncated message", "key", key, "max_runes", maxDescriptionLenRunes)
}
Expand Down Expand Up @@ -213,16 +202,11 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
labelValue := string(alert.Labels[model.LabelName(labelName)])

label, truncated := notify.TruncateInRunes(labelName, maxFieldNameLenRunes)
if err != nil {
return false, err
}
if truncated {
level.Warn(n.logger).Log("msg", "Truncated field name", "key", key, "max_runes", maxFieldNameLenRunes)
}

value, truncated := notify.TruncateInRunes(labelValue, maxFieldValueLenRunes)
if err != nil {
return false, err
}
if truncated {
level.Warn(n.logger).Log("msg", "Truncated field value", "key", key, "max_runes", maxFieldValueLenRunes)
}
Expand Down

0 comments on commit f2bd09e

Please sign in to comment.