Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add storage metrics for opendal storage. #4752

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
27 changes: 25 additions & 2 deletions quickwit/quickwit-storage/src/opendal_storage/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tokio::io::{AsyncRead, AsyncWriteExt};
use crate::storage::SendableAsync;
use crate::{
BulkDeleteError, OwnedBytes, PutPayload, Storage, StorageError, StorageErrorKind,
StorageResolverError, StorageResult,
StorageResolverError, StorageResult, STORAGE_METRICS,
};

/// OpenDAL based storage implementation.
Expand Down Expand Up @@ -88,20 +88,35 @@ impl Storage for OpendalStorage {
tokio::io::copy(&mut payload_reader, &mut storage_writer).await?;
storage_writer.close().await?;

// FIXME: should be payload.len() / ByteSize::mb(8)?
Copy link
Contributor

@Xuanwo Xuanwo Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, after buffer enabled, opendal makes sure all upload parts is buffer size.

// crate::STORAGE_METRICS.object_storage_put_parts.inc();
crate::STORAGE_METRICS
.object_storage_upload_num_bytes
.inc_by(payload.len());

Ok(())
}

async fn copy_to(&self, path: &Path, output: &mut dyn SendableAsync) -> StorageResult<()> {
let path = path.as_os_str().to_string_lossy();
let mut storage_reader = self.op.reader(&path).await?;
tokio::io::copy(&mut storage_reader, output).await?;
let num_bytes_copied = tokio::io::copy(&mut storage_reader, output).await?;
output.flush().await?;
crate::STORAGE_METRICS.object_storage_get_total.inc();
STORAGE_METRICS
.object_storage_download_num_bytes
.inc_by(num_bytes_copied);

Ok(())
}

async fn get_slice(&self, path: &Path, range: Range<usize>) -> StorageResult<OwnedBytes> {
let path = path.as_os_str().to_string_lossy();
let range = range.start as u64..range.end as u64;
crate::STORAGE_METRICS.object_storage_get_total.inc();
STORAGE_METRICS
.object_storage_download_num_bytes
.inc_by(range.end - range.start);
let storage_content = self.op.read_with(&path).range(range).await?;

Ok(OwnedBytes::new(storage_content))
Expand All @@ -114,14 +129,22 @@ impl Storage for OpendalStorage {
) -> StorageResult<Box<dyn AsyncRead + Send + Unpin>> {
let path = path.as_os_str().to_string_lossy();
let range = range.start as u64..range.end as u64;
crate::STORAGE_METRICS.object_storage_get_total.inc();
STORAGE_METRICS
.object_storage_download_num_bytes
.inc_by(range.end - range.start);
let storage_reader = self.op.reader_with(&path).range(range).await?;

Ok(Box::new(storage_reader))
}

async fn get_all(&self, path: &Path) -> StorageResult<OwnedBytes> {
let path = path.as_os_str().to_string_lossy();
crate::STORAGE_METRICS.object_storage_get_total.inc();
let storage_content = self.op.read(&path).await?;
STORAGE_METRICS
.object_storage_download_num_bytes
.inc_by(storage_content.len() as u64);

Ok(OwnedBytes::new(storage_content))
}
Expand Down
Loading