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

Raft: recovery throttle available units metric #6110

Merged
merged 1 commit into from
Aug 19, 2022
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
43 changes: 43 additions & 0 deletions src/v/raft/recovery_throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
* by the Apache License, Version 2.0
*/
#pragma once
#include "config/configuration.h"
#include "config/property.h"
#include "raft/logger.h"
#include "seastarx.h"
#include "ssx/metrics.h"
#include "ssx/semaphore.h"

#include <seastar/core/smp.hh>
Expand Down Expand Up @@ -44,6 +46,7 @@ class recovery_throttle {
, _last_refresh(clock_type::now())
, _refresh_timer([this] { handle_refresh(); }) {
_rate_binding.watch([this]() { update_rate(); });
setup_metrics();
}

ss::future<> throttle(size_t size, ss::abort_source& as) {
Expand Down Expand Up @@ -135,11 +138,51 @@ class recovery_throttle {
_rate = per_core_rate;
}

void setup_metrics() {
setup_internal_metrics();
setup_public_metrics();
}

void setup_internal_metrics() {
if (config::shard_local_cfg().disable_metrics()) {
return;
}

// TODO: Delete this metric after public is supported in scraping
// configurations
namespace sm = ss::metrics;
_internal_metrics.add_group(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we can have just a single function that takes a metrics endpoint as a parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think about it
But I think that now it is easier to just delete this function without refactoring code later.

"raft:recovery",
{sm::make_gauge(
"partition_movement_available_bandwidth",
[this] { return _sem.current(); },
sm::description(
"Bandwidth available for partition movement. bytes/sec"))});
}

void setup_public_metrics() {
if (config::shard_local_cfg().disable_public_metrics()) {
return;
}

namespace sm = ss::metrics;
_public_metrics.add_group(
"raft:recovery",
{sm::make_gauge(
"partition_movement_available_bandwidth",
[this] { return _sem.current(); },
sm::description(
"Bandwidth available for partition movement. bytes/sec"))});
}

config::binding<size_t> _rate_binding;
size_t _rate;
ssx::semaphore _sem;
clock_type::time_point _last_refresh;
ss::timer<> _refresh_timer;
ss::metrics::metric_groups _internal_metrics;
ss::metrics::metric_groups _public_metrics{
ssx::metrics::public_metrics_handle};
};

} // namespace raft
3 changes: 3 additions & 0 deletions src/v/raft/tests/raft_group_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,9 @@ struct raft_test_fixture {
raft_test_fixture() {
ss::smp::invoke_on_all([] {
config::shard_local_cfg().get("disable_metrics").set_value(true);
config::shard_local_cfg()
.get("disable_public_metrics")
.set_value(true);
config::shard_local_cfg()
.get("raft_heartbeat_disconnect_failures")
.set_value((size_t)0);
Expand Down