Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

services: Add basic metrics #127

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pin-project = "1"
reqwest = "0.11"
thiserror = "1"
tower = "0.4"
metrics = "0.18"

[dev-dependencies]
anyhow = "1.0"
Expand Down
11 changes: 11 additions & 0 deletions src/services/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use futures::AsyncWriteExt;
use log::debug;
use log::error;
use log::info;
use metrics::increment_counter;

use crate::error::Error;
use crate::error::Kind;
Expand Down Expand Up @@ -132,6 +133,8 @@ impl Backend {
#[async_trait]
impl Accessor for Backend {
async fn read(&self, args: &OpRead) -> Result<BoxedAsyncReader> {
increment_counter!("opendal_fs_read_requests");

let path = self.get_abs_path(&args.path);
info!(
"object {} read start: offset {:?}, size {:?}",
Expand Down Expand Up @@ -170,6 +173,8 @@ impl Accessor for Backend {
}

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);

Expand Down Expand Up @@ -236,6 +241,8 @@ impl Accessor for Backend {
}

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);

Expand All @@ -262,6 +269,8 @@ impl Accessor for Backend {
}

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);

Expand Down Expand Up @@ -297,6 +306,8 @@ impl Accessor for Backend {
}

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);

Expand Down
9 changes: 9 additions & 0 deletions src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use log::debug;
use log::error;
use log::info;
use log::warn;
use metrics::increment_counter;
use once_cell::sync::Lazy;

use super::error::parse_get_object_error;
Expand Down Expand Up @@ -375,6 +376,8 @@ impl Backend {
#[async_trait]
impl Accessor for Backend {
async fn read(&self, args: &OpRead) -> Result<BoxedAsyncReader> {
increment_counter!("opendal_s3_read_requests");

let p = self.get_abs_path(&args.path);
info!(
"object {} read start: offset {:?}, size {:?}",
Expand Down Expand Up @@ -430,6 +433,8 @@ impl Accessor for Backend {
}

async fn stat(&self, args: &OpStat) -> Result<Metadata> {
increment_counter!("opendal_s3_stat_requests");

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

Expand Down Expand Up @@ -479,6 +484,8 @@ impl Accessor for Backend {
}

async fn delete(&self, args: &OpDelete) -> Result<()> {
increment_counter!("opendal_s3_delete_requests");

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

Expand All @@ -496,6 +503,8 @@ impl Accessor for Backend {
}

async fn list(&self, args: &OpList) -> Result<BoxedObjectStream> {
increment_counter!("opendal_s3_list_requests");

let mut path = self.get_abs_path(&args.path);
// Make sure list path is endswith '/'
if !path.ends_with('/') && !path.is_empty() {
Expand Down