From b3b01b08bd3c522655a174327551d044325ea57f Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 2 Feb 2023 10:44:53 +0200 Subject: [PATCH] metrics: Allows filtering by dynamic labels The metrics relabel API allows the creation of new labels during run time. It would be helpful to add those labels to the set of all existing labels so that Prometheus will be able to filter by those labels. This patch adds the labels to the label collection after performing metric relabeling. Signed-off-by: Amnon Heiman --- src/core/metrics.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/metrics.cc b/src/core/metrics.cc index c70c214ed27..fad19cc6749 100644 --- a/src/core/metrics.cc +++ b/src/core/metrics.cc @@ -436,9 +436,6 @@ void impl::add_registration(const metric_id& id, const metric_type& type, metric throw std::runtime_error("registering metrics " + name + " registered with different type."); } metric[rm->info().id.labels()] = rm; - for (auto&& i : rm->info().id.labels()) { - _labels.insert(i.first); - } } else { _value_map[name].info().type = type.base_type; _value_map[name].info().d = d; @@ -447,6 +444,9 @@ void impl::add_registration(const metric_id& id, const metric_type& type, metric _value_map[name].info().aggregate_labels = aggregate_labels; _value_map[name][rm->info().id.labels()] = rm; } + for (auto&& i : rm->info().id.labels()) { + _labels.insert(i.first); + } dirty(); } @@ -488,7 +488,9 @@ future impl::set_relabel_configs(const std::vectorinfo().id.labels()["err"] = id; } - + for (auto&& i : rm->info().id.labels()) { + _labels.insert(i.first); + } family.second[lb] = rm; } }