diff --git a/include/seastar/core/metrics_api.hh b/include/seastar/core/metrics_api.hh index d84870b6f5b..a32b197d8db 100644 --- a/include/seastar/core/metrics_api.hh +++ b/include/seastar/core/metrics_api.hh @@ -192,6 +192,7 @@ struct metric_info { labels_type original_labels; bool enabled; skip_when_empty should_skip_when_empty; + std::vector aggregate_labels; }; @@ -216,7 +217,7 @@ class registered_metric final { metric_function _f; shared_ptr _impl; public: - registered_metric(metric_id id, metric_function f, bool enabled=true, skip_when_empty skip=skip_when_empty::no); + registered_metric(metric_id id, metric_function f, bool enabled=true, skip_when_empty skip=skip_when_empty::no, std::vector aggregate_labels = {}); metric_value operator()() const { return _f(); } diff --git a/include/seastar/core/relabel_config.hh b/include/seastar/core/relabel_config.hh index 1e0e17ee659..7d424c2aa65 100644 --- a/include/seastar/core/relabel_config.hh +++ b/include/seastar/core/relabel_config.hh @@ -89,7 +89,7 @@ public: * */ struct relabel_config { - enum class relabel_action {skip_when_empty, report_when_empty, replace, keep, drop, drop_label}; + enum class relabel_action {skip_when_empty, report_when_empty, replace, keep, drop, drop_label, aggregate_label}; std::vector source_labels; std::string target_label; std::string replacement = "${1}"; diff --git a/src/core/metrics.cc b/src/core/metrics.cc index af2e8937e0f..570ebfedc40 100644 --- a/src/core/metrics.cc +++ b/src/core/metrics.cc @@ -179,6 +179,10 @@ static bool apply_relabeling(const relabel_config& rc, impl::metric_info& info) } return true; } + case relabel_config::relabel_action::aggregate_label: { + info.aggregate_labels.push_back(rc.target_label); + return true; + } default: break; } @@ -201,12 +205,13 @@ static std::string get_unique_id() { label shard_label("shard"); namespace impl { -registered_metric::registered_metric(metric_id id, metric_function f, bool enabled, skip_when_empty skip) : +registered_metric::registered_metric(metric_id id, metric_function f, bool enabled, skip_when_empty skip, std::vector aggregate_labels) : _f(f), _impl(get_local_impl()) { _info.enabled = enabled; _info.should_skip_when_empty = skip; _info.id = id; _info.original_labels = id.labels(); + _info.aggregate_labels = aggregate_labels; } metric_value metric_value::operator+(const metric_value& c) { @@ -430,7 +435,7 @@ std::vector>& impl::functions() { } void impl::add_registration(const metric_id& id, const metric_type& type, metric_function f, const description& d, bool enabled, skip_when_empty skip, const std::vector& aggregate_labels) { - auto rm = ::seastar::make_shared(id, f, enabled, skip); + auto rm = ::seastar::make_shared(id, f, enabled, skip, aggregate_labels); for (auto&& rl : _relabel_configs) { apply_relabeling(rl, rm->info()); } @@ -469,6 +474,9 @@ future impl::set_relabel_configs(const std::vectorsecond->info().id.labels() = metric->second->info().original_labels; for (auto rl : _relabel_configs) { if (apply_relabeling(rl, metric->second->info())) { + if(!metric->second->info().aggregate_labels.empty()){ + _value_map[metric->second->info().id.full_name()].info().aggregate_labels = metric->second->info().aggregate_labels; + } dirty(); } } @@ -519,9 +527,13 @@ relabel_config::relabel_action relabel_config_action(const std::string& action) } if (action == "drop") { return relabel_config::relabel_action::drop; - } if (action == "drop_label") { + } + if (action == "drop_label") { return relabel_config::relabel_action::drop_label; } + if (action == "aggregate_label") { + return relabel_config::relabel_action::aggregate_label; + } return relabel_config::relabel_action::replace; }