Skip to content

Commit

Permalink
Merge pull request #14942 from omoerbeek/rec-sockets-less-chatty
Browse files Browse the repository at this point in the history
rec: log only one line per protocol for listening sockets,
  • Loading branch information
omoerbeek authored Dec 10, 2024
2 parents 9a78505 + 54d897e commit 4759ae2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 5 additions & 3 deletions pdns/recursordist/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2682,7 +2682,8 @@ static void handleNewUDPQuestion(int fileDesc, FDMultiplexer::funcparam_t& /* va
t_Counters.updateSnap(g_regressionTestMode);
}

unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log)
// The two last arguments to makeUDPServerSockets are used for logging purposes only
unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log, bool doLog, unsigned int instances)
{
int one = 1;
vector<string> localAddresses;
Expand Down Expand Up @@ -2771,8 +2772,9 @@ unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log)

deferredAdds.emplace_back(socketFd, handleNewUDPQuestion);
g_listenSocketsAddresses[socketFd] = address; // this is written to only from the startup thread, not from the workers
SLOG(g_log << Logger::Info << "Listening for UDP queries on " << address.toStringWithPort() << endl,
log->info(Logr::Info, "Listening for queries", "proto", Logging::Loggable("UDP"), "address", Logging::Loggable(address)));
}
if (doLog) {
log->info(Logr::Info, "Listening for queries", "proto", Logging::Loggable("UDP"), "addresses", Logging::IterLoggable(localAddresses.cbegin(), localAddresses.cend()), "socketInstances", Logging::Loggable(instances), "reuseport", Logging::Loggable(g_reusePort));
}
return localAddresses.size();
}
Expand Down
11 changes: 6 additions & 5 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1891,31 +1891,32 @@ static unsigned int initDistribution(Logr::log_t log)
for (unsigned int i = 0; i < RecThreadInfo::numDistributors(); i++, threadNum++) {
auto& info = RecThreadInfo::info(threadNum);
auto& deferredAdds = info.getDeferredAdds();
count += makeUDPServerSockets(deferredAdds, log);
// The two last arguments to make{UDP,TCP}ServerSockets are used for logging purposes only, same for calls below
count += makeUDPServerSockets(deferredAdds, log, i == RecThreadInfo::numDistributors() - 1, RecThreadInfo::numDistributors());
}
}
else {
/* first thread is the handler, there is no distributor here and workers are accepting queries */
for (unsigned int i = 0; i < RecThreadInfo::numUDPWorkers(); i++, threadNum++) {
auto& info = RecThreadInfo::info(threadNum);
auto& deferredAdds = info.getDeferredAdds();
count += makeUDPServerSockets(deferredAdds, log);
count += makeUDPServerSockets(deferredAdds, log, i == RecThreadInfo::numUDPWorkers() - 1, RecThreadInfo::numUDPWorkers());
}
}
threadNum = 1 + RecThreadInfo::numDistributors() + RecThreadInfo::numUDPWorkers();
for (unsigned int i = 0; i < RecThreadInfo::numTCPWorkers(); i++, threadNum++) {
auto& info = RecThreadInfo::info(threadNum);
auto& deferredAdds = info.getDeferredAdds();
auto& tcpSockets = info.getTCPSockets();
count += makeTCPServerSockets(deferredAdds, tcpSockets, log);
count += makeTCPServerSockets(deferredAdds, tcpSockets, log, i == RecThreadInfo::numTCPWorkers() - 1, RecThreadInfo::numTCPWorkers());
}
}
else {
std::set<int> tcpSockets;
/* we don't have reuseport so we can only open one socket per
listening addr:port and everyone will listen on it */
count += makeUDPServerSockets(s_deferredUDPadds, log);
count += makeTCPServerSockets(s_deferredTCPadds, tcpSockets, log);
count += makeUDPServerSockets(s_deferredUDPadds, log, true, 1);
count += makeTCPServerSockets(s_deferredTCPadds, tcpSockets, log, true, 1);

// TCP queries are handled by TCP workers
for (unsigned int i = 0; i < RecThreadInfo::numTCPWorkers(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions pdns/recursordist/rec-main.hh
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,10 @@ bool expectProxyProtocol(const ComboAddress& from, const ComboAddress& listenAdd
void finishTCPReply(std::unique_ptr<DNSComboWriter>&, bool hadError, bool updateInFlight);
void checkFastOpenSysctl(bool active, Logr::log_t);
void checkTFOconnect(Logr::log_t);
unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets, Logr::log_t);
unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets, Logr::log_t, bool doLog, unsigned int instances);
void handleNewTCPQuestion(int fileDesc, FDMultiplexer::funcparam_t&);

unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t);
unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t, bool doLog, unsigned int instances);
string doTraceRegex(FDWrapper file, vector<string>::const_iterator begin, vector<string>::const_iterator end);
extern bool g_luaSettingsInYAML;
void startLuaConfigDelayedThreads(const LuaConfigItems& luaConfig, uint64_t generation);
Expand Down
8 changes: 5 additions & 3 deletions pdns/recursordist/rec-tcp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,8 @@ LWResult::Result arecvtcp(PacketBuffer& data, const size_t len, shared_ptr<TCPIO
return LWResult::Result::Success;
}

unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets, Logr::log_t log)
// The two last arguments to makeTCPServerSockets are used for logging purposes only
unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets, Logr::log_t log, bool doLog, unsigned int instances)
{
vector<string> localAddresses;
stringtok(localAddresses, ::arg()["local-address"], " ,");
Expand Down Expand Up @@ -1186,12 +1187,13 @@ unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tc

// we don't need to update g_listenSocketsAddresses since it doesn't work for TCP/IP:
// - fd is not that which we know here, but returned from accept()
SLOG(g_log << Logger::Info << "Listening for TCP queries on " << address.toStringWithPort() << endl,
log->info(Logr::Info, "Listening for queries", "protocol", Logging::Loggable("TCP"), "address", Logging::Loggable(address)));

#ifdef TCP_DEFER_ACCEPT
first = false;
#endif
}
if (doLog) {
log->info(Logr::Info, "Listening for queries", "protocol", Logging::Loggable("TCP"), "addresses", Logging::IterLoggable(localAddresses.cbegin(), localAddresses.cend()), "socketInstances", Logging::Loggable(instances), "reuseport", Logging::Loggable(g_reusePort));
}
return localAddresses.size();
}

0 comments on commit 4759ae2

Please sign in to comment.