Skip to content

Commit

Permalink
Refine tracing events
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Aug 20, 2021
1 parent 1f109ae commit 45cb64d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
14 changes: 9 additions & 5 deletions src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::{
sync::{oneshot, RwLock},
time,
};
use tracing::{error, info, trace};
use tracing::{debug, error, info};
use webdav_handler::fs::{DavDirEntry, DavMetaData, FsError, FsFuture, FsResult};

const API_BASE_URL: &str = "https://api.aliyundrive.com";
Expand Down Expand Up @@ -74,7 +74,7 @@ impl AliyunDrive {
if drive_id.is_empty() {
bail!("get default drive id failed");
}
info!("default drive id is {}", drive_id);
info!(drive_id = %drive_id, "found default drive id");
drive.drive_id = Some(drive_id);

Ok(drive)
Expand All @@ -97,7 +97,11 @@ impl AliyunDrive {
let res = res.json::<RefreshTokenResponse>().await?;
cred.refresh_token = res.refresh_token.clone();
cred.access_token = Some(res.access_token.clone());
info!("refresh token succeed for {}", res.nick_name);
info!(
refresh_token = %res.refresh_token,
nick_name = %res.nick_name,
"refresh token succeed"
);
Ok(res)
}

Expand Down Expand Up @@ -211,7 +215,7 @@ impl AliyunDrive {
.expect("Time went backwards")
.as_secs();
if current_ts >= expires {
trace!("download url {} expired, get a new one", url);
debug!(url = %url, "download url expired, get a new one");
self.get_download_url(file_id).await?
} else {
url.to_string()
Expand All @@ -223,7 +227,7 @@ impl AliyunDrive {
url.to_string()
};
let end_pos = start_pos + size as u64 - 1;
trace!("download {} from {} to {}", url, start_pos, end_pos);
debug!(url = %url, start = start_pos, end = end_pos, "download file");
let range = format!("bytes={}-{}", start_pos, end_pos);
let res = self
.client
Expand Down
29 changes: 19 additions & 10 deletions src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ impl AliyunDriveFileSystem {
}

async fn cache_file_id(&self, path: String, file_id: String) {
trace!("cache file_id {}: {}", file_id, path);
trace!(path = %path, file_id = %file_id, "cache file_id");
self.file_ids.insert(path, file_id).await;
}

async fn cache_file(&self, file_id: String, file: AliyunFile) {
trace!("cache file {}: {}", file_id, file.name);
trace!(file_id = %file_id, file_name = %file.name, "cache file");
self.file_cache.insert(file_id, file).await;
}

async fn cache_read_dir(&self, path: &DavPath, file_id: String, files: Vec<AliyunFile>) {
trace!("cache read_dir {} file count: {}", file_id, files.len());
trace!(file_id = %file_id, count = files.len(), "cache read_dir");
let rel_path = path.as_rel_ospath();
for file in &files {
self.cache_file(file.id.clone(), file.clone()).await;
Expand All @@ -165,7 +165,7 @@ impl AliyunDriveFileSystem {

impl DavFileSystem for AliyunDriveFileSystem {
fn open<'a>(&'a self, path: &'a DavPath, _options: OpenOptions) -> FsFuture<Box<dyn DavFile>> {
debug!("fs: open {}", path);
debug!(path = %path, "fs: open");
async move {
let file_id = self.get_file_id(path).await?.ok_or(FsError::NotFound)?;
let file = self.get_file(file_id).await?;
Expand All @@ -180,7 +180,7 @@ impl DavFileSystem for AliyunDriveFileSystem {
path: &'a DavPath,
_meta: ReadDirMeta,
) -> FsFuture<FsStream<Box<dyn DavDirEntry>>> {
debug!("fs: read_dir {}", path);
debug!(path = %path, "fs: read_dir");
async move {
let files = self.read_dir_and_cache(path).await?;
let mut v: Vec<Box<dyn DavDirEntry>> = Vec::with_capacity(files.len());
Expand All @@ -197,7 +197,7 @@ impl DavFileSystem for AliyunDriveFileSystem {
}

fn metadata<'a>(&'a self, path: &'a DavPath) -> FsFuture<Box<dyn DavMetaData>> {
debug!("fs: metadata {}", path);
debug!(path = %path, "fs: metadata");
async move {
let file_id = self.get_file_id(path).await?.ok_or(FsError::NotFound)?;
if &file_id == "root" {
Expand Down Expand Up @@ -241,7 +241,7 @@ impl AliyunDavFile {

impl DavFile for AliyunDavFile {
fn metadata(&'_ mut self) -> FsFuture<'_, Box<dyn DavMetaData>> {
debug!("file: metadata {}", self.file.name);
debug!(file_id = %self.file.id, file_name = %self.file.name, "file: metadata");
async move {
let file = self.file.clone();
Ok(Box::new(file) as Box<dyn DavMetaData>)
Expand All @@ -259,8 +259,12 @@ impl DavFile for AliyunDavFile {

fn read_bytes(&mut self, count: usize) -> FsFuture<Bytes> {
debug!(
"file: read_bytes {}, pos {} count {}, size {}",
self.file.name, self.current_pos, count, self.file.size
file_id = %self.file.id,
file_name = %self.file.name,
pos = self.current_pos,
count = count,
size = self.file.size,
"file: read_bytes",
);
async move {
let download_url = self.file.download_url.as_ref().ok_or(FsError::NotFound)?;
Expand All @@ -276,7 +280,12 @@ impl DavFile for AliyunDavFile {
}

fn seek(&mut self, pos: SeekFrom) -> FsFuture<u64> {
debug!("file: seek {} to {:?}", self.file.name, pos);
debug!(
file_id = %self.file.id,
file_name = %self.file.name,
pos = ?pos,
"file: seek"
);
async move {
let new_pos = match pos {
SeekFrom::Start(pos) => pos,
Expand Down

0 comments on commit 45cb64d

Please sign in to comment.