Skip to content

Commit

Permalink
chore: unify the meta metrics styling (#2875)
Browse files Browse the repository at this point in the history
* chore: unify the meta metrics styling

* chore: apply suggestions from CR
  • Loading branch information
WenyXu authored Dec 6, 2023
1 parent a415685 commit 1141dbe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
32 changes: 20 additions & 12 deletions src/meta-srv/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,45 @@ use lazy_static::lazy_static;
use prometheus::*;

lazy_static! {
pub static ref METRIC_META_KV_REQUEST: HistogramVec = register_histogram_vec!(
"meta_kv_request",
/// Elapsed time to responding kv requests.
pub static ref METRIC_META_KV_REQUEST_ELAPSED: HistogramVec = register_histogram_vec!(
"meta_kv_request_elapsed",
"meta kv request",
&["target", "op", "cluster_id"]
)
.unwrap();
/// The heartbeat connection gauge.
pub static ref METRIC_META_HEARTBEAT_CONNECTION_NUM: IntGauge = register_int_gauge!(
"meta_heartbeat_connection_num",
"meta heartbeat connection num"
)
.unwrap();
/// Elapsed time to execution of heartbeat handlers.
pub static ref METRIC_META_HANDLER_EXECUTE: HistogramVec =
register_histogram_vec!("meta_handler_execute", "meta handler execute", &["name"]).unwrap();
/// Inactive region gauge.
pub static ref METRIC_META_INACTIVE_REGIONS: IntGauge =
register_int_gauge!("meta_inactive_regions", "meta inactive regions").unwrap();
pub static ref METRIC_META_LEADER_CACHED_KV_LOAD: HistogramVec =
/// Elapsed time to leader cache kv.
pub static ref METRIC_META_LEADER_CACHED_KV_LOAD_ELAPSED: HistogramVec =
register_histogram_vec!("meta_leader_cache_kv_load", "meta load cache", &["prefix"])
.unwrap();
pub static ref METRIC_META_LOAD_FOLLOWER_METADATA: Histogram = register_histogram!(
"meta_load_follower_metadata",
/// Elapsed time to load follower region metadata.
pub static ref METRIC_META_LOAD_FOLLOWER_METADATA_ELAPSED: Histogram = register_histogram!(
"meta_load_follower_metadata_elapsed",
"meta load follower regions metadata elapsed"
)
.unwrap();
pub static ref METRIC_META_LOAD_LEADER_METADATA: Histogram = register_histogram!(
"meta_load_leader_metadata",
/// Elapsed time to load leader region metadata.
pub static ref METRIC_META_LOAD_LEADER_METADATA_ELAPSED: Histogram = register_histogram!(
"meta_load_leader_metadata_elapsed",
"meta load leader regions metadata elapsed"
)
.unwrap();
pub static ref METRIC_META_KV_CACHE_BATCH_GET_HIT_RATE: Gauge = register_gauge!(
"meta_kv_cache_batch_get_hit_rate",
"meta kv cache batch get hit rate"
)
.unwrap();
/// Meta kv cache hit counter.
pub static ref METRIC_META_KV_CACHE_HIT: IntCounterVec =
register_int_counter_vec!("meta_kv_cache_hit", "meta kv cache hit", &["op"]).unwrap();
/// Meta kv cache miss counter.
pub static ref METRIC_META_KV_CACHE_MISS: IntCounterVec =
register_int_counter_vec!("meta_kv_cache_miss", "meta kv cache miss", &["op"]).unwrap();
}
4 changes: 2 additions & 2 deletions src/meta-srv/src/region/lease_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl RegionLeaseKeeper {
let table_ids = tables.keys().copied().collect::<Vec<_>>();

let metadata_subset = {
let _timer = metrics::METRIC_META_LOAD_LEADER_METADATA.start_timer();
let _timer = metrics::METRIC_META_LOAD_LEADER_METADATA_ELAPSED.start_timer();
self.collect_tables_metadata(&table_ids).await?
};

Expand Down Expand Up @@ -140,7 +140,7 @@ impl RegionLeaseKeeper {
let table_ids = tables.keys().copied().collect::<Vec<_>>();

let metadata_subset = {
let _timer = metrics::METRIC_META_LOAD_FOLLOWER_METADATA.start_timer();
let _timer = metrics::METRIC_META_LOAD_FOLLOWER_METADATA_ELAPSED.start_timer();
self.collect_tables_metadata(&table_ids).await?
};

Expand Down
16 changes: 8 additions & 8 deletions src/meta-srv/src/service/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tonic::{Request, Response};

use crate::error::{self, MissingRequestHeaderSnafu};
use crate::metasrv::MetaSrv;
use crate::metrics::METRIC_META_KV_REQUEST;
use crate::metrics::METRIC_META_KV_REQUEST_ELAPSED;
use crate::service::GrpcResult;

#[async_trait::async_trait]
Expand All @@ -48,7 +48,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[self.kv_backend().name(), "range", cluster_id_str.as_str()])
.start_timer();

Expand All @@ -74,7 +74,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[self.kv_backend().name(), "put", cluster_id_str.as_str()])
.start_timer();

Expand All @@ -100,7 +100,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[
self.kv_backend().name(),
"batch_get",
Expand Down Expand Up @@ -130,7 +130,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[
self.kv_backend().name(),
"batch_pub",
Expand Down Expand Up @@ -163,7 +163,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[
self.kv_backend().name(),
"batch_delete",
Expand Down Expand Up @@ -196,7 +196,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[
self.kv_backend().name(),
"compare_and_put",
Expand Down Expand Up @@ -229,7 +229,7 @@ impl store_server::Store for MetaSrv {
.cluster_id;
let cluster_id_str = cluster_id.to_string();

let _timer = METRIC_META_KV_REQUEST
let _timer = METRIC_META_KV_REQUEST_ELAPSED
.with_label_values(&[
self.kv_backend().name(),
"delete_range",
Expand Down
12 changes: 9 additions & 3 deletions src/meta-srv/src/service/store/cached_kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl LeaderCachedKvBackend {
/// The caller MUST ensure during the loading, there are no mutation requests reaching the `LeaderCachedKvStore`.
pub async fn load(&self) -> Result<()> {
for prefix in &CACHE_KEY_PREFIXES[..] {
let _timer = metrics::METRIC_META_LEADER_CACHED_KV_LOAD.with_label_values(&[prefix]);
let _timer =
metrics::METRIC_META_LEADER_CACHED_KV_LOAD_ELAPSED.with_label_values(&[prefix]);

// TODO(weny): Refactors PaginationStream's output to unary output.
let stream = PaginationStream::new(
Expand Down Expand Up @@ -261,15 +262,20 @@ impl KvBackend for LeaderCachedKvBackend {
.map(|kv| kv.key.clone())
.collect::<HashSet<_>>();

let hit_rate = hit_keys.len() as f64 / req.keys.len() as f64;
metrics::METRIC_META_KV_CACHE_BATCH_GET_HIT_RATE.set(hit_rate);
metrics::METRIC_META_KV_CACHE_HIT
.with_label_values(&[&"batch_get"])
.inc_by(hit_keys.len() as u64);

let missed_keys = req
.keys
.iter()
.filter(|key| !hit_keys.contains(*key))
.cloned()
.collect::<Vec<_>>();
metrics::METRIC_META_KV_CACHE_MISS
.with_label_values(&[&"batch_get"])
.inc_by(missed_keys.len() as u64);

let remote_req = BatchGetRequest { keys: missed_keys };

let ver = self.get_version();
Expand Down

0 comments on commit 1141dbe

Please sign in to comment.