From: Jess Bees Date: Tue, 28 Oct 2025 20:19:04 +0000 (-0400) Subject: Use a variant of string/unordered map as argument X-Git-Tag: rec-5.4.0-alpha1~40^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07b7e47e2c6832cbc78887b767a26af0820bfd48;p=thirdparty%2Fpdns.git Use a variant of string/unordered map as argument Using a Lua table for an argument is more intuitive than having an optional 2nd argument, and now `initMetric`'s signature is actually compatible with `getMetric`'s, rather than just being inspired by it. Signed-off-by: Jess Bees --- diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index b8a030fcad..2c0f801a88 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -430,20 +430,21 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive d_pd.emplace_back("now", &g_now); - d_lw->writeFunction("initMetric", [](const std::string& str, const std::string& maybePrometheusName, const std::string& maybePrometheusTypeName, boost::optional maybeDescr){ - // Shift arguments, because it's actually the second `prometheusName` argument which is optional - // to match the optional `prometheusName` in `getMetric`. + d_lw->writeFunction("initMetric", [](const std::string& str, boost::optional>> opts){ std::string prometheusName; std::string prometheusTypeName; std::string prometheusDescr; - if (maybeDescr) { - prometheusName = maybePrometheusName; - prometheusTypeName = maybePrometheusTypeName; - prometheusDescr = *maybeDescr; - } else { - prometheusDescr = prometheusTypeName; - prometheusTypeName = prometheusName; - prometheusName = ""; + + if (opts) { + auto* optPrometheusName = boost::get(&opts.get()); + if (optPrometheusName != nullptr) { + prometheusName = *optPrometheusName; + } else { + boost::optional> vars = {boost::get>(opts.get())}; + prometheusName = (*vars)["prometheusName"]; + prometheusTypeName = (*vars)["type"]; + prometheusDescr = (*vars)["description"]; + } } return DynMetric{initDynMetric(str, prometheusName, prometheusTypeName, prometheusDescr)};