From: Jess Bees Date: Wed, 5 Nov 2025 17:29:35 +0000 (-0500) Subject: Combine getMetric and initMetric X-Git-Tag: rec-5.4.0-alpha1~40^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e99a1cb53a49e368001197017852c7e0862314d;p=thirdparty%2Fpdns.git Combine getMetric and initMetric 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 --- diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index b52c94b46b..dd6b2f9317 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -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>> opts){ + d_lw->writeFunction("getMetric", [](const std::string& str, boost::optional>> 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 prometheusName) { - return DynMetric{getDynMetric(str, prometheusName ? *prometheusName : "")}; + return DynMetric{getDynMetric(str, prometheusName, prometheusTypeName, prometheusDescr)}; }); d_lw->registerFunction("inc", &DynMetric::inc); diff --git a/pdns/recursordist/rec_channel.hh b/pdns/recursordist/rec_channel.hh index 3ca29eb54f..aaa115edec 100644 --- a/pdns/recursordist/rec_channel.hh +++ b/pdns/recursordist/rec_channel.hh @@ -141,8 +141,7 @@ std::vector* pleaseGetBogusRemotes(); std::vector* pleaseGetLargeAnswerRemotes(); std::vector* pleaseGetTimeouts(); DNSName getRegisteredName(const DNSName& dom); -std::atomic* getDynMetric(const std::string& str, const std::string& prometheusName); -std::atomic* initDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr); +std::atomic* getDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr); std::optional getStatByName(const std::string& name); bool isStatDisabled(StatComponent component, const std::string& name); void disableStat(StatComponent component, const string& name); diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 1aa0e1368d..be85498427 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -178,12 +178,7 @@ static std::string getPrometheusName(const std::string& arg) return "pdns_recursor_" + name; } -std::atomic* getDynMetric(const std::string& str, const std::string& prometheusName) -{ - return initDynMetric(str, prometheusName, "", ""); -} - -std::atomic* initDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr) +std::atomic* 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);