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

metrics: support relabel aggregate #2130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion include/seastar/core/metrics_api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct metric_info {
labels_type original_labels;
bool enabled;
skip_when_empty should_skip_when_empty;
std::vector<std::string> aggregate_labels;
};


Expand All @@ -216,7 +217,7 @@ class registered_metric final {
metric_function _f;
shared_ptr<impl> _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<std::string> aggregate_labels = {});
metric_value operator()() const {
return _f();
}
Expand Down
2 changes: 1 addition & 1 deletion include/seastar/core/relabel_config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> source_labels;
std::string target_label;
std::string replacement = "${1}";
Expand Down
18 changes: 15 additions & 3 deletions src/core/metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<std::string> 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) {
Expand Down Expand Up @@ -430,7 +435,7 @@ std::vector<std::deque<metric_function>>& 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<std::string>& aggregate_labels) {
auto rm = ::seastar::make_shared<registered_metric>(id, f, enabled, skip);
auto rm = ::seastar::make_shared<registered_metric>(id, f, enabled, skip, aggregate_labels);
for (auto&& rl : _relabel_configs) {
apply_relabeling(rl, rm->info());
}
Expand Down Expand Up @@ -469,6 +474,9 @@ future<metric_relabeling_result> impl::set_relabel_configs(const std::vector<rel
metric->second->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();
}
}
Expand Down Expand Up @@ -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;
}

Expand Down