Skip to content

Commit

Permalink
feat: add metrics for region server (#2552)
Browse files Browse the repository at this point in the history
* feat: add metircs for region server

* fix: add comment and remove unused code
  • Loading branch information
fengjiachun authored Oct 10, 2023
1 parent 6b39f59 commit ae95f23
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/datanode/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 6 additions & 2 deletions src/datanode/src/region_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -227,7 +227,11 @@ impl RegionServerInner {
region_id: RegionId,
request: RegionRequest,
) -> Result<Output> {
// 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()),
Expand Down
17 changes: 17 additions & 0 deletions src/store-api/src/region_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<(RegionId, Self)>> {
Expand Down

0 comments on commit ae95f23

Please sign in to comment.