chore: add metrics for table route getting (#1636)

chore: add metrics for getting table_route
This commit is contained in:
fys
2023-05-25 10:02:59 +08:00
committed by GitHub
parent 61a32d1b9c
commit 8f9e9686fe
5 changed files with 25 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -5883,6 +5883,7 @@ dependencies = [
"common-error",
"common-meta",
"common-query",
"common-telemetry",
"datafusion",
"datafusion-common",
"datafusion-expr",

View File

@@ -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

View File

@@ -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;

View File

@@ -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";

View File

@@ -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<MetaClient>,
@@ -42,6 +44,8 @@ impl TableRoutes {
}
pub async fn get_route(&self, table_name: &TableName) -> Result<Arc<TableRoute>> {
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<Arc<TableRoute>> {
let _timer = timer!(metrics::METRIC_TABLE_ROUTE_GET_REMOTE);
let mut resp = self
.meta_client
.route(RouteRequest {