From: Otto Moerbeek Date: Wed, 5 Nov 2025 13:40:06 +0000 (+0100) Subject: Nits X-Git-Tag: rec-5.4.0-alpha1~40^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=717d186587a9c53ef4f77771ffc26c4bc2ba165a;p=thirdparty%2Fpdns.git Nits Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/docs/lua-scripting/statistics.rst b/pdns/recursordist/docs/lua-scripting/statistics.rst index 1362e312f9..dd16878b51 100644 --- a/pdns/recursordist/docs/lua-scripting/statistics.rst +++ b/pdns/recursordist/docs/lua-scripting/statistics.rst @@ -12,7 +12,7 @@ Create a custom metric with: .. code-block:: lua - myMetric=getMetric("myspecialmetric") + myMetric = getMetric("myspecialmetric") .. function:: getMetric(name [, prometheusName]) -> Metric @@ -24,6 +24,8 @@ Create a custom metric with: :param string prometheusName: The optional Prometheus specific name. +.. versionadded:: 5.4.0 + .. function:: initMetric(name [, prometheusName]) -> Metric initMetric(name [, prometheusTable]) -> Metric @@ -31,7 +33,9 @@ Create a custom metric with: :param string prometheusName: The optional Prometheus specific name :param table prometheusTable: The optional table of Prometheus specific options - Creates a new :class:`Metric` object with the name ``name``, and initializes it with optional Prometheus specific details. Calling this function with a string is identical to calling ``getMetric``. Calling this function with a table gives the metric an optional Prometheus name, type, and description. + Creates a new :class:`Metric` object with the name ``name`` and initializes it with optional Prometheus specific details. + Calling this function with a string is identical to calling :func:`getMetric`. + Calling this function with a table allows passing the desired Prometheus name, type, and description. The elements of the table can be: diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index 2c0f801a88..b52c94b46b 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -436,11 +436,9 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive std::string prometheusDescr; if (opts) { - auto* optPrometheusName = boost::get(&opts.get()); - if (optPrometheusName != nullptr) { + if (const auto* optPrometheusName = boost::get(&*opts); optPrometheusName != nullptr) { prometheusName = *optPrometheusName; - } else { - boost::optional> vars = {boost::get>(opts.get())}; + } else if (auto* vars = boost::get>(&*opts); vars != nullptr) { prometheusName = (*vars)["prometheusName"]; prometheusTypeName = (*vars)["type"]; prometheusDescr = (*vars)["description"]; diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index c8ad64b302..1aa0e1368d 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -191,31 +191,22 @@ std::atomic* initDynMetric(const std::string& str, const std::str return iter->second.d_ptr; } - std::string name(str); - if (!prometheusName.empty()) { - name = prometheusName; - } - else { - name = getPrometheusName(name); - } + std::string name = prometheusName.empty() ? getPrometheusName(str) : prometheusName; std::optional metricType; - if (!prometheusTypeName.empty()) { - static const std::map namesToTypes = { - {"counter", PrometheusMetricType::counter}, - {"gauge", PrometheusMetricType::gauge}, - }; - auto realtype = namesToTypes.find(prometheusTypeName); - if (realtype != namesToTypes.end()) { - metricType = std::optional(realtype->second); - } + if (prometheusTypeName == "counter") { + metricType = PrometheusMetricType::counter; + } + else if (prometheusTypeName == "gauge") { + metricType = PrometheusMetricType::gauge; } + std::optional descr; if (!prometheusDescr.empty()) { - descr = std::optional(std::move(prometheusDescr)); + descr = prometheusDescr; } - auto ret = dynmetrics{new std::atomic(), std::move(name), metricType, descr}; + auto ret = dynmetrics{new std::atomic(), std::move(name), metricType, std::move(descr)}; (*locked)[str] = ret; return ret.d_ptr; }