From: Otto Moerbeek Date: Wed, 7 Sep 2022 13:42:54 +0000 (+0200) Subject: Provide metrics for rcodes returned bu auths. X-Git-Tag: rec-4.9.0-alpha0~20^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccdac0adaecdd2cacae63112f39292120e54cb6c;p=thirdparty%2Fpdns.git Provide metrics for rcodes returned bu auths. 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? --- diff --git a/pdns/dns.cc b/pdns/dns.cc index 12689d9831..1f04600001 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -57,12 +57,32 @@ std::vector RCode::rcodes_s = boost::assign::list_of ("Bad/missing Server Cookie") ; +static const std::array 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); diff --git a/pdns/dns.hh b/pdns/dns.hh index 218c7a3570..683f4d072b 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -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 rcodes_s; }; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 69aebb2a58..09b5854159 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -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& 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() diff --git a/pdns/syncres.cc b/pdns/syncres.cc index f8d604ca31..d940c2afb1 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -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(); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index f28f9168ce..b919b4e189 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -807,6 +807,7 @@ struct RecursorStats pdns::stat_t dns64prefixanswers{0}; pdns::stat_t maintenanceUsec{0}; pdns::stat_t maintenanceCalls{0}; + std::array authRCode; RecursorStats() : answers("answers", { 1000, 10000, 100000, 1000000 }), diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 24d5a9c938..64b25b5fa0 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -1154,6 +1154,11 @@ const std::map 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