Skip to content

Commit f8221a3

Browse files
authored
fix: always contains path label if configured (#5433)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
1 parent f52c488 commit f8221a3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/src/layers/observe/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ pub use metrics::METRIC_OPERATION_ERRORS_TOTAL;
5151
/// - level > 0: the path label will be the path split by "/" and get the last n level,
5252
/// if n=1 and input path is "abc/def/ghi", and then we'll use "abc/" as the path label.
5353
pub fn path_label_value(path: &str, level: usize) -> Option<&str> {
54-
if path.is_empty() {
55-
return None;
56-
}
57-
5854
if level > 0 {
55+
if path.is_empty() {
56+
return Some("");
57+
}
58+
5959
let label_value = path
6060
.char_indices()
6161
.filter(|&(_, c)| c == '/')
@@ -80,6 +80,7 @@ mod tests {
8080
assert_eq!(path_label_value(path, 3), Some("abc/def/ghi"));
8181
assert_eq!(path_label_value(path, usize::MAX), Some("abc/def/ghi"));
8282

83-
assert_eq!(path_label_value("", 1), None);
83+
assert_eq!(path_label_value("", 0), None);
84+
assert_eq!(path_label_value("", 1), Some(""));
8485
}
8586
}

0 commit comments

Comments
 (0)