Skip to content

Commit

Permalink
feat(metrics): new storage_http_requests_count
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Nov 5, 2024
1 parent db32c8d commit 6232187
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/common/metrics/src/metrics/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,30 @@ use std::sync::LazyLock;
use std::time::Duration;

use databend_common_base::runtime::metrics::register_counter;
use databend_common_base::runtime::metrics::register_counter_family;
use databend_common_base::runtime::metrics::register_gauge;
use databend_common_base::runtime::metrics::register_histogram_in_milliseconds;
use databend_common_base::runtime::metrics::Counter;
use databend_common_base::runtime::metrics::FamilyCounter;
use databend_common_base::runtime::metrics::Gauge;
use databend_common_base::runtime::metrics::Histogram;
use prometheus_client::encoding::EncodeLabelSet;

// Common metrics.
static OMIT_FILTER_ROWGROUPS: LazyLock<Counter> =
LazyLock::new(|| register_counter("omit_filter_rowgroups"));
static OMIT_FILTER_ROWS: LazyLock<Counter> = LazyLock::new(|| register_counter("omit_filter_rows"));

/// Storage Http metrics.
#[derive(Clone, Debug, EncodeLabelSet, Hash, PartialEq, Eq)]
struct StorageHttpLabels {
host: String,
method: String,
}

static STORAGE_HTTP_REQUESTS_COUNT: LazyLock<FamilyCounter<StorageHttpLabels>> =
LazyLock::new(|| register_counter_family("storage_http_requests_count"));

// COPY metrics.
static COPY_PURGE_FILE_COUNTER: LazyLock<Counter> =
LazyLock::new(|| register_counter("copy_purge_file_counter"));
Expand Down Expand Up @@ -306,6 +319,13 @@ pub fn metrics_inc_omit_filter_rows(c: u64) {
OMIT_FILTER_ROWS.inc_by(c);
}

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

/// COPY
pub fn metrics_inc_copy_purge_files_counter(c: u32) {
COPY_PURGE_FILE_COUNTER.inc_by(c as u64);
Expand Down
1 change: 1 addition & 0 deletions src/common/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ databend-common-base = { workspace = true }
databend-common-exception = { workspace = true }
databend-common-expression = { workspace = true }
databend-common-meta-app = { workspace = true }
databend-common-metrics = { workspace = true }
databend-enterprise-storage-encryption = { workspace = true }
flagset = { workspace = true }
futures = { workspace = true }
Expand Down
14 changes: 14 additions & 0 deletions src/common/storage/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::mem;
use std::str::FromStr;

use databend_common_base::http_client::GLOBAL_HTTP_CLIENT;
use databend_common_metrics::storage::metrics_inc_storage_http_requests_count;
use futures::TryStreamExt;
use http::Request;
use http::Response;
Expand Down Expand Up @@ -45,6 +46,19 @@ impl HttpFetch for StorageHttpClient {
let uri = req.uri().clone();
let is_head = req.method() == http::Method::HEAD;

let host = uri.host().unwrap_or_default();
let method = match req.method() {
&http::Method::GET => {
if uri.path() == "/" {
"LIST"
} else {
"GET"
}
}
m => m.as_str(),
};
metrics_inc_storage_http_requests_count(host.to_string(), method.to_string());

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

let mut req_builder = self
Expand Down

0 comments on commit 6232187

Please sign in to comment.