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

refactor(layers/prometheus): provide builder APIs #5072

Merged
merged 19 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ mod dtrace;
#[cfg(all(target_os = "linux", feature = "layers-dtrace"))]
pub use self::dtrace::DtraceLayer;

#[cfg(any(feature = "layers-prometheus", feature = "layers-prometheus-client"))]
koushiro marked this conversation as resolved.
Show resolved Hide resolved
pub mod observe;
35 changes: 35 additions & 0 deletions core/src/layers/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
//! This module offers essential components to facilitate the implementation of observability in OpenDAL.

mod metrics;

pub use metrics::MetricMetadata;
pub use metrics::MetricsAccessor;
pub use metrics::MetricsIntercept;
Expand All @@ -33,3 +34,37 @@ pub use metrics::LABEL_SCHEME;
pub use metrics::METRIC_OPERATION_BYTES;
pub use metrics::METRIC_OPERATION_DURATION_SECONDS;
pub use metrics::METRIC_OPERATION_ERRORS_TOTAL;

pub(crate) fn path_label_value(path: &str, path_level: usize) -> Option<&str> {
koushiro marked this conversation as resolved.
Show resolved Hide resolved
if path.is_empty() {
koushiro marked this conversation as resolved.
Show resolved Hide resolved
return None;
}

if path_level > 0 {
let label_value = path
.char_indices()
.filter(|&(_, c)| c == '/')
.nth(path_level - 1)
.map_or(path, |(i, _)| &path[..i]);
Some(label_value)
} else {
None
}
}

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

#[test]
fn test_path_label_value() {
let path = "abc/def/ghi";
assert_eq!(path_label_value(path, 0), None);
assert_eq!(path_label_value(path, 1), Some("abc"));
assert_eq!(path_label_value(path, 2), Some("abc/def"));
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);
}
}
Loading
Loading