Skip to content

Commit

Permalink
dnsdist: Report the TCP latency for TCP-only Do53, DoT and DoH backends
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rgacogne committed Mar 14, 2023
1 parent 426f9f0 commit f8f0911
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 7 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
4 changes: 2 additions & 2 deletions pdns/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/html/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ $(document).ready(function() {
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>';
$.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"];
var latency = (b["protocol"].includes("UDP") ? ((b["latency"] === null) ? 0.0 : b["latency"]) : ((b["tcpLatency"] === null) ? 0.0 : b["tcpLatency"]));
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>");
bouw = bouw + ("<td>"+b["weight"]+"</td><td>"+b["order"]+"</td><td align=left>"+b["pools"]+"</td></tr>");
});
Expand Down

0 comments on commit f8f0911

Please sign in to comment.