]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
One way of solving the race. Still needs operator[] though, since policyName 10605/head
authorOtto <otto.moerbeek@open-xchange.com>
Fri, 20 Aug 2021 11:49:37 +0000 (13:49 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Fri, 20 Aug 2021 11:49:37 +0000 (13:49 +0200)
can vary.

pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/recursordist/docs/metrics.rst
pdns/recursordist/rec_metrics.hh
pdns/syncres.cc
pdns/syncres.hh

index fc765629018cff73bb2da3db645b24fd0846caf3..158675c76dee5fc1827314abeae8a2945e8203e6 100644 (file)
@@ -1161,7 +1161,7 @@ static PolicyResult handlePolicyHit(const DNSFilterEngine::Policy& appliedPolicy
   /* don't account truncate actions for TCP queries, since they are not applied */
   if (appliedPolicy.d_kind != DNSFilterEngine::PolicyKind::Truncate || !dc->d_tcp) {
     ++g_stats.policyResults[appliedPolicy.d_kind];
-    ++g_stats.policyHits[appliedPolicy.getName()];
+    ++(g_stats.policyHits.lock()->operator[](appliedPolicy.getName()));
   }
 
   if (sr.doLog() &&  appliedPolicy.d_type != DNSFilterEngine::PolicyType::None) {
index eb562f5c2e0f109908bf7d9cae16d566326d775d..360b1f54c89b4bcdb599b474af3614eec2392dae 100644 (file)
@@ -1153,13 +1153,13 @@ static StatsMap toCPUStatsMap(const string& name)
   return entries;
 }
 
-static StatsMap toRPZStatsMap(const string& name, const std::unordered_map<std::string, std::atomic<uint64_t>>& map)
+static StatsMap toRPZStatsMap(const string& name, LockGuarded<std::unordered_map<std::string, std::atomic<uint64_t>>>& map)
 {
   const string pbasename = getPrometheusName(name);
   StatsMap entries;
 
   uint64_t total = 0;
-  for (const auto& entry: map) {
+  for (const auto& entry: *map.lock()) {
     auto &key = entry.first;
     auto count = entry.second.load();
     std::string sname, pname;
@@ -1168,7 +1168,7 @@ static StatsMap toRPZStatsMap(const string& name, const std::unordered_map<std::
       pname = pbasename + "{type=\"filter\"}";
     } else {
       sname = name + "-rpz-" + key;
-      pname = pbasename + "{type=\"rpz\",policyname=\"" + entry.first + "\"}";
+      pname = pbasename + "{type=\"rpz\",policyname=\"" + key + "\"}";
     }
     entries.emplace(sname, StatsMapEntry{pname, std::to_string(count)});
     total += count;
index c1f7255483b595d5b8aa3fbfa6ad5ca6796be70d..a3a83c338cf3e0a8219599575f9ba6c38ab415a8 100644 (file)
@@ -597,7 +597,7 @@ packets dropped because of (Lua) policy decision
 policy-hits
 ^^^^^^^^^^^
 Number of policy decisions based on Lua (``type = "filter"``), or RPZ (``type = "rpz"``). RPZ hits include the :ref:`rpz-policyName`.
-These metrics are useful for Prometheus and not listed other outputs by default.
+These metrics are useful for Prometheus and not listed in other outputs by default.
 
 policy-result-noaction
 ^^^^^^^^^^^^^^^^^^^^^^
index 1e6d875f284d0cba03f3db3a6c94f27f0804c406..1881ce12c4b7d559ad0e8b866525190fbc9c3890 100644 (file)
@@ -26,7 +26,7 @@
 #include <map>
 
 // Metric types for Prometheus
-enum class PrometheusMetricType
+enum class PrometheusMetricType : uint8_t
 {
   counter,
   gauge,
index e484736429cf96a2cde1a2f8c3697a66caf8f895..1b1910554ef2b4446f57e79159d3af285ef2fe4d 100644 (file)
@@ -2184,7 +2184,7 @@ void SyncRes::handlePolicyHit(const std::string& prefix, const DNSName& qname, c
   /* don't account truncate actions for TCP queries, since they are not applied */
   if (d_appliedPolicy.d_kind != DNSFilterEngine::PolicyKind::Truncate || !d_queryReceivedOverTCP) {
     ++g_stats.policyResults[d_appliedPolicy.d_kind];
-    ++g_stats.policyHits[d_appliedPolicy.getName()];
+    ++(g_stats.policyHits.lock()->operator[](d_appliedPolicy.getName()));
   }
 
   if (d_appliedPolicy.d_type != DNSFilterEngine::PolicyType::None) {
index 7bbadc4993de5520791a32213d0812de72829d19..4b1f752c27f3d0462d98a836722d80fd01f91efe 100644 (file)
@@ -1072,7 +1072,7 @@ struct RecursorStats
   std::map<vState, std::atomic<uint64_t> > dnssecResults;
   std::map<vState, std::atomic<uint64_t> > xdnssecResults;
   std::map<DNSFilterEngine::PolicyKind, std::atomic<uint64_t> > policyResults;
-  std::unordered_map<std::string, std::atomic<uint64_t>> policyHits;
+  LockGuarded<std::unordered_map<std::string, std::atomic<uint64_t>>> policyHits;
   std::atomic<uint64_t> rebalancedQueries{0};
   std::atomic<uint64_t> proxyProtocolInvalidCount{0};
   std::atomic<uint64_t> nodLookupsDroppedOversize{0};