]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Nits
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 5 Nov 2025 13:40:06 +0000 (14:40 +0100)
committerJess Bees <jesse@toomanybees.com>
Mon, 17 Nov 2025 19:35:55 +0000 (14:35 -0500)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/docs/lua-scripting/statistics.rst
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/rec_channel_rec.cc

index 1362e312f9fe024a0bbaa409be030831a90848fd..dd16878b513464ad2a438f02ef56885295be5e76 100644 (file)
@@ -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:
 
index 2c0f801a889a8eee195dfa07c763189ed908ab49..b52c94b46bd8347b4a4c978c38edd14e49bb7bb1 100644 (file)
@@ -436,11 +436,9 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive
     std::string prometheusDescr;
 
     if (opts) {
-      auto* optPrometheusName = boost::get<std::string>(&opts.get());
-      if (optPrometheusName != nullptr) {
+      if (const auto* optPrometheusName = boost::get<std::string>(&*opts); optPrometheusName != nullptr) {
         prometheusName = *optPrometheusName;
-      } else {
-        boost::optional<std::unordered_map<std::string, std::string>> vars = {boost::get<std::unordered_map<std::string, std::string>>(opts.get())};
+      } else if (auto* vars = boost::get<std::unordered_map<std::string, std::string>>(&*opts); vars != nullptr) {
         prometheusName = (*vars)["prometheusName"];
         prometheusTypeName = (*vars)["type"];
         prometheusDescr = (*vars)["description"];
index c8ad64b3029fada72e1a9eb8c63b6e2884a740ac..1aa0e1368de114e17b8dc99144249b168d96fa05 100644 (file)
@@ -191,31 +191,22 @@ std::atomic<unsigned long>* 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<PrometheusMetricType> metricType;
-  if (!prometheusTypeName.empty()) {
-    static const std::map<std::string, PrometheusMetricType> 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<std::string> descr;
   if (!prometheusDescr.empty()) {
-    descr = std::optional(std::move(prometheusDescr));
+    descr = prometheusDescr;
   }
 
-  auto ret = dynmetrics{new std::atomic<unsigned long>(), std::move(name), metricType, descr};
+  auto ret = dynmetrics{new std::atomic<unsigned long>(), std::move(name), metricType, std::move(descr)};
   (*locked)[str] = ret;
   return ret.d_ptr;
 }