]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: always include stats for RPZs in Prometheus data 14557/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 24 Jul 2024 12:14:40 +0000 (14:14 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 14 Aug 2024 07:36:58 +0000 (09:36 +0200)
Previously, zero stats would be skipped, making sure correct policy names are used.
Fixes #14522

pdns/recursordist/rec-main.cc

index f2262f8b3cd9c48f403c368d109699c10d551697..89543ee5671b475ea6d73e4cb7863363faf30f8f 100644 (file)
@@ -2907,6 +2907,10 @@ static void recursorThread()
       checkFrameStreamExport(luaconfsLocal, luaconfsLocal->frameStreamExportConfig, t_frameStreamServersInfo);
       checkFrameStreamExport(luaconfsLocal, luaconfsLocal->nodFrameStreamExportConfig, t_nodFrameStreamServersInfo);
 #endif
+      for (const auto& rpz : luaconfsLocal->rpzs) {
+        string name = rpz.polName.empty() ? (rpz.primaries.empty() ? "rpzFile" : rpz.name) : rpz.polName;
+        t_Counters.at(rec::PolicyNameHits::policyName).counts[name] = 0;
+      }
     }
 
     t_fdm = unique_ptr<FDMultiplexer>(getMultiplexer(log));
@@ -3439,11 +3443,19 @@ void startLuaConfigDelayedThreads(const vector<RPZTrackerParams>& rpzs, uint64_t
   }
 }
 
+static void* pleaseInitPolCounts(const string& name)
+{
+  if (t_Counters.at(rec::PolicyNameHits::policyName).counts.count(name) == 0) {
+    t_Counters.at(rec::PolicyNameHits::policyName).counts[name] = 0;
+  }
+  return nullptr;
+}
+
 static void activateRPZFile(const RPZTrackerParams& params, LuaConfigItems& lci, shared_ptr<DNSFilterEngine::Zone>& zone)
 {
   auto log = lci.d_slog->withValues("file", Logging::Loggable(params.name));
 
-  zone->setName(params.polName);
+  zone->setName(params.polName.empty() ? "rpzFile" : params.polName);
   try {
     SLOG(g_log << Logger::Warning << "Loading RPZ from file '" << params.name << "'" << endl,
          log->info(Logr::Info, "Loading RPZ from file"));
@@ -3519,10 +3531,11 @@ static void activateRPZs(LuaConfigItems& lci)
     else {
       DNSName domain(params.name);
       zone->setDomain(domain);
-      zone->setName(params.polName);
+      zone->setName(params.polName.empty() ? params.name : params.polName);
       params.zoneIdx = lci.dfe.addZone(zone);
       activateRPZPrimary(params, lci, zone, domain);
     }
+    broadcastFunction([name = zone->getName()] { return pleaseInitPolCounts(name); });
   }
 }