Reflect Discord's max length message limits (#3597)

* 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>
This commit is contained in:
Tomas Kozak 2023-11-15 08:37:47 +01:00 committed by GitHub
parent 9dbc8b6b91
commit d2b6692f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -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
@ -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 {