Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add metrics for region server #2552

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/datanode/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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";
fengjiachun marked this conversation as resolved.
Show resolved Hide resolved
/// 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
@@ -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<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()),
17 changes: 17 additions & 0 deletions src/store-api/src/region_request.rs
Original file line number Diff line number Diff line change
@@ -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)>> {