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: ...@@ -129,6 +129,11 @@ private:
for (const auto& lbl : labels) { for (const auto& lbl : labels) {
if (auto ptr = get_if<settings>(cfg, lbl.str())) { if (auto ptr = get_if<settings>(cfg, lbl.str())) {
if (auto bounds = get_if<std::vector<value_type>>(ptr, "buckets")) { 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); init_buckets(*bounds);
return true; return true;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#pragma once #pragma once
#include <algorithm>
#include <initializer_list> #include <initializer_list>
#include <map> #include <map>
#include <memory> #include <memory>
...@@ -362,11 +363,19 @@ public: ...@@ -362,11 +363,19 @@ public:
} }
const settings* sub_settings = nullptr; const settings* sub_settings = nullptr;
upper_bounds_list upper_bounds; upper_bounds_list upper_bounds;
if (config_ != nullptr) if (config_ != nullptr) {
if (auto grp = get_if<settings>(config_, prefix)) if (auto grp = get_if<settings>(config_, prefix)) {
if (sub_settings = get_if<settings>(grp, name); sub_settings != nullptr) if (sub_settings = get_if<settings>(grp, name);
if (auto lst = get_if<upper_bounds_list>(sub_settings, "buckets")) 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); upper_bounds = std::move(*lst);
}
}
}
}
if (upper_bounds.empty()) if (upper_bounds.empty())
upper_bounds.assign(default_upper_bounds.begin(), upper_bounds.assign(default_upper_bounds.begin(),
default_upper_bounds.end()); 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