]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a function to know how many TLS sessions are currently cached 10997/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 17 Nov 2021 14:53:27 +0000 (15:53 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 17 Nov 2021 14:53:27 +0000 (15:53 +0100)
Also dump the number of cached (active and idle) outgoing connections
when requested.

pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc
pdns/dnsdist-tcp.cc
pdns/dnsdistdist/dnsdist-nghttp2.cc
pdns/dnsdistdist/dnsdist-session-cache.cc
pdns/dnsdistdist/dnsdist-session-cache.hh
pdns/dnsdistdist/docs/reference/config.rst

index 44e33cc027dc6ad5996f8ad01992c78f415ef39d..f9e47106d0a7c73b82acd799babc25e7b686af21 100644 (file)
@@ -457,6 +457,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "getDNSCryptBindCount", true, "", "returns the number of DNSCrypt listeners" },
   { "getDOHFrontend", true, "n", "returns the DOH frontend with index n" },
   { "getDOHFrontendCount", true, "", "returns the number of DoH listeners" },
+  { "getOutgoingTLSSessionCacheSize", true, "", "returns the number of TLS sessions (for outgoing connections) currently cached" },
   { "getPool", true, "name", "return the pool named `name`, or \"\" for the default pool" },
   { "getPoolServers", true, "pool", "return servers part of this pool" },
   { "getQueryCounters", true, "[max=10]", "show current buffer of query counters, limited by 'max' if provided" },
index fde21a9fccb47b5f95b6d308d060f91e487e40bb..76746b3f3f0fa9c4e3d621d61a3ce10b2cdb6ef6 100644 (file)
@@ -1346,6 +1346,11 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     TLSSessionCache::setSessionValidity(validity);
   });
 
+  luaCtx.writeFunction("getOutgoingTLSSessionCacheSize", []() {
+    setLuaNoSideEffect();
+    return g_sessionCache.getSize();
+  });
+
   luaCtx.writeFunction("setCacheCleaningDelay", [](uint64_t delay) {
     checkParameterBound("setCacheCleaningDelay", delay, std::numeric_limits<uint32_t>::max());
     g_cacheCleaningDelay = delay;
index 5d3a422a8e93e0eecad0f3efd818b5911bcd96a7..f181d751a657d5cc3df9e0041d43eaa274efb743 100644 (file)
@@ -1277,6 +1277,7 @@ static void tcpClientThread(int pipefd, int crossProtocolQueriesPipeFD, int cros
                   errlog(" - Worker thread pipe");
                 }
               });
+              errlog("The TCP/DoT client cache has %d active and %d idle outgoing connections cached", t_downstreamTCPConnectionsManager.getActiveCount(), t_downstreamTCPConnectionsManager.getIdleCount());
             }
           }
         }
index 5df7f337c804bf44c43d47fe19d21b403c6bf98b..9d5781e3329c43fc0ded345e48dd65731478e649 100644 (file)
@@ -924,6 +924,7 @@ static void dohClientThread(int crossProtocolPipeFD)
                   errlog(" - Worker thread pipe");
                 }
               });
+              errlog("The DoH client cache has %d active and %d idle outgoing connections cached", t_downstreamDoHConnectionsManager.getActiveCount(), t_downstreamDoHConnectionsManager.getIdleCount());
             }
           }
         }
index b227efd2c6b61498022a70bc1f02ed9dc4cf8151..42ba272ed4b75885148ef7546c17de8da8fe8d92 100644 (file)
@@ -78,3 +78,13 @@ std::unique_ptr<TLSSession> TLSSessionCache::getSession(const boost::uuids::uuid
 
   return value;
 }
+
+size_t TLSSessionCache::getSize()
+{
+  size_t count = 0;
+  auto data = d_data.lock();
+  for (const auto& backend : data->d_sessions) {
+    count += backend.second.d_sessions.size();
+  }
+  return count;
+}
index 47d76bc47807dba7f2848218574135f875743c08..1881fb1af5e5bd6f433545b818d3a13a8788c861 100644 (file)
@@ -53,6 +53,8 @@ public:
     s_maxSessionsPerBackend = max;
   }
 
+  size_t getSize();
+
 private:
   static time_t s_cleanupDelay;
   static time_t s_sessionValidity;
index b2386707f029cfa1a40cfbe6ab88736dd232dee6..7d93539b06d94694d51a33582ae6297a096ff4c0 100644 (file)
@@ -943,6 +943,12 @@ Status, Statistics and More
 
   Return the number of DOHFrontend binds.
 
+.. function:: getOutgoingTLSSessionCacheSize()
+
+  .. versionadded:: 1.7.0
+
+  Return the number of TLS sessions (for outgoing connections) currently cached.
+
 .. function:: getTLSContext(idx)
 
   Return the TLSContext object for the context of index ``idx``.