From: Ensar Sarajčić Date: Thu, 12 Dec 2024 16:38:43 +0000 (+0100) Subject: dnsdist: clean up clang-tidy warnings in lua and metrics X-Git-Tag: dnsdist-2.0.0-alpha0^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec216cdb5f74e3947ebefeb1effb3de767c63d96;p=thirdparty%2Fpdns.git dnsdist: clean up clang-tidy warnings in lua and metrics --- diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index bf7e179ed0..ff4e05587e 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -3413,12 +3413,12 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) newThread.detach(); }); - luaCtx.writeFunction("declareMetric", [](const std::string& name, const std::string& type, const std::string& description, boost::optional> opts) { + luaCtx.writeFunction("declareMetric", [](const std::string& name, const std::string& type, const std::string& description, const boost::optional>& opts) { bool withLabels = false; std::optional customName = std::nullopt; if (opts) { auto* optCustomName = boost::get(&opts.get()); - if (optCustomName) { + if (optCustomName != nullptr) { customName = std::optional(*optCustomName); } if (!customName) { @@ -3436,7 +3436,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } return true; }); - luaCtx.writeFunction("incMetric", [](const std::string& name, boost::optional> opts) { + luaCtx.writeFunction("incMetric", [](const std::string& name, const boost::optional>& opts) { auto incOpts = opts.get_value_or(1); uint64_t step = 1; std::unordered_map labels; @@ -3457,11 +3457,11 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } return std::get(result); }); - luaCtx.writeFunction("decMetric", [](const std::string& name, boost::optional> opts) { + luaCtx.writeFunction("decMetric", [](const std::string& name, const boost::optional>& opts) { auto decOpts = opts.get_value_or(1); uint64_t step = 1; std::unordered_map labels; - if (auto custom_step = boost::get(&decOpts)) { + if (auto* custom_step = boost::get(&decOpts)) { step = *custom_step; } else { diff --git a/pdns/dnsdistdist/dnsdist-metrics.cc b/pdns/dnsdistdist/dnsdist-metrics.cc index 10d18dc292..293be6d95c 100644 --- a/pdns/dnsdistdist/dnsdist-metrics.cc +++ b/pdns/dnsdistdist/dnsdist-metrics.cc @@ -211,17 +211,18 @@ static string prometheusLabelValueEscape(const string& value) { 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; } @@ -229,8 +230,8 @@ static string prometheusLabelValueEscape(const string& value) static std::string generateCombinationOfLabels(const std::unordered_map& 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& 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& label) { + return acc + (acc.empty() ? std::string() : ",") + label.first + "=" + "\"" + prometheusLabelValueEscape(label.second) + "\""; }); }