From ae95f23e05246cce8fb402cd9cf648e07b85e34a Mon Sep 17 00:00:00 2001 From: JeremyHi Date: Tue, 10 Oct 2023 15:40:16 +0800 Subject: [PATCH] feat: add metrics for region server (#2552) * feat: add metircs for region server * fix: add comment and remove unused code --- src/datanode/src/metrics.rs | 6 ++++-- src/datanode/src/region_server.rs | 8 ++++++-- src/store-api/src/region_request.rs | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/datanode/src/metrics.rs b/src/datanode/src/metrics.rs index 755b84a40d95..858506c89efa 100644 --- a/src/datanode/src/metrics.rs +++ b/src/datanode/src/metrics.rs @@ -14,5 +14,7 @@ //! datanode metrics -pub const HANDLE_SQL_ELAPSED: &str = "datanode.handle_sql_elapsed"; -pub const HANDLE_PROMQL_ELAPSED: &str = "datanode.handle_promql_elapsed"; +/// The elapsed time of handling a request in the region_server. +pub const HANDLE_REGION_REQUEST_ELAPSED: &str = "datanode.handle_region_request_elapsed"; +/// Region request type label. +pub const REGION_REQUEST_TYPE: &str = "datanode.region_request_type"; diff --git a/src/datanode/src/region_server.rs b/src/datanode/src/region_server.rs index ef489499bfac..e073baa87e5e 100644 --- a/src/datanode/src/region_server.rs +++ b/src/datanode/src/region_server.rs @@ -28,7 +28,7 @@ use common_query::physical_plan::DfPhysicalPlanAdapter; use common_query::{DfPhysicalPlan, Output}; use common_recordbatch::SendableRecordBatchStream; use common_runtime::Runtime; -use common_telemetry::{info, warn}; +use common_telemetry::{info, timer, warn}; use dashmap::DashMap; use datafusion::catalog::schema::SchemaProvider; use datafusion::catalog::{CatalogList, CatalogProvider}; @@ -227,7 +227,11 @@ impl RegionServerInner { region_id: RegionId, request: RegionRequest, ) -> Result { - // TODO(ruihang): add some metrics + let request_type = request.request_type(); + let _timer = timer!( + crate::metrics::HANDLE_REGION_REQUEST_ELAPSED, + &[(crate::metrics::REGION_REQUEST_TYPE, request_type),] + ); let region_change = match &request { RegionRequest::Create(create) => RegionChange::Register(create.engine.clone()), diff --git a/src/store-api/src/region_request.rs b/src/store-api/src/region_request.rs index 04251b81aeed..b6f06b790dab 100644 --- a/src/store-api/src/region_request.rs +++ b/src/store-api/src/region_request.rs @@ -43,6 +43,23 @@ pub enum RegionRequest { } impl RegionRequest { + /// Returns the type name of the [RegionRequest]. + #[inline] + pub fn request_type(&self) -> &'static str { + match &self { + RegionRequest::Put(_) => "put", + RegionRequest::Delete(_) => "delete", + RegionRequest::Create(_) => "create", + RegionRequest::Drop(_) => "drop", + RegionRequest::Open(_) => "open", + RegionRequest::Close(_) => "close", + RegionRequest::Alter(_) => "alter", + RegionRequest::Flush(_) => "flush", + RegionRequest::Compact(_) => "compact", + RegionRequest::Truncate(_) => "truncate", + } + } + /// Convert [Body](region_request::Body) to a group of [RegionRequest] with region id. /// Inserts/Deletes request might become multiple requests. Others are one-to-one. pub fn try_from_request_body(body: region_request::Body) -> Result> {