From 479a54046a421a036f42734742b7de39303d8bd3 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 8 Dec 2015 11:05:23 +0100 Subject: [PATCH] fix up dns ring measurements for BW and NXDOMAIN to not inflate rates erroneously --- pdns/dnsdist-lua2.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 9c036ecb2..40951bbbd 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -22,8 +22,7 @@ static double DiffTime(const struct timespec& first, const struct timespec& seco } map filterScore(const map& counts, - struct timespec& mintime, - struct timespec& maxtime, int rate) + double delta, int rate) { std::multimap score; for(const auto& e : counts) @@ -31,7 +30,6 @@ map filterScore(const map ret; - double delta=DiffTime(mintime, maxtime); double lim = delta*rate; for(auto s = score.crbegin(); s != score.crend() && s->first > lim; ++s) { @@ -45,42 +43,45 @@ typedef map cou map exceedRespGen(int rate, int seconds, std::function T) { counts_t counts; - struct timespec mintime, maxtime, cutoff; - clock_gettime(CLOCK_MONOTONIC, &maxtime); - mintime=cutoff=maxtime; + struct timespec cutoff, mintime, now; + clock_gettime(CLOCK_MONOTONIC, &now); + cutoff = mintime = now; cutoff.tv_sec -= seconds; for(const auto& c : g_rings.respRing) { if(seconds && c.when < cutoff) continue; + if(now < c.when) + continue; T(counts, c); if(c.when < mintime) mintime = c.when; } - - return filterScore(counts, mintime, maxtime, rate); + double delta = seconds ? seconds : DiffTime(now, mintime); + return filterScore(counts, delta, rate); } map exceedQueryGen(int rate, int seconds, std::function T) { counts_t counts; - struct timespec mintime, maxtime, cutoff; - clock_gettime(CLOCK_MONOTONIC, &maxtime); - mintime=cutoff=maxtime; + struct timespec cutoff, mintime, now; + clock_gettime(CLOCK_MONOTONIC, &now); + cutoff = mintime = now; cutoff.tv_sec -= seconds; - + ReadLock rl(&g_rings.queryLock); for(const auto& c : g_rings.queryRing) { if(seconds && c.when < cutoff) continue; - + if(now < c.when) + continue; T(counts, c); if(c.when < mintime) mintime = c.when; } - - return filterScore(counts, mintime, maxtime, rate); + double delta = seconds ? seconds : DiffTime(now, mintime); + return filterScore(counts, delta, rate); } -- 2.40.0