Skip to content

Commit

Permalink
Merge pull request #10018 from travisdowns/td-9982-avail-memory-in-in…
Browse files Browse the repository at this point in the history
…ternal-metrics

This change adds the available_memory metric, which has been very useful, to the internal metrics endpoint in addition to the public metrics one (where it is today).

Currently, some users are pulling only /metrics or have dashboards or other integrations oriented towards /metrics, and can't use this key memory metric. Furthermore, all of the other memory metrics are in /metrics so it is odd that the most important memory metric is stranded elsewhere.

This change reverses this decision and put available_memory in both places, in line with all other memory metrics and the majority of metrics in general.

See redpanda-data/core-internal#103 for background on this metric.

Fixes #9982.
  • Loading branch information
travisdowns authored Apr 13, 2023
2 parents 6f873c7 + b4feb16 commit 55194d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/v/resource_mgmt/available_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void available_memory::register_metrics() {
}

auto& m = _metrics.emplace();
m.groups.add_group(
m.add_group(
prometheus_sanitize::metrics_name("memory"),
{ss::metrics::make_gauge(
"available_memory",
Expand Down
2 changes: 1 addition & 1 deletion src/v/resource_mgmt/available_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class available_memory final {
_local_instance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

intrusive_list<reporter, &reporter::hook> _reporters;
std::optional<ssx::metrics::public_metrics_group> _metrics;
std::optional<ssx::metrics::all_metrics_groups> _metrics;
size_t _lwm;
};

Expand Down
27 changes: 27 additions & 0 deletions src/v/ssx/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <seastar/core/future.hh>
#include <seastar/core/metrics.hh>
#include <seastar/core/metrics_registration.hh>

namespace ssx::metrics {

Expand Down Expand Up @@ -50,4 +51,30 @@ struct public_metrics_group {
}
};

/**
* @brief A class bundling together public and internal metrics.
*
* Intended to replace an ss::metrics::metric_groups instance when
* you want a metric exposed on both the /metrics (aka "internal")
* and /public_metrics (aka "public") metrics endpoint.
*/
class all_metrics_groups {
ss::metrics::metric_groups _public{public_metrics_handle}, _internal;

public:
/**
* @brief Adds the given metric group to public and internal metrics.
*
* The behavior is same as ss::metrics::metric_groups::add_group but for
* both metric endpoints.
*/
all_metrics_groups& add_group(
const seastar::metrics::group_name_type& name,
const std::initializer_list<seastar::metrics::metric_definition>& l) {
_internal.add_group(name, l);
_public.add_group(name, l);
return *this;
};
};

} // namespace ssx::metrics

0 comments on commit 55194d0

Please sign in to comment.