]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: clean up clang-tidy warnings in lua and metrics
authorEnsar Sarajčić <dev@ensarsarajcic.com>
Thu, 12 Dec 2024 16:38:43 +0000 (17:38 +0100)
committerEnsar Sarajčić <dev@ensarsarajcic.com>
Thu, 12 Dec 2024 16:38:43 +0000 (17:38 +0100)
pdns/dnsdistdist/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-metrics.cc

index bf7e179ed0b374c0813870ff21754f7cf700f7d9..ff4e05587e5c1f8bf75e93efe08dd0e1d14426de 100644 (file)
@@ -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<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) {
@@ -3436,7 +3436,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     }
     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;
@@ -3457,11 +3457,11 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     }
     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 {
index 10d18dc2923acc4c26a138662937b896906e26e2..293be6d95c4d5b8b94117248a59f86d99837115f 100644 (file)
@@ -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<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) + "\"";
   });
 }