-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truncate messages with fewer characters #3072
Conversation
Signed-off-by: charlie4284 <charlie4284@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Signed-off-by: charlie4284 <charlie4284@gmail.com> Signed-off-by: charlie4284 <charlie4284@gmail.com> Signed-off-by: Yijie Qin <qinyijie@amazon.com>
@@ -90,7 +90,7 @@ func Truncate(s string, n int) (string, bool) { | |||
if n <= 3 { | |||
return string(r[:n]), true | |||
} | |||
return string(r[:n-3]) + "...", true | |||
return string(r[:n-1]) + "…", true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"…" is encoded as 3 bytes in utf-8, so this makes string longer by 2 bytes compared to previous version.
Furthermore blindly cutting last 3 or 1 byte can actually break the utf-8 sequence of bytes. Ideally string would be truncated at rune boundary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this eventually: https://github.com/prometheus/alertmanager/blob/main/notify/util.go#L88-L130
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice, I missed that when checking changelog of alertmanager 0.26.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Replace three dots characters
...
with ellipsis (U+2026)…
characters to save 2 extra chars space.Related issue: #3050