Skip to content

Commit

Permalink
Reflect Discord's max length message limits (#3597)
Browse files Browse the repository at this point in the history
* Reflect Discord's max length message limits

Signed-off-by: Tomas Kozak <kozak@talko.cz>

* Fix log key name

Signed-off-by: Tomas Kozak <kozak@talko.cz>

---------

Signed-off-by: Tomas Kozak <kozak@talko.cz>
  • Loading branch information
kozaktomas committed Nov 15, 2023
1 parent 9dbc8b6 commit d2b6692
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions notify/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import (
"github.com/prometheus/alertmanager/types"
)

const (
// https://discord.com/developers/docs/resources/channel#embed-object-embed-limits - 256 characters or runes.
maxTitleLenRunes = 256
// https://discord.com/developers/docs/resources/channel#embed-object-embed-limits - 4096 characters or runes.
maxDescriptionLenRunes = 4096
)

const (
colorRed = 0x992D22
colorGreen = 0x2ECC71
Expand Down Expand Up @@ -90,14 +97,20 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
return false, err
}

title := tmpl(n.conf.Title)
title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), maxTitleLenRunes)
if err != nil {
return false, err
}
description := tmpl(n.conf.Message)
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)
}

color := colorGrey
if alerts.Status() == model.AlertFiring {
Expand Down

0 comments on commit d2b6692

Please sign in to comment.