Skip to content

Commit

Permalink
feat(query): add bucket name to storage http request metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Feb 10, 2025
1 parent aa45b18 commit e887c6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/common/metrics/src/metrics/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static OMIT_FILTER_ROWS: LazyLock<Counter> = LazyLock::new(|| register_counter("
struct StorageHttpLabels {
host: String,
method: String,
bucket: String,
}

static STORAGE_HTTP_REQUESTS_COUNT: LazyLock<FamilyCounter<StorageHttpLabels>> =
Expand Down Expand Up @@ -320,9 +321,13 @@ pub fn metrics_inc_omit_filter_rows(c: u64) {
}

/// Storage Http metrics.
pub fn metrics_inc_storage_http_requests_count(host: String, method: String) {
pub fn metrics_inc_storage_http_requests_count(host: String, method: String, bucket: String) {
STORAGE_HTTP_REQUESTS_COUNT
.get_or_create(&StorageHttpLabels { host, method })
.get_or_create(&StorageHttpLabels {
host,
method,
bucket,
})
.inc();
}

Expand Down
14 changes: 13 additions & 1 deletion src/common/storage/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ impl HttpFetch for StorageHttpClient {
}
m => m.as_str(),
};
metrics_inc_storage_http_requests_count(host.to_string(), method.to_string());
// get first component in path as bucket name
let bucket = match url.path_segments() {
Some(mut segments) => match segments.next() {
Some(bucket) => bucket,
None => "-",
},
None => "-",
};
metrics_inc_storage_http_requests_count(
host.to_string(),
method.to_string(),
bucket.to_string(),
);

let (parts, body) = req.into_parts();

Expand Down

0 comments on commit e887c6e

Please sign in to comment.