From b3ccd3eaca50820cafcf520d8374c73774c23840 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 18 Jan 2021 11:19:56 +0100 Subject: [PATCH] dnsdist: Add a debugging function to load a grepq into the rings --- pdns/dnsdist-rings.cc | 72 ++++++++++++++++++++++++++++++++++++ pdns/dnsdist-rings.hh | 4 ++ pdns/dnsdistdist/Makefile.am | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) 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 \ -- 2.47.2