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 some metrics #1384

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/datanode/src/instance/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Instance {
promql: &PromQuery,
query_ctx: QueryContextRef,
) -> Result<Output> {
let _timer = timer!(metrics::METRIC_HANDLE_PROMQL_ELAPSED);
let _timer = timer!(metrics::HANDLE_PROMQL_ELAPSED);

let stmt = QueryLanguageParser::parse_promql(promql).context(ExecuteSqlSnafu)?;

Expand Down
4 changes: 2 additions & 2 deletions src/datanode/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

//! datanode metrics

pub const METRIC_HANDLE_SQL_ELAPSED: &str = "datanode.handle_sql_elapsed";
pub const METRIC_HANDLE_PROMQL_ELAPSED: &str = "datanode.handle_promql_elapsed";
pub const HANDLE_SQL_ELAPSED: &str = "datanode.handle_sql_elapsed";
pub const HANDLE_PROMQL_ELAPSED: &str = "datanode.handle_promql_elapsed";
3 changes: 3 additions & 0 deletions src/frontend/src/instance/distributed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl DistInstance {
create_table: &mut CreateTableExpr,
partitions: Option<Partitions>,
) -> Result<TableRef> {
let _timer = common_telemetry::timer!(crate::metrics::DIST_CREATE_TABLE);
let table_name = TableName::new(
&create_table.catalog_name,
&create_table.schema_name,
Expand Down Expand Up @@ -189,6 +190,7 @@ impl DistInstance {
create_table, datanode, create_expr_for_region.region_ids,
);

let _timer = common_telemetry::timer!(crate::metrics::DIST_CREATE_TABLE_IN_DATANODE);
client
.create(create_expr_for_region)
.await
Expand Down Expand Up @@ -460,6 +462,7 @@ impl DistInstance {
partitions: Option<Partitions>,
table_info: &RawTableInfo,
) -> Result<RouteResponse> {
let _timer = common_telemetry::timer!(crate::metrics::DIST_CREATE_TABLE_IN_META);
let mut catalog_name = create_table.catalog_name.clone();
if catalog_name.is_empty() {
catalog_name = DEFAULT_CATALOG_NAME.to_string();
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod grpc;
pub mod influxdb;
pub mod instance;
pub(crate) mod metric;
mod metrics;
pub mod mysql;
pub mod opentsdb;
pub mod postgres;
Expand Down
22 changes: 22 additions & 0 deletions src/frontend/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

//! frontend metrics

/// Metrics for creating table in dist mode.
pub const DIST_CREATE_TABLE: &str = "frontend.dist.create_table";

pub const DIST_CREATE_TABLE_IN_META: &str = "frontend.dist.create_table.update_meta";

pub const DIST_CREATE_TABLE_IN_DATANODE: &str = "frontend.dist.create_table.invoke_datanode";
18 changes: 12 additions & 6 deletions src/mito/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use crate::error::{
MissingTimestampIndexSnafu, RegionNotFoundSnafu, Result, TableExistsSnafu,
};
use crate::manifest::TableManifest;
use crate::metrics;
use crate::table::MitoTable;
pub const INIT_COLUMN_ID: ColumnId = 0;
const INIT_TABLE_VERSION: TableVersion = 0;
Expand Down Expand Up @@ -95,6 +96,7 @@ impl<S: StorageEngine> TableEngine for MitoEngine<S> {
ctx: &EngineContext,
request: CreateTableRequest,
) -> TableResult<TableRef> {
let _timer = common_telemetry::timer!(metrics::MITO_CREATE_TABLE_ELAPSED);
self.inner
.create_table(ctx, request)
.await
Expand All @@ -107,6 +109,7 @@ impl<S: StorageEngine> TableEngine for MitoEngine<S> {
ctx: &EngineContext,
request: OpenTableRequest,
) -> TableResult<Option<TableRef>> {
let _timer = common_telemetry::timer!(metrics::MITO_OPEN_TABLE_ELAPSED);
self.inner
.open_table(ctx, request)
.await
Expand All @@ -119,6 +122,7 @@ impl<S: StorageEngine> TableEngine for MitoEngine<S> {
ctx: &EngineContext,
req: AlterTableRequest,
) -> TableResult<TableRef> {
let _timer = common_telemetry::timer!(metrics::MITO_ALTER_TABLE_ELAPSED);
self.inner
.alter_table(ctx, req)
.await
Expand Down Expand Up @@ -423,12 +427,14 @@ impl<S: StorageEngine> MitoEngineInner<S> {
compaction_time_window: request.table_options.compaction_time_window,
};

let region = self
.storage_engine
.create_region(&StorageEngineContext::default(), region_descriptor, &opts)
.await
.map_err(BoxedError::new)
.context(error::CreateRegionSnafu)?;
let region = {
let _timer = common_telemetry::timer!(crate::metrics::MITO_CREATE_REGION_ELAPSED);
self.storage_engine
.create_region(&StorageEngineContext::default(), region_descriptor, &opts)
.await
.map_err(BoxedError::new)
.context(error::CreateRegionSnafu)?
};
info!(
"Mito engine created region: {}, id: {}",
region.name(),
Expand Down
1 change: 1 addition & 0 deletions src/mito/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pub mod config;
pub mod engine;
pub mod error;
mod manifest;
mod metrics;
pub mod table;
27 changes: 27 additions & 0 deletions src/mito/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

// ! mito table engine metrics

/// Elapsed time of creating tables
pub const MITO_CREATE_TABLE_ELAPSED: &str = "datanode.mito.create_table";
/// Elapsed time of creating single region when creating tables.
pub const MITO_CREATE_REGION_ELAPSED: &str = "datanode.mito.create_table.create_region";
/// Elapsed time of updating table manifest when creating tables.
pub const MITO_CREATE_TABLE_UPDATE_MANIFEST_ELAPSED: &str =
"datanode.mito.create_table.update_manifest";
/// Elapsed time of opening tables
pub const MITO_OPEN_TABLE_ELAPSED: &str = "datanode.mito.open_table";
/// Elapsed time of altering tables
pub const MITO_ALTER_TABLE_ELAPSED: &str = "datanode.mito.alter_table";
2 changes: 2 additions & 0 deletions src/mito/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ impl<R: Region> MitoTable<R> {
) -> Result<MitoTable<R>> {
let manifest = TableManifest::create(&table_manifest_dir(table_dir), object_store);

let _timer =
common_telemetry::timer!(crate::metrics::MITO_CREATE_TABLE_UPDATE_MANIFEST_ELAPSED);
// TODO(dennis): save manifest version into catalog?
let _manifest_version = manifest
.update(TableMetaActionList::with_action(TableMetaAction::Change(
Expand Down
1 change: 1 addition & 0 deletions src/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod write_batch;

pub use engine::EngineImpl;
mod file_purger;
mod metrics;

pub use sst::parquet::ParquetWriter;
pub use sst::Source;
18 changes: 18 additions & 0 deletions src/storage/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

//! storage metrics

/// Elapsed time of updating manifest when creating regions.
pub const CREATE_REGION_UPDATE_MANIFEST: &str = "storage.create_region.update_manifest";
22 changes: 13 additions & 9 deletions src/storage/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,21 @@ impl<S: LogStore> RegionImpl<S> {
store_config: StoreConfig<S>,
) -> Result<RegionImpl<S>> {
let metadata = Arc::new(metadata);

// Try to persist region data to manifest, ensure the new region could be recovered from
// the manifest.
let manifest_version = store_config
.manifest
.update(RegionMetaActionList::with_action(RegionMetaAction::Change(
RegionChange {
metadata: metadata.as_ref().into(),
committed_sequence: INIT_COMMITTED_SEQUENCE,
},
)))
.await?;
let manifest_version = {
let _timer = common_telemetry::timer!(crate::metrics::CREATE_REGION_UPDATE_MANIFEST);
store_config
.manifest
.update(RegionMetaActionList::with_action(RegionMetaAction::Change(
RegionChange {
metadata: metadata.as_ref().into(),
committed_sequence: INIT_COMMITTED_SEQUENCE,
},
)))
.await?
};

let mutable_memtable = store_config
.memtable_builder
Expand Down