Skip to content

Commit

Permalink
Merge pull request PowerDNS#12648 from rgacogne/ddist-relevant-latency
Browse files Browse the repository at this point in the history
dnsdist: Report the TCP latency for TCP-only Do53, DoT and DoH backends
  • Loading branch information
rgacogne authored Mar 15, 2023
2 parents 48126e3 + fe77240 commit 4c5f127
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions pdns/dnsdist-carbon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdist-lua-bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
});
luaCtx.registerFunction<uint64_t(DownstreamState::*)()const>("getOutstanding", [](const DownstreamState& s) { return s.outstanding.load(); });
luaCtx.registerFunction<uint64_t(DownstreamState::*)()const>("getDrops", [](const DownstreamState& s) { return s.reuseds.load(); });
luaCtx.registerFunction<double(DownstreamState::*)()const>("getLatency", [](const DownstreamState& s) { return s.latencyUsec; });
luaCtx.registerFunction<double(DownstreamState::*)()const>("getLatency", [](const DownstreamState& s) { return s.getRelevantLatencyUsec(); });
luaCtx.registerFunction("isUp", &DownstreamState::isUp);
luaCtx.registerFunction("setDown", &DownstreamState::setDown);
luaCtx.registerFunction("setUp", &DownstreamState::setUp);
Expand Down
21 changes: 12 additions & 9 deletions pdns/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdist-snmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions pdns/dnsdist.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lbpolicies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ template <class T> static std::shared_ptr<DownstreamState> 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++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lua-ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions pdns/dnsdistdist/html/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,12 @@ $(document).ready(function() {
$("#version").text(data["daemon_type"]+" "+data["version"]);
$("#acl").text(data["acl"]);
$("#local").text(data["local"]);
var bouw='<table width="100%"><tr align=right><th>#</th><th align=left>Name</th><th align=left>Address</th><th>Status</th><th>Latency</th><th>Queries</th><th>Drops</th><th>QPS</th><th>Out</th><th>Weight</th><th>Order</th><th align=left>Pools</th></tr>';
var bouw='<table width="100%"><tr align=right><th>#</th><th align=left>Name</th><th align=left>Address</th><th>Status</th><th>UDP Latency</th><th>TCP Latency</th><th>Queries</th><th>Drops</th><th>QPS</th><th>Out</th><th>Weight</th><th>Order</th><th align=left>Pools</th></tr>';
$.each(data["servers"], function(a,b) {
bouw = bouw + ("<tr align=right><td>"+b["id"]+"</td><td align=left>"+b["name"]+"</td><td align=left>"+b["address"]+"</td><td>"+b["state"]+"</td>");
var latency = (b["latency"] === null) ? 0.0 : b["latency"];
bouw = bouw + ("<td>"+latency.toFixed(2)+"</td><td>"+b["queries"]+"</td><td>"+b["reuseds"]+"</td><td>"+(b["qps"]).toFixed(2)+"</td><td>"+b["outstanding"]+"</td>");
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 + ("<td>"+latency+"</td><td>"+tcpLatency+"</td><td>"+b["queries"]+"</td><td>"+b["reuseds"]+"</td><td>"+(b["qps"]).toFixed(2)+"</td><td>"+b["outstanding"]+"</td>");
bouw = bouw + ("<td>"+b["weight"]+"</td><td>"+b["order"]+"</td><td align=left>"+b["pools"]+"</td></tr>");
});
bouw = bouw + "</table>";
Expand Down
6 changes: 3 additions & 3 deletions regression-tests.dnsdist/test_BackendDiscovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down

0 comments on commit 4c5f127

Please sign in to comment.