You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by ma...@apache.org on 2024/12/19 11:52:53 UTC

(opendal) branch main updated: fix: always contains path label if configured (#5433)

This is an automated email from the ASF dual-hosted git repository.

manjusaka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new f8221a3f7 fix: always contains path label if configured (#5433)
f8221a3f7 is described below

commit f8221a3f77715dafddc395c3ea2689ea4d66cf41
Author: Ruihang Xia <wa...@gmail.com>
AuthorDate: Thu Dec 19 19:52:47 2024 +0800

    fix: always contains path label if configured (#5433)
    
    Signed-off-by: Ruihang Xia <wa...@gmail.com>
---
 core/src/layers/observe/mod.rs | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/core/src/layers/observe/mod.rs b/core/src/layers/observe/mod.rs
index dcbe059a4..5465bcd0a 100644
--- a/core/src/layers/observe/mod.rs
+++ b/core/src/layers/observe/mod.rs
@@ -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 == '/')
@@ -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(""));
     }
 }