]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Combine getMetric and initMetric
authorJess Bees <jesse@toomanybees.com>
Wed, 5 Nov 2025 17:29:35 +0000 (12:29 -0500)
committerJess Bees <jesse@toomanybees.com>
Mon, 17 Nov 2025 19:35:55 +0000 (14:35 -0500)
initMetric's signature is intentionally backwards compatible with getMetric,
so if there's no performance impact we can transparently combine their
functionality without breaking changes.

Signed-off-by: Jess Bees <jesse@toomanybees.com>
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/rec_channel.hh
pdns/recursordist/rec_channel_rec.cc

index b52c94b46bd8347b4a4c978c38edd14e49bb7bb1..dd6b2f9317346f609cef08f2964410a8a7851c0a 100644 (file)
@@ -430,7 +430,7 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive
 
   d_pd.emplace_back("now", &g_now);
 
-  d_lw->writeFunction("initMetric", [](const std::string& str, boost::optional<boost::variant<std::string, std::unordered_map<std::string, std::string>>> opts){
+  d_lw->writeFunction("getMetric", [](const std::string& str, boost::optional<boost::variant<std::string, std::unordered_map<std::string, std::string>>> opts){
     std::string prometheusName;
     std::string prometheusTypeName;
     std::string prometheusDescr;
@@ -445,11 +445,7 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive
       }
     }
 
-    return DynMetric{initDynMetric(str, prometheusName, prometheusTypeName, prometheusDescr)};
-  });
-
-  d_lw->writeFunction("getMetric", [](const std::string& str, boost::optional<std::string> prometheusName) {
-    return DynMetric{getDynMetric(str, prometheusName ? *prometheusName : "")};
+    return DynMetric{getDynMetric(str, prometheusName, prometheusTypeName, prometheusDescr)};
     });
 
   d_lw->registerFunction("inc", &DynMetric::inc);
index 3ca29eb54f8143e498669a606d4167f182f90a95..aaa115edec5380cb1f3d76becd2de9e921aa30f7 100644 (file)
@@ -141,8 +141,7 @@ std::vector<ComboAddress>* pleaseGetBogusRemotes();
 std::vector<ComboAddress>* pleaseGetLargeAnswerRemotes();
 std::vector<ComboAddress>* pleaseGetTimeouts();
 DNSName getRegisteredName(const DNSName& dom);
-std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName);
-std::atomic<unsigned long>* initDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr);
+std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr);
 std::optional<uint64_t> getStatByName(const std::string& name);
 bool isStatDisabled(StatComponent component, const std::string& name);
 void disableStat(StatComponent component, const string& name);
index 1aa0e1368de114e17b8dc99144249b168d96fa05..be85498427aed930fbb7c9d513c8897dc23a2252 100644 (file)
@@ -178,12 +178,7 @@ static std::string getPrometheusName(const std::string& arg)
   return "pdns_recursor_" + name;
 }
 
-std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName)
-{
-  return initDynMetric(str, prometheusName, "", "");
-}
-
-std::atomic<unsigned long>* initDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr)
+std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr)
 {
   auto locked = d_dynmetrics.lock();
   auto iter = locked->find(str);