newThread.detach();
});
- luaCtx.writeFunction("declareMetric", [](const std::string& name, const std::string& type, const std::string& description, boost::optional<boost::variant<std::string, declare_metric_opts_t>> opts) {
+ luaCtx.writeFunction("declareMetric", [](const std::string& name, const std::string& type, const std::string& description, const boost::optional<boost::variant<std::string, declare_metric_opts_t>>& opts) {
bool withLabels = false;
std::optional<std::string> customName = std::nullopt;
if (opts) {
auto* optCustomName = boost::get<std::string>(&opts.get());
- if (optCustomName) {
+ if (optCustomName != nullptr) {
customName = std::optional(*optCustomName);
}
if (!customName) {
}
return true;
});
- luaCtx.writeFunction("incMetric", [](const std::string& name, boost::optional<boost::variant<uint64_t, update_metric_opts_t>> opts) {
+ luaCtx.writeFunction("incMetric", [](const std::string& name, const boost::optional<boost::variant<uint64_t, update_metric_opts_t>>& opts) {
auto incOpts = opts.get_value_or(1);
uint64_t step = 1;
std::unordered_map<std::string, std::string> labels;
}
return std::get<uint64_t>(result);
});
- luaCtx.writeFunction("decMetric", [](const std::string& name, boost::optional<boost::variant<uint64_t, update_metric_opts_t>> opts) {
+ luaCtx.writeFunction("decMetric", [](const std::string& name, const boost::optional<boost::variant<uint64_t, update_metric_opts_t>>& opts) {
auto decOpts = opts.get_value_or(1);
uint64_t step = 1;
std::unordered_map<std::string, std::string> labels;
- if (auto custom_step = boost::get<uint64_t>(&decOpts)) {
+ if (auto* custom_step = boost::get<uint64_t>(&decOpts)) {
step = *custom_step;
}
else {
{
string ret;
- for (char i : value) {
- if (i == '"' || i == '\\') {
+ for (char lblchar : value) {
+ if (lblchar == '"' || lblchar == '\\') {
ret += '\\';
- ret += i;
+ ret += lblchar;
}
- else if (i == '\n') {
+ else if (lblchar == '\n') {
ret += '\\';
ret += 'n';
}
- else
- ret += i;
+ else {
+ ret += lblchar;
+ }
}
return ret;
}
static std::string generateCombinationOfLabels(const std::unordered_map<std::string, std::string>& labels)
{
auto ordered = std::map(labels.begin(), labels.end());
- return std::accumulate(ordered.begin(), ordered.end(), std::string(), [](const std::string& acc, const std::pair<std::string, std::string>& l) {
- return acc + (acc.empty() ? std::string() : ",") + l.first + "=" + "\"" + prometheusLabelValueEscape(l.second) + "\"";
+ return std::accumulate(ordered.begin(), ordered.end(), std::string(), [](const std::string& acc, const std::pair<std::string, std::string>& label) {
+ return acc + (acc.empty() ? std::string() : ",") + label.first + "=" + "\"" + prometheusLabelValueEscape(label.second) + "\"";
});
}