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: Allows filtering by dynamic labels #1461

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions src/core/metrics.cc
Original file line number Diff line number Diff line change
@@ -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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yikes. I don't follow this change and to be honest -- I don't even follow the code before this change :(

When registering new metrics, the if (_value_map.find(name) != _value_map.end()) { from above would evaluate to false so we get into the else branch and skip the _labels.insert() before the patch, but make insertions after it. What's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xemul Let me try to explain, the metrics layer holds a set of all available labels.
This way, if some queries for a specific label value (i.e. Prometheus API), it can check if this label exists.
Recently, a new API was added to the metrics layer that would allow dynamically add or change label values.

Following that change it's possible that someone register a metrics with specific labels, but because of relabel_config more labels were added.
The series address this situations, it always tries to update the set of labels.

Overall there's little impact on performance, metrics are registered once, and most of them during startup.

Copy link
Contributor

Choose a reason for hiding this comment

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

The series address this situations, it always tries to update the set of labels.

That's clear, thanks. However, I still don't get why the

    for (auto&& i : rm->info().id.labels()) {
        _labels.insert(i.first);
    }

appeared in the impl::add_registration's "else" branch only now. Before this change, if a new metrics is added, its labels were not added to the _labels set?

Overall there's little impact on performance, metrics are registered once, and most of them during startup.

Yes, of course. Performance is not of interest here.

Copy link
Contributor Author

@amnonh amnonh Feb 16, 2023

Choose a reason for hiding this comment

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

Up until now, metrics were static, so it was enough to look for labels the first time a metric was added. However, maybe this assumption is wrong to begin with, and this is a bug (i.e., it shouldn't have been conditional in the first place).

I hit that limitation when I tested adding labels dynamically and managed to get to a situation where I could add a label, but I couldn't filter by it.

dirty();
}

@@ -488,7 +488,9 @@ future<metric_relabeling_result> impl::set_relabel_configs(const std::vector<rel
conflicts.metrics_relabeled_due_to_collision++;
rm->info().id.labels()["err"] = id;
}

for (auto&& i : rm->info().id.labels()) {
_labels.insert(i.first);
}
family.second[lb] = rm;
}
}