Skip to content
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

Merged
merged 1 commit into from Sep 12, 2022

Conversation

yanksyoon
Copy link
Contributor

Replace three dots characters ... with ellipsis (U+2026) characters to save 2 extra chars space.
Related issue: #3050

Signed-off-by: charlie4284 <charlie4284@gmail.com>
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@simonpasquier simonpasquier merged commit 3d624c0 into prometheus:main Sep 12, 2022
qinxx108 pushed a commit to qinxx108/alertmanager that referenced this pull request Dec 13, 2022
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
Copy link
Contributor

@pstibrany pstibrany Sep 4, 2023

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants