Skip to content

Commit

Permalink
Merge pull request redpanda-data#15966 from travisdowns/td-677-15811-…
Browse files Browse the repository at this point in the history
…metrics-reduction

Add partition aggregation to some metrics
  • Loading branch information
travisdowns authored Jan 12, 2024
2 parents 5e38dec + 65c0a89 commit 750bbdb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
49 changes: 30 additions & 19 deletions src/v/cluster/partition_probe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

namespace cluster {

static const ss::sstring cluster_metrics_name
= prometheus_sanitize::metrics_name("cluster:partition");

replicated_partition_probe::replicated_partition_probe(
const partition& p) noexcept
: _partition(p) {
Expand Down Expand Up @@ -59,8 +62,31 @@ void replicated_partition_probe::setup_internal_metrics(const model::ntp& ntp) {
partition_label(ntp.tp.partition()),
};

// The following few metrics uses a separate add_group call which doesn't
// aggregate any labels since aggregation does not make sense for "leader
// ID" values.
_metrics.add_group(
cluster_metrics_name,
{sm::make_gauge(
"leader_id",
[this] {
return _partition.raft()->get_leader_id().value_or(
model::node_id(-1));
},
sm::description("Id of current partition leader"),
labels),
sm::make_gauge(
"under_replicated_replicas",
[this] {
return _partition.raft()->get_under_replicated().value_or(0);
},
sm::description("Number of under replicated replicas"),
labels)},
{},
{sm::shard_label});

_metrics.add_group(
prometheus_sanitize::metrics_name("cluster:partition"),
cluster_metrics_name,
{
sm::make_gauge(
"leader",
Expand Down Expand Up @@ -96,21 +122,6 @@ void replicated_partition_probe::setup_internal_metrics(const model::ntp& ntp) {
sm::description(
"Partion high watermark i.e. highest consumable offset"),
labels),
sm::make_gauge(
"leader_id",
[this] {
return _partition.raft()->get_leader_id().value_or(
model::node_id(-1));
},
sm::description("Id of current partition leader"),
labels),
sm::make_gauge(
"under_replicated_replicas",
[this] {
return _partition.raft()->get_under_replicated().value_or(0);
},
sm::description("Number of under replicated replicas"),
labels),
sm::make_counter(
"records_produced",
[this] { return _records_produced; },
Expand Down Expand Up @@ -153,13 +164,13 @@ void replicated_partition_probe::setup_internal_metrics(const model::ntp& ntp) {
labels),
},
{},
{sm::shard_label});
{sm::shard_label, partition_label});

if (
config::shard_local_cfg().enable_schema_id_validation()
!= pandaproxy::schema_registry::schema_id_validation_mode::none) {
_metrics.add_group(
prometheus_sanitize::metrics_name("cluster:partition"),
cluster_metrics_name,
{
sm::make_counter(
"schema_id_validation_records_failed",
Expand Down Expand Up @@ -276,7 +287,7 @@ void replicated_partition_probe::setup_public_metrics(const model::ntp& ntp) {
config::shard_local_cfg().enable_schema_id_validation()
!= pandaproxy::schema_registry::schema_id_validation_mode::none) {
_public_metrics.add_group(
prometheus_sanitize::metrics_name("cluster:partition"),
cluster_metrics_name,
{
sm::make_counter(
"schema_id_validation_records_failed",
Expand Down
2 changes: 1 addition & 1 deletion src/v/cluster/rm_stm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ void rm_stm::setup_metrics() {
labels),
},
{},
{sm::shard_label});
{sm::shard_label, partition_label});
}

ss::future<> rm_stm::maybe_log_tx_stats() {
Expand Down
3 changes: 2 additions & 1 deletion src/v/raft/consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <seastar/core/fstream.hh>
#include <seastar/core/future.hh>
#include <seastar/core/gate.hh>
#include <seastar/core/metrics.hh>
#include <seastar/core/semaphore.hh>
#include <seastar/util/defer.hh>

Expand Down Expand Up @@ -185,7 +186,7 @@ void consensus::setup_metrics() {
labels),
},
{},
{sm::shard_label});
{sm::shard_label, sm::label("partition")});
}

void consensus::setup_public_metrics() {
Expand Down
2 changes: 2 additions & 0 deletions src/v/storage/probe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void probe::setup_metrics(const model::ntp& ntp) {
_metrics.add_group(
group_name,
{
// compaction_ratio cannot easily be aggregated since aggregation always
// sums values and sum is nonsensical for a compaction ratio
sm::make_total_bytes(
"compaction_ratio",
[this] { return _compaction_ratio; },
Expand Down

0 comments on commit 750bbdb

Please sign in to comment.