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..6e3252f809a3 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -881,14 +881,15 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) ostringstream ret; boost::format fmt; + auto latFmt = boost::format("%5.1f"); if (showUUIDs) { - fmt = boost::format("%1$-3d %15$-36s %2$-20.20s %|62t|%3% %|107t|%4$5s %|88t|%5$7.1f %|103t|%6$7d %|106t|%7$10d %|115t|%8$10d %|117t|%9$10d %|123t|%10$7d %|128t|%11$5.1f %|146t|%12$5.1f %|152t|%13$11d %14%"); - // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools" % "UUID") << endl; + fmt = boost::format("%1$-3d %15$-36s %2$-20.20s %|62t|%3% %|107t|%4$5s %|88t|%5$7.1f %|103t|%6$7d %|106t|%7$10d %|115t|%8$10d %|117t|%9$10d %|123t|%10$7d %|128t|%11$5.1f %|146t|%12$5s %|152t|%16$5s %|158t|%13$11d %14%"); + // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (tcp latency) + ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools" % "UUID" % "TCP") << endl; } else { - fmt = boost::format("%1$-3d %2$-20.20s %|25t|%3% %|70t|%4$5s %|51t|%5$7.1f %|66t|%6$7d %|69t|%7$10d %|78t|%8$10d %|80t|%9$10d %|86t|%10$7d %|91t|%11$5.1f %|109t|%12$5.1f %|115t|%13$11d %14%"); - ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools") << endl; + fmt = boost::format("%1$-3d %2$-20.20s %|25t|%3% %|70t|%4$5s %|51t|%5$7.1f %|66t|%6$7d %|69t|%7$10d %|78t|%8$10d %|80t|%9$10d %|86t|%10$7d %|91t|%11$5.1f %|109t|%12$5s %|115t|%15$5s %|121t|%13$11d %14%"); + ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools" % "TCP") << endl; } uint64_t totQPS{0}, totQueries{0}, totDrops{0}; @@ -903,11 +904,13 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } pools += p; } + const std::string latency = (s->latencyUsec == 0.0 ? "-" : boost::str(latFmt % (s->latencyUsec / 1000.0))); + const std::string latencytcp = (s->latencyUsecTCP == 0.0 ? "-" : boost::str(latFmt % (s->latencyUsecTCP / 1000.0))); 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) % latency % s->outstanding.load() % pools % *s->d_config.id % latencytcp) << 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) % latency % s->outstanding.load() % pools % latencytcp) << endl; } totQPS += s->queryLoad; totQueries += s->queries.load(); @@ -916,12 +919,12 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } if (showUUIDs) { ret << (fmt % "All" % "" % "" % "" - % (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" % "") + % (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" % "" % "") << endl; } else { ret << (fmt % "All" % "" % "" % "" - % (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "") + % (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" % "") << endl; } 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 05277e4e9ccb..81c1b061faae 100644 --- a/pdns/dnsdistdist/html/local.js +++ b/pdns/dnsdistdist/html/local.js @@ -193,11 +193,12 @@ $(document).ready(function() { $("#version").text(data["daemon_type"]+" "+data["version"]); $("#acl").text(data["acl"]); $("#local").text(data["local"]); - var bouw=''; + var bouw='
#NameAddressStatusLatencyQueriesDropsQPSOutWeightOrderPools
'; $.each(data["servers"], function(a,b) { bouw = bouw + (""); - var latency = (b["latency"] === null) ? 0.0 : b["latency"]; - bouw = bouw + (""); + var latency = (b["latency"] === null || b["latency"] === 0.0) ? "-" : b["latency"].toFixed(2); + var tcpLatency = (b["tcpLatency"] === null || b["tcpLatency"] === 0.0) ? "-" : b["tcpLatency"].toFixed(2); + bouw = bouw + (""); bouw = bouw + (""); }); bouw = bouw + "
#NameAddressStatusUDP LatencyTCP LatencyQueriesDropsQPSOutWeightOrderPools
"+b["id"]+""+b["name"]+""+b["address"]+""+b["state"]+""+latency.toFixed(2)+""+b["queries"]+""+b["reuseds"]+""+(b["qps"]).toFixed(2)+""+b["outstanding"]+""+latency+""+tcpLatency+""+b["queries"]+""+b["reuseds"]+""+(b["qps"]).toFixed(2)+""+b["outstanding"]+""+b["weight"]+""+b["order"]+""+b["pools"]+"
"; diff --git a/regression-tests.dnsdist/test_BackendDiscovery.py b/regression-tests.dnsdist/test_BackendDiscovery.py index f8b1f14041e7..df54c74e3815 100644 --- a/regression-tests.dnsdist/test_BackendDiscovery.py +++ b/regression-tests.dnsdist/test_BackendDiscovery.py @@ -356,7 +356,7 @@ def checkBackendsUpgraded(self): if line.startswith('#') or line.startswith('All'): continue tokens = line.split() - self.assertTrue(len(tokens) == 12 or len(tokens) == 13) + self.assertTrue(len(tokens) == 13 or len(tokens) == 14) if tokens[1] == '127.0.0.1:10652': # in this particular case, the upgraded backend # does not replace the existing one and thus @@ -365,8 +365,8 @@ def checkBackendsUpgraded(self): else: self.assertEquals(tokens[2], 'UP') pool = '' - if len(tokens) == 13: - pool = tokens[12] + if len(tokens) == 14: + pool = tokens[13] backends[tokens[1]] = pool expected = {