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

feat: add path prefix label to obejct storage metrics #4277

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
147 changes: 114 additions & 33 deletions src/object-store/src/layers/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ use prometheus::{
Histogram, HistogramTimer, HistogramVec, IntCounterVec,
};

use crate::util::extract_parent_path;

type Result<T> = std::result::Result<T, opendal::Error>;

lazy_static! {
static ref REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!(
"opendal_requests_total",
"Total times of all kinds of operation being called",
&["scheme", "operation"],
&["scheme", "operation", "path"],
)
.unwrap();
static ref REQUESTS_DURATION_SECONDS: HistogramVec = register_histogram_vec!(
Expand All @@ -40,7 +42,7 @@ lazy_static! {
"Histogram of the time spent on specific operation",
exponential_buckets(0.01, 2.0, 16).unwrap()
),
&["scheme", "operation"]
&["scheme", "operation", "path"]
)
.unwrap();
static ref BYTES_TOTAL: HistogramVec = register_histogram_vec!(
Expand All @@ -49,7 +51,7 @@ lazy_static! {
"Total size of sync or async Read/Write",
exponential_buckets(0.01, 2.0, 16).unwrap()
),
&["scheme", "operation"]
&["scheme", "operation", "path"]
)
.unwrap();
}
Expand Down Expand Up @@ -126,12 +128,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::CreateDir.into_static()])
.with_label_values(&[
&self.scheme,
Operation::CreateDir.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::CreateDir.into_static()])
.with_label_values(&[
&self.scheme,
Operation::CreateDir.into_static(),
&path_label,
])
.start_timer();
let create_res = self.inner.create_dir(path, args).await;

Expand All @@ -143,12 +154,13 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::Read.into_static()])
.with_label_values(&[&self.scheme, Operation::Read.into_static(), &path_label])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::Read.into_static()])
.with_label_values(&[&self.scheme, Operation::Read.into_static(), &path_label])
.start_timer();

let (rp, r) = self.inner.read(path, args).await.map_err(|e| {
Expand All @@ -161,19 +173,24 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
PrometheusMetricWrapper::new(
r,
Operation::Read,
BYTES_TOTAL.with_label_values(&[&self.scheme, Operation::Read.into_static()]),
BYTES_TOTAL.with_label_values(&[
&self.scheme,
Operation::Read.into_static(),
&path_label,
]),
timer,
),
))
}

async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::Write.into_static()])
.with_label_values(&[&self.scheme, Operation::Write.into_static(), &path_label])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::Write.into_static()])
.with_label_values(&[&self.scheme, Operation::Write.into_static(), &path_label])
.start_timer();

let (rp, r) = self.inner.write(path, args).await.map_err(|e| {
Expand All @@ -186,18 +203,23 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
PrometheusMetricWrapper::new(
r,
Operation::Write,
BYTES_TOTAL.with_label_values(&[&self.scheme, Operation::Write.into_static()]),
BYTES_TOTAL.with_label_values(&[
&self.scheme,
Operation::Write.into_static(),
&path_label,
]),
timer,
),
))
}

async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::Stat.into_static()])
.with_label_values(&[&self.scheme, Operation::Stat.into_static(), &path_label])
.inc();
let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::Stat.into_static()])
.with_label_values(&[&self.scheme, Operation::Stat.into_static(), &path_label])
.start_timer();

let stat_res = self.inner.stat(path, args).await;
Expand All @@ -209,12 +231,13 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

async fn delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::Delete.into_static()])
.with_label_values(&[&self.scheme, Operation::Delete.into_static(), &path_label])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::Delete.into_static()])
.with_label_values(&[&self.scheme, Operation::Delete.into_static(), &path_label])
.start_timer();

let delete_res = self.inner.delete(path, args).await;
Expand All @@ -226,12 +249,13 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::List.into_static()])
.with_label_values(&[&self.scheme, Operation::List.into_static(), &path_label])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::List.into_static()])
.with_label_values(&[&self.scheme, Operation::List.into_static(), &path_label])
.start_timer();

let list_res = self.inner.list(path, args).await;
Expand All @@ -245,11 +269,11 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {

async fn batch(&self, args: OpBatch) -> Result<RpBatch> {
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::Batch.into_static()])
.with_label_values(&[&self.scheme, Operation::Batch.into_static(), ""])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::Batch.into_static()])
.with_label_values(&[&self.scheme, Operation::Batch.into_static(), ""])
.start_timer();
let result = self.inner.batch(args).await;

Expand All @@ -261,12 +285,13 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::Presign.into_static()])
.with_label_values(&[&self.scheme, Operation::Presign.into_static(), &path_label])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::Presign.into_static()])
.with_label_values(&[&self.scheme, Operation::Presign.into_static(), &path_label])
.start_timer();
let result = self.inner.presign(path, args).await;
timer.observe_duration();
Expand All @@ -278,12 +303,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

fn blocking_create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::BlockingCreateDir.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingCreateDir.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::BlockingCreateDir.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingCreateDir.into_static(),
&path_label,
])
.start_timer();
let result = self.inner.blocking_create_dir(path, args);

Expand All @@ -296,12 +330,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

fn blocking_read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::BlockingReader)> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::BlockingRead.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingRead.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::BlockingRead.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingRead.into_static(),
&path_label,
])
sunng87 marked this conversation as resolved.
Show resolved Hide resolved
.start_timer();

self.inner
Expand All @@ -315,6 +358,7 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
BYTES_TOTAL.with_label_values(&[
&self.scheme,
Operation::BlockingRead.into_static(),
&path_label,
]),
timer,
),
Expand All @@ -327,12 +371,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

fn blocking_write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::BlockingWriter)> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::BlockingWrite.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingWrite.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::BlockingWrite.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingWrite.into_static(),
&path_label,
])
sunng87 marked this conversation as resolved.
Show resolved Hide resolved
.start_timer();

self.inner
Expand All @@ -346,6 +399,7 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
BYTES_TOTAL.with_label_values(&[
&self.scheme,
Operation::BlockingWrite.into_static(),
&path_label,
]),
timer,
),
Expand All @@ -358,12 +412,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

fn blocking_stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::BlockingStat.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingStat.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::BlockingStat.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingStat.into_static(),
&path_label,
])
.start_timer();
let result = self.inner.blocking_stat(path, args);
timer.observe_duration();
Expand All @@ -374,12 +437,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

fn blocking_delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::BlockingDelete.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingDelete.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::BlockingDelete.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingDelete.into_static(),
&path_label,
])
.start_timer();
let result = self.inner.blocking_delete(path, args);
timer.observe_duration();
Expand All @@ -391,12 +463,21 @@ impl<A: Access> LayeredAccess for PrometheusAccess<A> {
}

fn blocking_list(&self, path: &str, args: OpList) -> Result<(RpList, Self::BlockingLister)> {
let path_label = extract_parent_path(path);
REQUESTS_TOTAL
.with_label_values(&[&self.scheme, Operation::BlockingList.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingList.into_static(),
&path_label,
])
.inc();

let timer = REQUESTS_DURATION_SECONDS
.with_label_values(&[&self.scheme, Operation::BlockingList.into_static()])
.with_label_values(&[
&self.scheme,
Operation::BlockingList.into_static(),
&path_label,
])
.start_timer();
let result = self.inner.blocking_list(path, args);
timer.observe_duration();
Expand Down
Loading