From 8f9e9686fee0914c96b97ba39bdba682a82303fe Mon Sep 17 00:00:00 2001 From: fys <40801205+Fengys123@users.noreply.github.com> Date: Thu, 25 May 2023 10:02:59 +0800 Subject: [PATCH] chore: add metrics for table route getting (#1636) chore: add metrics for getting table_route --- Cargo.lock | 1 + src/partition/Cargo.toml | 1 + src/partition/src/lib.rs | 1 + src/partition/src/metrics.rs | 16 ++++++++++++++++ src/partition/src/route.rs | 6 ++++++ 5 files changed, 25 insertions(+) create mode 100644 src/partition/src/metrics.rs diff --git a/Cargo.lock b/Cargo.lock index 1fcf4d763e..cd315d7998 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5883,6 +5883,7 @@ dependencies = [ "common-error", "common-meta", "common-query", + "common-telemetry", "datafusion", "datafusion-common", "datafusion-expr", diff --git a/src/partition/Cargo.toml b/src/partition/Cargo.toml index fc8839e45f..c7ee679c99 100644 --- a/src/partition/Cargo.toml +++ b/src/partition/Cargo.toml @@ -11,6 +11,7 @@ common-catalog = { path = "../common/catalog" } common-error = { path = "../common/error" } common-query = { path = "../common/query" } common-meta = { path = "../common/meta" } +common-telemetry = { path = "../common/telemetry" } datafusion-common.workspace = true datafusion-expr.workspace = true datafusion.workspace = true diff --git a/src/partition/src/lib.rs b/src/partition/src/lib.rs index 731abbd45e..9dba350441 100644 --- a/src/partition/src/lib.rs +++ b/src/partition/src/lib.rs @@ -17,6 +17,7 @@ pub mod columns; pub mod error; pub mod manager; +pub mod metrics; pub mod partition; pub mod range; pub mod route; diff --git a/src/partition/src/metrics.rs b/src/partition/src/metrics.rs new file mode 100644 index 0000000000..54785dd01f --- /dev/null +++ b/src/partition/src/metrics.rs @@ -0,0 +1,16 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub(crate) const METRIC_TABLE_ROUTE_GET_REMOTE: &str = "frontend.table_route.get.remote"; +pub(crate) const METRIC_TABLE_ROUTE_GET: &str = "frontend.table_route.get"; diff --git a/src/partition/src/route.rs b/src/partition/src/route.rs index 851761abd1..91ea996edc 100644 --- a/src/partition/src/route.rs +++ b/src/partition/src/route.rs @@ -17,11 +17,13 @@ use std::time::Duration; use common_meta::rpc::router::{RouteRequest, TableRoute}; use common_meta::table_name::TableName; +use common_telemetry::timer; use meta_client::client::MetaClient; use moka::future::{Cache, CacheBuilder}; use snafu::{ensure, ResultExt}; use crate::error::{self, Result}; +use crate::metrics; pub struct TableRoutes { meta_client: Arc, @@ -42,6 +44,8 @@ impl TableRoutes { } pub async fn get_route(&self, table_name: &TableName) -> Result> { + let _timer = timer!(metrics::METRIC_TABLE_ROUTE_GET); + self.cache .try_get_with_by_ref(table_name, self.get_from_meta(table_name)) .await @@ -54,6 +58,8 @@ impl TableRoutes { } async fn get_from_meta(&self, table_name: &TableName) -> Result> { + let _timer = timer!(metrics::METRIC_TABLE_ROUTE_GET_REMOTE); + let mut resp = self .meta_client .route(RouteRequest {