Commit aa64eb85 authored by Dominik Charousset's avatar Dominik Charousset

Add sanity checks for user-defined bucket settings

parent f5948795
......@@ -129,6 +129,11 @@ private:
for (const auto& lbl : labels) {
if (auto ptr = get_if<settings>(cfg, lbl.str())) {
if (auto bounds = get_if<std::vector<value_type>>(ptr, "buckets")) {
std::sort(bounds->begin(), bounds->end());
bounds->erase(std::unique(bounds->begin(), bounds->end()),
bounds->end());
if (bounds->empty())
return false;
init_buckets(*bounds);
return true;
}
......
......@@ -18,6 +18,7 @@
#pragma once
#include <algorithm>
#include <initializer_list>
#include <map>
#include <memory>
......@@ -362,11 +363,19 @@ public:
}
const settings* sub_settings = nullptr;
upper_bounds_list upper_bounds;
if (config_ != nullptr)
if (auto grp = get_if<settings>(config_, prefix))
if (sub_settings = get_if<settings>(grp, name); sub_settings != nullptr)
if (auto lst = get_if<upper_bounds_list>(sub_settings, "buckets"))
upper_bounds = std::move(*lst);
if (config_ != nullptr) {
if (auto grp = get_if<settings>(config_, prefix)) {
if (sub_settings = get_if<settings>(grp, name);
sub_settings != nullptr) {
if (auto lst = get_if<upper_bounds_list>(sub_settings, "buckets")) {
std::sort(lst->begin(), lst->end());
lst->erase(std::unique(lst->begin(), lst->end()), lst->end());
if (!lst->empty())
upper_bounds = std::move(*lst);
}
}
}
}
if (upper_bounds.empty())
upper_bounds.assign(default_upper_bounds.begin(),
default_upper_bounds.end());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment