From 518bac35bc32834517f8ad356c05406522eb61be Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Thu, 14 Dec 2023 15:15:30 +0900 Subject: [PATCH] feat: add log and tracing layers for Copy From statement (#2929) feat: add log and tracing layers --- src/common/datasource/src/object_store/fs.rs | 9 +++++++++ src/common/datasource/src/object_store/s3.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/common/datasource/src/object_store/fs.rs b/src/common/datasource/src/object_store/fs.rs index 7f43c50591dc..6d342f8eb30b 100644 --- a/src/common/datasource/src/object_store/fs.rs +++ b/src/common/datasource/src/object_store/fs.rs @@ -23,6 +23,15 @@ pub fn build_fs_backend(root: &str) -> Result { let _ = builder.root(root); let object_store = ObjectStore::new(builder) .context(BuildBackendSnafu)? + .layer( + object_store::layers::LoggingLayer::default() + // Print the expected error only in DEBUG level. + // See https://docs.rs/opendal/latest/opendal/layers/struct.LoggingLayer.html#method.with_error_level + .with_error_level(Some("debug")) + .expect("input error level must be valid"), + ) + .layer(object_store::layers::TracingLayer) + .layer(object_store::layers::PrometheusMetricsLayer) .finish(); Ok(object_store) } diff --git a/src/common/datasource/src/object_store/s3.rs b/src/common/datasource/src/object_store/s3.rs index 87975280879d..577a33eb6897 100644 --- a/src/common/datasource/src/object_store/s3.rs +++ b/src/common/datasource/src/object_store/s3.rs @@ -80,8 +80,18 @@ pub fn build_s3_backend( } } + // TODO(weny): Consider finding a better way to eliminate duplicate code. Ok(ObjectStore::new(builder) .context(error::BuildBackendSnafu)? + .layer( + object_store::layers::LoggingLayer::default() + // Print the expected error only in DEBUG level. + // See https://docs.rs/opendal/latest/opendal/layers/struct.LoggingLayer.html#method.with_error_level + .with_error_level(Some("debug")) + .expect("input error level must be valid"), + ) + .layer(object_store::layers::TracingLayer) + .layer(object_store::layers::PrometheusMetricsLayer) .finish()) }