Skip to content

Commit

Permalink
fix: always contains path label if configured
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia committed Dec 19, 2024
1 parent 6306acf commit 7affda0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/src/layers/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ pub use metrics::METRIC_OPERATION_ERRORS_TOTAL;
/// - level > 0: the path label will be the path split by "/" and get the last n level,
/// if n=1 and input path is "abc/def/ghi", and then we'll use "abc/" as the path label.
pub fn path_label_value(path: &str, level: usize) -> Option<&str> {
if path.is_empty() {
return None;
}

if level > 0 {
if path.is_empty() {
return Some("");
}

let label_value = path
.char_indices()
.filter(|&(_, c)| c == '/')
Expand All @@ -80,6 +80,7 @@ mod tests {
assert_eq!(path_label_value(path, 3), Some("abc/def/ghi"));
assert_eq!(path_label_value(path, usize::MAX), Some("abc/def/ghi"));

assert_eq!(path_label_value("", 1), None);
assert_eq!(path_label_value("", 0), None);
assert_eq!(path_label_value("", 1), Some(""));
}
}

0 comments on commit 7affda0

Please sign in to comment.