From: bert hubert Date: Tue, 8 Dec 2015 10:05:23 +0000 (+0100) Subject: fix up dns ring measurements for BW and NXDOMAIN to not inflate rates erroneously X-Git-Tag: dnsdist-1.0.0-alpha1~99^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=479a54046a421a036f42734742b7de39303d8bd3;p=pdns fix up dns ring measurements for BW and NXDOMAIN to not inflate rates erroneously --- 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); }