From f8f09117af520ca2a3da328207c3234edfba353b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 14 Mar 2023 10:22:14 +0100 Subject: [PATCH] dnsdist: Report the TCP latency for TCP-only Do53, DoT and DoH backends Since 1.8.0 we separately record the latency for queries forwarded over UDP and TCP, to get a better picture of what is going on. It means we have to be careful to pick the relevant one when looking at the latency. --- pdns/dnsdist-carbon.cc | 1 + pdns/dnsdist-lua-bindings.cc | 2 +- pdns/dnsdist-lua.cc | 4 ++-- pdns/dnsdist-snmp.cc | 2 +- pdns/dnsdist.hh | 8 ++++++++ pdns/dnsdistdist/dnsdist-lbpolicies.cc | 2 +- pdns/dnsdistdist/dnsdist-lua-ffi.cc | 2 +- pdns/dnsdistdist/html/local.js | 2 +- 8 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index b953180180e8..74514ab963a0 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -77,6 +77,7 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint) str << base << "responses" << ' ' << state->responses.load() << " " << now << "\r\n"; str << base << "drops" << ' ' << state->reuseds.load() << " " << now << "\r\n"; str << base << "latency" << ' ' << (state->d_config.availability != DownstreamState::Availability::Down ? state->latencyUsec / 1000.0 : 0) << " " << now << "\r\n"; + str << base << "latencytcp" << ' ' << (state->d_config.availability != DownstreamState::Availability::Down ? state->latencyUsecTCP / 1000.0 : 0) << " " << now << "\r\n"; str << base << "senderrors" << ' ' << state->sendErrors.load() << " " << now << "\r\n"; str << base << "outstanding" << ' ' << state->outstanding.load() << " " << now << "\r\n"; str << base << "tcpdiedsendingquery" << ' ' << state->tcpDiedSendingQuery.load() << " " << now << "\r\n"; diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index d6087531fa6c..5246e482142e 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -119,7 +119,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) }); luaCtx.registerFunction("getOutstanding", [](const DownstreamState& s) { return s.outstanding.load(); }); luaCtx.registerFunction("getDrops", [](const DownstreamState& s) { return s.reuseds.load(); }); - luaCtx.registerFunction("getLatency", [](const DownstreamState& s) { return s.latencyUsec; }); + luaCtx.registerFunction("getLatency", [](const DownstreamState& s) { return s.getRelevantLatencyUsec(); }); luaCtx.registerFunction("isUp", &DownstreamState::isUp); luaCtx.registerFunction("setDown", &DownstreamState::setDown); luaCtx.registerFunction("setUp", &DownstreamState::setUp); diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index fdce3a779f9d..94a5d1bb5148 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -904,10 +904,10 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) pools += p; } if (showUUIDs) { - ret << (fmt % counter % s->getName() % s->d_config.remote.toStringWithPort() % status % s->queryLoad % s->qps.getRate() % s->d_config.order % s->d_config.d_weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec / 1000.0) % s->outstanding.load() % pools % *s->d_config.id) << endl; + ret << (fmt % counter % s->getName() % s->d_config.remote.toStringWithPort() % status % s->queryLoad % s->qps.getRate() % s->d_config.order % s->d_config.d_weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->getRelevantLatencyUsec() / 1000.0) % s->outstanding.load() % pools % *s->d_config.id) << endl; } else { - ret << (fmt % counter % s->getName() % s->d_config.remote.toStringWithPort() % status % s->queryLoad % s->qps.getRate() % s->d_config.order % s->d_config.d_weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec / 1000.0) % s->outstanding.load() % pools) << endl; + ret << (fmt % counter % s->getName() % s->d_config.remote.toStringWithPort() % status % s->queryLoad % s->qps.getRate() % s->d_config.order % s->d_config.d_weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->getRelevantLatencyUsec() / 1000.0) % s->outstanding.load() % pools) << endl; } totQPS += s->queryLoad; totQueries += s->queries.load(); diff --git a/pdns/dnsdist-snmp.cc b/pdns/dnsdist-snmp.cc index 784af371ab62..d853a32d04ea 100644 --- a/pdns/dnsdist-snmp.cc +++ b/pdns/dnsdist-snmp.cc @@ -303,7 +303,7 @@ static int backendStatTable_handler(netsnmp_mib_handler* handler, break; case COLUMN_BACKENDLATENCY: DNSDistSNMPAgent::setCounter64Value(request, - server->latencyUsec/1000.0); + server->getRelevantLatencyUsec() / 1000.0); break; case COLUMN_BACKENDWEIGHT: DNSDistSNMPAgent::setCounter64Value(request, diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 88900e1dab03..472a729ba170 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -1048,6 +1048,14 @@ public: return dnsdist::Protocol::DoUDP; } + double getRelevantLatencyUsec() const + { + if (isTCPOnly()) { + return latencyUsecTCP; + } + return latencyUsec; + } + static int s_udpTimeout; static bool s_randomizeSockets; static bool s_randomizeIDs; diff --git a/pdns/dnsdistdist/dnsdist-lbpolicies.cc b/pdns/dnsdistdist/dnsdist-lbpolicies.cc index cec6769dd0fb..70fec893c88a 100644 --- a/pdns/dnsdistdist/dnsdist-lbpolicies.cc +++ b/pdns/dnsdistdist/dnsdist-lbpolicies.cc @@ -40,7 +40,7 @@ template static std::shared_ptr getLeastOutstanding(c size_t usableServers = 0; for (const auto& d : servers) { if (d.second->isUp()) { - poss[usableServers] = std::make_pair(std::make_tuple(d.second->outstanding.load(), d.second->d_config.order, d.second->latencyUsec), d.first); + poss[usableServers] = std::make_pair(std::make_tuple(d.second->outstanding.load(), d.second->d_config.order, d.second->getRelevantLatencyUsec()), d.first); usableServers++; } } diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi.cc b/pdns/dnsdistdist/dnsdist-lua-ffi.cc index b690dd368bb5..c9fa8407ef80 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/dnsdist-lua-ffi.cc @@ -683,7 +683,7 @@ int dnsdist_ffi_server_get_order(const dnsdist_ffi_server_t* server) double dnsdist_ffi_server_get_latency(const dnsdist_ffi_server_t* server) { - return server->server->latencyUsec; + return server->server->getRelevantLatencyUsec(); } bool dnsdist_ffi_server_is_up(const dnsdist_ffi_server_t* server) diff --git a/pdns/dnsdistdist/html/local.js b/pdns/dnsdistdist/html/local.js index cbf953406368..1dc39b87aaf5 100644 --- a/pdns/dnsdistdist/html/local.js +++ b/pdns/dnsdistdist/html/local.js @@ -193,7 +193,7 @@ $(document).ready(function() { var bouw=''; $.each(data["servers"], function(a,b) { bouw = bouw + (""); - var latency = (b["latency"] === null) ? 0.0 : b["latency"]; + var latency = (b["protocol"].includes("UDP") ? ((b["latency"] === null) ? 0.0 : b["latency"]) : ((b["tcpLatency"] === null) ? 0.0 : b["tcpLatency"])); bouw = bouw + (""); bouw = bouw + (""); });
#NameAddressStatusLatencyQueriesDropsQPSOutWeightOrderPools
"+b["id"]+""+b["name"]+""+b["address"]+""+b["state"]+""+latency.toFixed(2)+""+b["queries"]+""+b["reuseds"]+""+(b["qps"]).toFixed(2)+""+b["outstanding"]+""+b["weight"]+""+b["order"]+""+b["pools"]+"