]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Stop reporting timeouts in `topSlow()`, add `topTimeouts()` 14573/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 20 Aug 2024 12:44:57 +0000 (14:44 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 20 Aug 2024 12:49:19 +0000 (14:49 +0200)
Until this commit `topSlow()` returned queries that timed out, which
is not very helpful. This was happening because timeouts are internally
recorded with a very high response time.
With this change, `topSlow()` now ignores queries that timed out, and
a new command is added to look into these: `topTimeouts()`.

pdns/dnsdistdist/dnsdist-console.cc
pdns/dnsdistdist/dnsdist-lua-inspection.cc
pdns/dnsdistdist/docs/reference/config.rst

index d1d273853511a0f3509446dd70471f9df935a46a..12926eeedf94dcf0f022a973a2a1ffc14d3df376 100644 (file)
@@ -844,7 +844,8 @@ static const std::vector<dnsdist::console::ConsoleKeyword> s_consoleKeywords
     {"topResponseRules", true, "[top][, vars]", "show `top` response rules"},
     {"topRules", true, "[top][, vars]", "show `top` rules"},
     {"topSelfAnsweredResponseRules", true, "[top][, vars]", "show `top` self-answered response rules"},
-    {"topSlow", true, "[top][, limit][, labels]", "show `top` queries slower than `limit` milliseconds, grouped by last `labels` labels"},
+    {"topSlow", true, "[top][, limit][, labels]", "show `top` queries slower than `limit` milliseconds (timeouts excepted), grouped by last `labels` labels"},
+    {"topTimeouts", true, "[top][, labels]", "show `top` queries that timed out, grouped by last `labels` labels"},
     {"TrailingDataRule", true, "", "Matches if the query has trailing data"},
     {"truncateTC", true, "bool", "if set (defaults to no starting with dnsdist 1.2.0) truncate TC=1 answers so they are actually empty. Fixes an issue for PowerDNS Authoritative Server 2.9.22. Note: turning this on breaks compatibility with RFC 6891."},
     {"unregisterDynBPFFilter", true, "DynBPFFilter", "unregister this dynamic BPF filter"},
index f3cef29f1e4daa4d68549e5665f0aa69fa004ba2..73e5fdaf1ff9a68c53e8347d112b66bf055fe171 100644 (file)
@@ -518,11 +518,18 @@ void setupLuaInspection(LuaContext& luaCtx)
 
   luaCtx.executeCode(R"(function topResponses(top, kind, labels) top = top or 10; kind = kind or 0; for k,v in ipairs(getTopResponses(top, kind, labels)) do show(string.format("%4d  %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)");
 
-  luaCtx.writeFunction("getSlowResponses", [](uint64_t top, uint64_t msec, boost::optional<int> labels) {
-    return getGenResponses(top, labels, [msec](const Rings::Response& resp) { return resp.usec > msec * 1000; });
+  luaCtx.writeFunction("getSlowResponses", [](uint64_t top, uint64_t msec, boost::optional<int> labels, boost::optional<bool> timeouts) {
+    return getGenResponses(top, labels, [msec, timeouts](const Rings::Response& resp) {
+      if (timeouts && *timeouts) {
+        return resp.usec == std::numeric_limits<unsigned int>::max();
+      }
+      return resp.usec > msec * 1000 && resp.usec != std::numeric_limits<unsigned int>::max();
+    });
   });
 
-  luaCtx.executeCode(R"(function topSlow(top, msec, labels) top = top or 10; msec = msec or 500; for k,v in ipairs(getSlowResponses(top, msec, labels)) do show(string.format("%4d  %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)");
+  luaCtx.executeCode(R"(function topSlow(top, msec, labels) top = top or 10; msec = msec or 500; for k,v in ipairs(getSlowResponses(top, msec, labels, false)) do show(string.format("%4d  %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)");
+
+  luaCtx.executeCode(R"(function topTimeouts(top, labels) top = top or 10; for k,v in ipairs(getSlowResponses(top, 0, labels, true)) do show(string.format("%4d  %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)");
 
   luaCtx.writeFunction("getTopBandwidth", [](uint64_t top) {
     setLuaNoSideEffect();
index 969b45db1242e15754eece773ed7074ffd2cb672..fb3c8c951864251705d84bbdd60d9f93ff155aeb 100644 (file)
@@ -1504,6 +1504,9 @@ Status, Statistics and More
 
 .. function:: topSlow([num[, limit[, labels]]])
 
+  .. versionchanged:: 1.9.7
+    queries that timed out are no longer reported by ``topSlow``, see :func:`topTimeouts` instead
+
   Print the ``num`` slowest queries that are slower than ``limit`` milliseconds.
   Optionally grouped by the rightmost ``labels`` DNS labels.
 
@@ -1511,6 +1514,16 @@ Status, Statistics and More
   :param int limit: Show queries slower than this amount of milliseconds, defaults to 2000
   :param int label: Number of labels to cut down to
 
+.. function:: topTimeouts([num[, labels]])
+
+  .. versionadded:: 1.9.7
+
+  Print the ``num`` queries that timed out the most.
+  Optionally grouped by the rightmost ``labels`` DNS labels.
+
+  :param int num: Number to show, defaults to 10
+  :param int label: Number of labels to cut down to
+
 .. _dynblocksref:
 
 Dynamic Blocks