Skip to content

Commit

Permalink
update get_path_label
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro committed Aug 24, 2024
1 parent b5fb7d0 commit 2fac4be
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/src/layers/prometheus_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ impl<R: oio::BlockingWrite> oio::BlockingWrite for PrometheusClientMetricWrapper

fn get_path_label(path: &str, path_level: usize) -> Option<&str> {
if path_level > 0 {
if path.is_empty() {
return None;
}
let label_value = path
.char_indices()
.filter(|&(_, c)| c == '/')
Expand All @@ -838,3 +841,20 @@ fn get_path_label(path: &str, path_level: usize) -> Option<&str> {
None
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_get_path_label() {
let path = "abc/def/ghi";
assert_eq!(get_path_label(path, 0), None);
assert_eq!(get_path_label(path, 1), Some("abc"));
assert_eq!(get_path_label(path, 2), Some("abc/def"));
assert_eq!(get_path_label(path, 3), Some("abc/def/ghi"));
assert_eq!(get_path_label(path, usize::MAX), Some("abc/def/ghi"));

assert_eq!(get_path_label("", 1), None);
}
}

0 comments on commit 2fac4be

Please sign in to comment.