Skip to content

Commit 750bbdb

Browse files
authored
Merge pull request redpanda-data#15966 from travisdowns/td-677-15811-metrics-reduction
Add partition aggregation to some metrics
2 parents 5e38dec + 65c0a89 commit 750bbdb

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

src/v/cluster/partition_probe.cc

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
namespace cluster {
2222

23+
static const ss::sstring cluster_metrics_name
24+
= prometheus_sanitize::metrics_name("cluster:partition");
25+
2326
replicated_partition_probe::replicated_partition_probe(
2427
const partition& p) noexcept
2528
: _partition(p) {
@@ -59,8 +62,31 @@ void replicated_partition_probe::setup_internal_metrics(const model::ntp& ntp) {
5962
partition_label(ntp.tp.partition()),
6063
};
6164

65+
// The following few metrics uses a separate add_group call which doesn't
66+
// aggregate any labels since aggregation does not make sense for "leader
67+
// ID" values.
68+
_metrics.add_group(
69+
cluster_metrics_name,
70+
{sm::make_gauge(
71+
"leader_id",
72+
[this] {
73+
return _partition.raft()->get_leader_id().value_or(
74+
model::node_id(-1));
75+
},
76+
sm::description("Id of current partition leader"),
77+
labels),
78+
sm::make_gauge(
79+
"under_replicated_replicas",
80+
[this] {
81+
return _partition.raft()->get_under_replicated().value_or(0);
82+
},
83+
sm::description("Number of under replicated replicas"),
84+
labels)},
85+
{},
86+
{sm::shard_label});
87+
6288
_metrics.add_group(
63-
prometheus_sanitize::metrics_name("cluster:partition"),
89+
cluster_metrics_name,
6490
{
6591
sm::make_gauge(
6692
"leader",
@@ -96,21 +122,6 @@ void replicated_partition_probe::setup_internal_metrics(const model::ntp& ntp) {
96122
sm::description(
97123
"Partion high watermark i.e. highest consumable offset"),
98124
labels),
99-
sm::make_gauge(
100-
"leader_id",
101-
[this] {
102-
return _partition.raft()->get_leader_id().value_or(
103-
model::node_id(-1));
104-
},
105-
sm::description("Id of current partition leader"),
106-
labels),
107-
sm::make_gauge(
108-
"under_replicated_replicas",
109-
[this] {
110-
return _partition.raft()->get_under_replicated().value_or(0);
111-
},
112-
sm::description("Number of under replicated replicas"),
113-
labels),
114125
sm::make_counter(
115126
"records_produced",
116127
[this] { return _records_produced; },
@@ -153,13 +164,13 @@ void replicated_partition_probe::setup_internal_metrics(const model::ntp& ntp) {
153164
labels),
154165
},
155166
{},
156-
{sm::shard_label});
167+
{sm::shard_label, partition_label});
157168

158169
if (
159170
config::shard_local_cfg().enable_schema_id_validation()
160171
!= pandaproxy::schema_registry::schema_id_validation_mode::none) {
161172
_metrics.add_group(
162-
prometheus_sanitize::metrics_name("cluster:partition"),
173+
cluster_metrics_name,
163174
{
164175
sm::make_counter(
165176
"schema_id_validation_records_failed",
@@ -276,7 +287,7 @@ void replicated_partition_probe::setup_public_metrics(const model::ntp& ntp) {
276287
config::shard_local_cfg().enable_schema_id_validation()
277288
!= pandaproxy::schema_registry::schema_id_validation_mode::none) {
278289
_public_metrics.add_group(
279-
prometheus_sanitize::metrics_name("cluster:partition"),
290+
cluster_metrics_name,
280291
{
281292
sm::make_counter(
282293
"schema_id_validation_records_failed",

src/v/cluster/rm_stm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ void rm_stm::setup_metrics() {
24452445
labels),
24462446
},
24472447
{},
2448-
{sm::shard_label});
2448+
{sm::shard_label, partition_label});
24492449
}
24502450

24512451
ss::future<> rm_stm::maybe_log_tx_stats() {

src/v/raft/consensus.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <seastar/core/fstream.hh>
4545
#include <seastar/core/future.hh>
4646
#include <seastar/core/gate.hh>
47+
#include <seastar/core/metrics.hh>
4748
#include <seastar/core/semaphore.hh>
4849
#include <seastar/util/defer.hh>
4950

@@ -185,7 +186,7 @@ void consensus::setup_metrics() {
185186
labels),
186187
},
187188
{},
188-
{sm::shard_label});
189+
{sm::shard_label, sm::label("partition")});
189190
}
190191

191192
void consensus::setup_public_metrics() {

src/v/storage/probe.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ void probe::setup_metrics(const model::ntp& ntp) {
159159
_metrics.add_group(
160160
group_name,
161161
{
162+
// compaction_ratio cannot easily be aggregated since aggregation always
163+
// sums values and sum is nonsensical for a compaction ratio
162164
sm::make_total_bytes(
163165
"compaction_ratio",
164166
[this] { return _compaction_ratio; },

0 commit comments

Comments
 (0)