Skip to content

Commit 37dd08b

Browse files
bors[bot]nightkr
andauthored
Merge #337
337: Truncate events to the actual length limit, rather than a constant amount r=teozkr a=teozkr ## Description ## Review Checklist - [ ] Code contains useful comments - [ ] (Integration-)Test cases added (or not applicable) - [ ] Documentation added (or not applicable) - [ ] Changelog updated (or not applicable) Co-authored-by: Teo Klestrup Röijezon <[email protected]>
2 parents 19808b4 + a06abcb commit 37dd08b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Fixed
8+
9+
- Truncate k8s event strings correctly, when required ([#337]).
10+
11+
[#337]: https://github.com/stackabletech/operator-rs/pull/337
12+
713
## [0.13.0] - 2022-02-23
814

915
### Added

src/logging/k8s_events.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ mod message {
8787
const ELLIPSIS_LEN: usize = ELLIPSIS.len_utf8();
8888
let len = msg.len();
8989
if len > max_len {
90-
msg.truncate(find_start_of_char(msg, len.saturating_sub(ELLIPSIS_LEN)));
90+
let start_of_trunc_char = find_start_of_char(msg, max_len.saturating_sub(ELLIPSIS_LEN));
91+
msg.truncate(start_of_trunc_char);
9192
if ELLIPSIS_LEN <= max_len {
9293
msg.push(ELLIPSIS);
9394
}
9495
}
96+
debug_assert!(msg.len() <= max_len);
9597
}
9698

9799
fn find_start_of_char(s: &str, mut pos: usize) -> usize {
@@ -120,7 +122,10 @@ mod message {
120122
fn truncate_should_ellipsize_large_string() {
121123
let mut x = "hello".to_string();
122124
truncate_with_ellipsis(&mut x, 4);
123-
assert_eq!(&x, "he…");
125+
assert_eq!(&x, "h…");
126+
x = "hello, this is a much larger string".to_string();
127+
truncate_with_ellipsis(&mut x, 4);
128+
assert_eq!(&x, "h…");
124129
}
125130

126131
#[test]

0 commit comments

Comments
 (0)