]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Provide metrics for rcodes returned bu auths.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 7 Sep 2022 13:42:54 +0000 (15:42 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 27 Sep 2022 14:31:51 +0000 (16:31 +0200)
Only basic rcodes (found in dns header) counted for now, as we
do not process extended error codes in OPT records.

Maybe this should be a histogram in the Prometheus case?

pdns/dns.cc
pdns/dns.hh
pdns/rec_channel_rec.cc
pdns/syncres.cc
pdns/syncres.hh
pdns/ws-recursor.cc

index 12689d9831420e7124b18b445bba45cfb1e184c0..1f046000011d8abe4b609f3fc35676aaa7f83e9d 100644 (file)
@@ -57,12 +57,32 @@ std::vector<std::string> RCode::rcodes_s = boost::assign::list_of
   ("Bad/missing Server Cookie")
 ;
 
+static const std::array<std::string, 10> rcodes_short_s =  {
+  "noerror",
+  "formerr",
+  "servfail",
+  "nxdomain",
+  "notimp",
+  "refused",
+  "yxdomain",
+  "yxrrset",
+  "nxrrset",
+  "notauth",
+};
+
 std::string RCode::to_s(uint8_t rcode) {
   if (rcode > 0xF)
     return std::string("ErrOutOfRange");
   return ERCode::to_s(rcode);
 }
 
+std::string RCode::to_short_s(uint8_t rcode) {
+  if (rcode >= rcodes_short_s.size()) {
+    return "rcode" + std::to_string(rcode);
+  }
+  return rcodes_short_s.at(rcode);
+}
+
 std::string ERCode::to_s(uint8_t rcode) {
   if (rcode > RCode::rcodes_s.size()-1)
     return std::string("Err#")+std::to_string(rcode);
index 218c7a3570a2f64e5ca6e25eef8b56eacfc815c1..683f4d072b9bfe9e83446618b4d778013dc13db7 100644 (file)
@@ -34,6 +34,7 @@ class RCode
 public:
   enum rcodes_ { NoError=0, FormErr=1, ServFail=2, NXDomain=3, NotImp=4, Refused=5, YXDomain=6, YXRRSet=7, NXRRSet=8, NotAuth=9, NotZone=10};
   static std::string to_s(uint8_t rcode);
+  static std::string to_short_s(uint8_t rcode);
   static std::vector<std::string> rcodes_s;
 };
 
index 69aebb2a581f57377fb9c585fa6932da67c08b0a..09b5854159b03cc54481c33a52d5e648205b31aa 100644 (file)
@@ -1121,6 +1121,21 @@ static StatsMap toStatsMap(const string& name, const pdns::AtomicHistogram& hist
   return entries;
 }
 
+static StatsMap toAuthRCodeStatsMap(const string& name, const std::array<pdns::stat_t, 16>& v)
+{
+  const string pbasename = getPrometheusName(name);
+  StatsMap entries;
+
+  uint8_t n = 0;
+  for (const auto& entry : v) {
+    const auto key = RCode::to_short_s(n);
+    std::string pname = pbasename + "{rcode=\"" + key + "\"}";
+    entries.emplace("auth-" + key + "-answers", StatsMapEntry{pname, std::to_string(entry)});
+    n++;
+  }
+  return entries;
+}
+
 static StatsMap toCPUStatsMap(const string& name)
 {
   const string pbasename = getPrometheusName(name);
@@ -1451,6 +1466,9 @@ static void registerAllStats1()
   addGetStat("proxy-mapping-total", []() {
     return toProxyMappingStatsMap("proxy-mapping-total");
   });
+  addGetStat("auth-rcode-answers", []() {
+    return toAuthRCodeStatsMap("auth-rcode-answers", g_stats.authRCode);
+  });
 }
 
 void registerAllStats()
index f8d604ca31c2dc929dcb0cdaf92b781f5b8a8767..d940c2afb148bc59ed1245098f80cc5417817928 100644 (file)
@@ -5194,6 +5194,7 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname,
 
   d_totUsec += lwr.d_usec;
   accountAuthLatency(lwr.d_usec, remoteIP.sin4.sin_family);
+  ++g_stats.authRCode[lwr.d_rcode];
 
   if (!dontThrottle) {
     auto dontThrottleNames = g_dontThrottleNames.getLocal();
index f28f9168ce2a9d919c04e1b46356ec5d20aa65c1..b919b4e18927c3d7a38acf0ceb6b55129404d11c 100644 (file)
@@ -807,6 +807,7 @@ struct RecursorStats
   pdns::stat_t dns64prefixanswers{0};
   pdns::stat_t maintenanceUsec{0};
   pdns::stat_t maintenanceCalls{0};
+  std::array<pdns::stat_t, 16> authRCode;
 
   RecursorStats() :
     answers("answers", { 1000, 10000, 100000, 1000000 }),
index 24d5a9c93828c20c7509252e05c3ede7674e5367..64b25b5fa010380a9cc485fb2c1e2f72b4ea0526 100644 (file)
@@ -1154,6 +1154,11 @@ const std::map<std::string, MetricDefinition> MetricDefinitionStorage::d_metrics
   {"proxy-mapping-total-n-0",
    MetricDefinition(PrometheusMetricType::multicounter,
                     "Number of queries matching proxyMappings")},
+
+  // For multicounters, state the first
+  {"auth-noerror-answers",
+   MetricDefinition(PrometheusMetricType::multicounter,
+                    "Count of RCodes returned by authoritative servers")},
 };
 
 #define CHECK_PROMETHEUS_METRICS 0