Skip to content

Commit

Permalink
chore: Level down some log entry to debug (#181)
Browse files Browse the repository at this point in the history
* chore: Level down some log entry to debug

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix format

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Mar 25, 2022
1 parent a41f097 commit 51c0d22
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 77 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ hyper = { version = "0.14", features = ["full"] }
hyper-tls = "0.5.0"
log = "0.4"
metrics = "0.18"
minitrace = "0.4.0"
once_cell = "1"
pin-project = "1"
quick-xml = { version = "0.22.0", features = ["serialize"] }
Expand All @@ -42,8 +43,6 @@ thiserror = "1"
time = "0.3.7"
tokio = { version = "1.17", features = ["full"] }
tower = "0.4"
minitrace = "0.4.0"


[dev-dependencies]
anyhow = "1.0"
Expand All @@ -60,4 +59,3 @@ rand = "0.8"
sha2 = "0.10"
size = "0.1"
uuid = { version = "0.8", features = ["serde", "v4"] }

66 changes: 30 additions & 36 deletions src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use log::error;
use log::info;
use log::warn;
use metrics::increment_counter;
use minitrace::trace;
use reqsign::services::azure::storage::Signer;
use time::format_description::well_known::Rfc2822;
use time::OffsetDateTime;
Expand All @@ -42,11 +43,9 @@ use crate::credential::Credential;
use crate::error::Error;
use crate::error::Kind;
use crate::error::Result;
use crate::object::BoxedObjectStream;
use crate::object::Metadata;
use crate::ops::HeaderRange;
use crate::ops::OpDelete;
use crate::ops::OpList;
use crate::ops::OpRead;
use crate::ops::OpStat;
use crate::ops::OpWrite;
Expand Down Expand Up @@ -230,19 +229,20 @@ impl Backend {
}
#[async_trait]
impl Accessor for Backend {
#[trace("read")]
async fn read(&self, args: &OpRead) -> Result<BoxedAsyncReader> {
increment_counter!("opendal_azure_read_requests");

let p = self.get_abs_path(&args.path);
info!(
debug!(
"object {} read start: offset {:?}, size {:?}",
&p, args.offset, args.size
);

let resp = self.get_object(&p, args.offset, args.size).await?;
let resp = self.get_blob(&p, args.offset, args.size).await?;
match resp.status() {
StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
info!(
debug!(
"object {} reader created: offset {:?}, size {:?}",
&p, args.offset, args.size
);
Expand All @@ -252,25 +252,27 @@ impl Accessor for Backend {
_ => Err(parse_error_response(resp, "read", &p).await),
}
}
#[trace("write")]
async fn write(&self, r: BoxedAsyncReader, args: &OpWrite) -> Result<usize> {
let p = self.get_abs_path(&args.path);
info!("object {} write start: size {}", &p, args.size);
debug!("object {} write start: size {}", &p, args.size);

let resp = self.put_object(&p, r, args.size).await?;
let resp = self.put_blob(&p, r, args.size).await?;

match resp.status() {
http::StatusCode::CREATED | http::StatusCode::OK => {
info!("object {} write finished: size {:?}", &p, args.size);
debug!("object {} write finished: size {:?}", &p, args.size);
Ok(args.size as usize)
}
_ => Err(parse_error_response(resp, "write", &p).await),
}
}
#[trace("stat")]
async fn stat(&self, args: &OpStat) -> Result<Metadata> {
increment_counter!("opendal_azure_stat_requests");

let p = self.get_abs_path(&args.path);
info!("object {} stat start", &p);
debug!("object {} stat start", &p);

// Stat root always returns a DIR.
if self.get_rel_path(&p).is_empty() {
Expand All @@ -280,11 +282,11 @@ impl Accessor for Backend {
m.set_mode(ObjectMode::DIR);
m.set_complete();

info!("backed root object stat finished");
debug!("backed root object stat finished");
return Ok(m);
}

let resp = self.head_object(&p).await?;
let resp = self.get_blob_properties(&p).await?;
match resp.status() {
http::StatusCode::OK => {
let mut m = Metadata::default();
Expand Down Expand Up @@ -321,7 +323,7 @@ impl Accessor for Backend {

m.set_complete();

info!("object {} stat finished: {:?}", &p, m);
debug!("object {} stat finished: {:?}", &p, m);
Ok(m)
}
StatusCode::NOT_FOUND if p.ends_with('/') => {
Expand All @@ -331,36 +333,33 @@ impl Accessor for Backend {
m.set_mode(ObjectMode::DIR);
m.set_complete();

info!("object {} stat finished", &p);
debug!("object {} stat finished", &p);
Ok(m)
}
_ => Err(parse_error_response(resp, "stat", &p).await),
}
}
#[trace("delete")]
async fn delete(&self, args: &OpDelete) -> Result<()> {
increment_counter!("opendal_azure_delete_requests");

let p = self.get_abs_path(&args.path);
info!("object {} delete start", &p);
debug!("object {} delete start", &p);

let resp = self.delete_object(&p).await?;
let resp = self.delete_blob(&p).await?;
match resp.status() {
StatusCode::NO_CONTENT => {
info!("object {} delete finished", &p);
debug!("object {} delete finished", &p);
Ok(())
}
_ => Err(parse_error_response(resp, "delete", &p).await),
}
}
#[warn(dead_code)]
async fn list(&self, args: &OpList) -> Result<BoxedObjectStream> {
let _ = args;
unimplemented!()
}
}

impl Backend {
pub(crate) async fn get_object(
#[trace("get_blob")]
pub(crate) async fn get_blob(
&self,
path: &str,
offset: Option<u64>,
Expand Down Expand Up @@ -394,7 +393,8 @@ impl Backend {
}
})
}
pub(crate) async fn put_object(
#[trace("put_blob")]
pub(crate) async fn put_blob(
&self,
path: &str,
r: BoxedAsyncReader,
Expand Down Expand Up @@ -427,8 +427,11 @@ impl Backend {
})
}

#[warn(dead_code)]
pub(crate) async fn head_object(&self, path: &str) -> Result<hyper::Response<hyper::Body>> {
#[trace("get_blob_properties")]
pub(crate) async fn get_blob_properties(
&self,
path: &str,
) -> Result<hyper::Response<hyper::Body>> {
let req = hyper::Request::head(&format!(
"https://{}.{}/{}/{}",
self.account_name, self.endpoint, self.container, path
Expand All @@ -450,7 +453,8 @@ impl Backend {
})
}

pub(crate) async fn delete_object(&self, path: &str) -> Result<hyper::Response<hyper::Body>> {
#[trace("delete_blob")]
pub(crate) async fn delete_blob(&self, path: &str) -> Result<hyper::Response<hyper::Body>> {
let req = hyper::Request::delete(&format!(
"https://{}.{}/{}/{}",
self.account_name, self.endpoint, self.container, path
Expand All @@ -472,16 +476,6 @@ impl Backend {
}
})
}
#[allow(dead_code)]
pub(crate) async fn list_object(
&self,
path: &str,
continuation_token: &str,
) -> Result<hyper::Response<hyper::Body>> {
let _ = path;
let _ = continuation_token;
unimplemented!()
}
}
struct ByteStream(hyper::Response<hyper::Body>);

Expand Down
2 changes: 0 additions & 2 deletions src/services/azblob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@
pub mod backend;
pub use backend::Backend;
pub use backend::Builder;

mod object_stream;
13 changes: 0 additions & 13 deletions src/services/azblob/object_stream.rs

This file was deleted.

25 changes: 16 additions & 9 deletions src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ use futures::io;
use futures::AsyncReadExt;
use futures::AsyncSeekExt;
use futures::AsyncWriteExt;
use log::debug;
use log::error;
use log::info;
use metrics::increment_counter;
use minitrace::trace;
use tokio::fs;

use super::error::parse_io_error;
Expand Down Expand Up @@ -125,11 +127,12 @@ impl Backend {

#[async_trait]
impl Accessor for Backend {
#[trace("read")]
async fn read(&self, args: &OpRead) -> Result<BoxedAsyncReader> {
increment_counter!("opendal_fs_read_requests");

let path = self.get_abs_path(&args.path);
info!(
debug!(
"object {} read start: offset {:?}, size {:?}",
&path, args.offset, args.size
);
Expand Down Expand Up @@ -159,18 +162,19 @@ impl Accessor for Backend {
None => Box::new(f),
};

info!(
debug!(
"object {} reader created: offset {:?}, size {:?}",
&path, args.offset, args.size
);
Ok(r)
}

#[trace("write")]
async fn write(&self, mut r: BoxedAsyncReader, args: &OpWrite) -> Result<usize> {
increment_counter!("opendal_fs_write_requests");

let path = self.get_abs_path(&args.path);
info!("object {} write start: size {}", &path, args.size);
debug!("object {} write start: size {}", &path, args.size);

// Create dir before write path.
//
Expand Down Expand Up @@ -224,15 +228,16 @@ impl Accessor for Backend {
e
})?;

info!("object {} write finished: size {:?}", &path, args.size);
debug!("object {} write finished: size {:?}", &path, args.size);
Ok(s as usize)
}

#[trace("stat")]
async fn stat(&self, args: &OpStat) -> Result<Metadata> {
increment_counter!("opendal_fs_stat_requests");

let path = self.get_abs_path(&args.path);
info!("object {} stat start", &path);
debug!("object {} stat start", &path);

let meta = fs::metadata(&path).await.map_err(|e| {
let e = parse_io_error(e, "stat", &path);
Expand All @@ -255,15 +260,16 @@ impl Accessor for Backend {
);
m.set_complete();

info!("object {} stat finished", &path);
debug!("object {} stat finished", &path);
Ok(m)
}

#[trace("delete")]
async fn delete(&self, args: &OpDelete) -> Result<()> {
increment_counter!("opendal_fs_delete_requests");

let path = self.get_abs_path(&args.path);
info!("object {} delete start", &path);
debug!("object {} delete start", &path);

// PathBuf.is_dir() is not free, call metadata directly instead.
let meta = fs::metadata(&path).await;
Expand All @@ -289,15 +295,16 @@ impl Accessor for Backend {

f.map_err(|e| parse_io_error(e, "delete", &path))?;

info!("object {} delete finished", &path);
debug!("object {} delete finished", &path);
Ok(())
}

#[trace("list")]
async fn list(&self, args: &OpList) -> Result<BoxedObjectStream> {
increment_counter!("opendal_fs_list_requests");

let path = self.get_abs_path(&args.path);
info!("object {} list start", &path);
debug!("object {} list start", &path);

let f = fs::read_dir(&path).await.map_err(|e| {
let e = parse_io_error(e, "read", &path);
Expand Down
6 changes: 6 additions & 0 deletions src/services/memory/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use async_trait::async_trait;
use bytes::Bytes;
use futures::io;
use futures::TryStreamExt;
use minitrace::trace;

use crate::error::Error;
use crate::error::Kind;
Expand Down Expand Up @@ -79,6 +80,7 @@ impl Backend {

#[async_trait]
impl Accessor for Backend {
#[trace("read")]
async fn read(&self, args: &OpRead) -> Result<BoxedAsyncReader> {
let path = Backend::normalize_path(&args.path);

Expand Down Expand Up @@ -119,6 +121,7 @@ impl Accessor for Backend {
let r: BoxedAsyncReader = Box::new(BytesStream(data).into_async_read());
Ok(r)
}
#[trace("write")]
async fn write(&self, mut r: BoxedAsyncReader, args: &OpWrite) -> Result<usize> {
let path = Backend::normalize_path(&args.path);

Expand Down Expand Up @@ -146,6 +149,7 @@ impl Accessor for Backend {

Ok(n as usize)
}
#[trace("stat")]
async fn stat(&self, args: &OpStat) -> Result<Metadata> {
let path = Backend::normalize_path(&args.path);

Expand Down Expand Up @@ -176,6 +180,7 @@ impl Accessor for Backend {

Ok(meta)
}
#[trace("delete")]
async fn delete(&self, args: &OpDelete) -> Result<()> {
let path = Backend::normalize_path(&args.path);

Expand All @@ -184,6 +189,7 @@ impl Accessor for Backend {

Ok(())
}
#[trace("list")]
async fn list(&self, args: &OpList) -> Result<BoxedObjectStream> {
let path = Backend::normalize_path(&args.path);

Expand Down
Loading

0 comments on commit 51c0d22

Please # to comment.