From: Remi Gacogne Date: Mon, 18 Jan 2021 10:19:56 +0000 (+0100) Subject: dnsdist: Add a debugging function to load a grepq into the rings X-Git-Tag: dnsdist-1.6.0-alpha1~26^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9984%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Add a debugging function to load a grepq into the rings --- diff --git a/pdns/dnsdist-rings.cc b/pdns/dnsdist-rings.cc index c7cb57d22b..29da4431b4 100644 --- a/pdns/dnsdist-rings.cc +++ b/pdns/dnsdist-rings.cc @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + #include "dnsdist-rings.hh" size_t Rings::numDistinctRequestors() @@ -79,3 +81,73 @@ std::unordered_map>> Rings::getTopBand ret.insert({count, {"Rest", rest, total > 0 ? 100.0*rest/total : 100.0}}); return ret; } + +size_t Rings::loadFromFile(const std::string& filepath, const struct timespec& now) +{ + ifstream ifs(filepath); + if (!ifs) { + throw std::runtime_error("unable to open the file at " + filepath); + } + + size_t inserted = 0; + string line; + dnsheader dh; + memset(&dh, 0, sizeof(dh)); + + while (std::getline(ifs, line)) { + boost::trim_right_if(line, boost::is_any_of(" \r\n\x1a")); + boost::trim_left(line); + bool isResponse = false; + vector parts; + stringtok(parts, line, " \t,"); + + if (parts.size() == 7) { + } + else if (parts.size() >= 10 && parts.size() <= 12) { + isResponse = true; + } + else { + cerr<<"skipping line with "< timeStr; + stringtok(timeStr, parts.at(idx++), "."); + if (timeStr.size() != 2) { + cerr<<"skipping invalid time "< > d_shards; std::atomic d_blockingQueryInserts; std::atomic d_blockingResponseInserts; diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index b3b254baed..dd8d2e3bd1 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -233,7 +233,7 @@ testrunner_SOURCES = \ dnsdist-lua-ffi-interface.h dnsdist-lua-ffi-interface.inc \ dnsdist-lua-ffi.cc dnsdist-lua-ffi.hh \ dnsdist-lua-vars.cc \ - dnsdist-rings.hh \ + dnsdist-rings.cc dnsdist-rings.hh \ dnsdist-xpf.cc dnsdist-xpf.hh \ dnsdist.hh \ dnslabeltext.cc \