This is an automated email from the ASF dual-hosted git repository. wangdan pushed a commit to branch migrate-metrics-dev in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
commit 0f8f14c4166fcedba96b85607f06d898e8564745 Author: Dan Wang <[email protected]> AuthorDate: Mon Feb 13 15:45:40 2023 +0800 feat(new_metrics): add replica-level metric entity (#1345) --- src/replica/replica_base.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ src/replica/replica_base.h | 10 +++++---- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/replica/replica_base.cpp b/src/replica/replica_base.cpp new file mode 100644 index 000000000..11e08ae05 --- /dev/null +++ b/src/replica/replica_base.cpp @@ -0,0 +1,52 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#include "replica_base.h" + +#include <fmt/core.h> + +METRIC_DEFINE_entity(replica); + +namespace dsn { +namespace replication { + +namespace { + +metric_entity_ptr instantiate_replica_metric_entity(const gpid &id) +{ + auto entity_id = fmt::format("replica_{}", id); + + // Do NOT add `replica_base._app_name` as the table name to the attributes of entity, since + // it is read-only and will never be updated even if the table is renamed. + return METRIC_ENTITY_replica.instantiate( + entity_id, + {{"table_id", std::to_string(id.get_app_id())}, + {"partition_id", std::to_string(id.get_partition_index())}}); +} + +} // anonymous namespace + +replica_base::replica_base(gpid id, string_view name, string_view app_name) + : _gpid(id), + _name(name), + _app_name(app_name), + _replica_metric_entity(instantiate_replica_metric_entity(id)) +{ +} + +} // namespace replication +} // namespace dsn diff --git a/src/replica/replica_base.h b/src/replica/replica_base.h index 64f294e87..88202d055 100644 --- a/src/replica/replica_base.h +++ b/src/replica/replica_base.h @@ -27,6 +27,7 @@ #pragma once #include "common/gpid.h" +#include "utils/metrics.h" #include "utils/string_view.h" namespace dsn { @@ -35,10 +36,7 @@ namespace replication { /// Base class for types that are one-instance-per-replica. struct replica_base { - replica_base(gpid id, string_view name, string_view app_name) - : _gpid(id), _name(name), _app_name(app_name) - { - } + replica_base(gpid id, string_view name, string_view app_name); explicit replica_base(replica_base *rhs) : replica_base(rhs->get_gpid(), rhs->replica_name(), rhs->_app_name) @@ -53,10 +51,14 @@ struct replica_base const char *log_prefix() const { return _name.c_str(); } + const metric_entity_ptr &replica_metric_entity() const { return _replica_metric_entity; } + private: const gpid _gpid; const std::string _name; + // TODO(wangdan): drop `_app_name` or make it changeable, since a table could be renamed. const std::string _app_name; + const metric_entity_ptr _replica_metric_entity; }; } // namespace replication --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
