]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add downstream TLS session resumption metric
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 5 May 2021 08:40:31 +0000 (10:40 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Aug 2021 14:30:27 +0000 (16:30 +0200)
pdns/dnsdist-carbon.cc
pdns/dnsdist-lua-inspection.cc
pdns/dnsdist-web.cc
pdns/dnsdist.hh
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
regression-tests.dnsdist/test_API.py

index afbe27decd2ffd9712659fb27d28c288107e411e..4f3859aeeaa3e671a23a97987c9499ce06435cea 100644 (file)
@@ -107,6 +107,7 @@ void carbonDumpThread()
             str<<base<<"tcpmaxconcurrentconnections" << ' '<< state->tcpMaxConcurrentConnections.load() << " " << now << "\r\n";
             str<<base<<"tcpnewconnections" << ' '<< state->tcpNewConnections.load() << " " << now << "\r\n";
             str<<base<<"tcpreusedconnections" << ' '<< state->tcpReusedConnections.load() << " " << now << "\r\n";
+            str<<base<<"tlsresumptions" << ' '<< state->tlsResumptions.load() << " " << now << "\r\n";
             str<<base<<"tcpavgqueriesperconnection" << ' '<< state->tcpAvgQueriesPerConnection.load() << " " << now << "\r\n";
             str<<base<<"tcpavgconnectionduration" << ' '<< state->tcpAvgConnectionDuration.load() << " " << now << "\r\n";
           }
index 4c9024c8bbe690674f080bbf8db95ee48bbb0b39..1853e0fc0fc99842cd30f48e2e22f5916e620062 100644 (file)
@@ -610,13 +610,13 @@ void setupLuaInspection(LuaContext& luaCtx)
       ret << endl;
 
       ret << "Backends:" << endl;
-      fmt = boost::format("%-3d %-20.20s %-20.20s %-20d %-20d %-25d %-20d %-20d %-20d %-20d %-20d %-20d %-20d %-20f %-20f");
-      ret << (fmt % "#" % "Name" % "Address" % "Connections" % " Max concurrent conn" % "Died sending query" % "Died reading response" % "Gave up" % "Read timeouts" % "Write timeouts" % "Connect timeouts" % "Total connections" % "Reused connections" % "Avg queries/conn" % "Avg duration") << endl;
+      fmt = boost::format("%-3d %-20.20s %-20.20s %-20d %-20d %-25d %-20d %-20d %-20d %-20d %-20d %-20d %-20d %-20d %-20f %-20f");
+      ret << (fmt % "#" % "Name" % "Address" % "Connections" % " Max concurrent conn" % "Died sending query" % "Died reading response" % "Gave up" % "Read timeouts" % "Write timeouts" % "Connect timeouts" % "Total connections" % "Reused connections" % "TLS resumptions" % "Avg queries/conn" % "Avg duration") << endl;
 
       auto states = g_dstates.getLocal();
       counter = 0;
       for(const auto& s : *states) {
-        ret << (fmt % counter % s->getName() % s->remote.toStringWithPort() % s->tcpCurrentConnections % s->tcpMaxConcurrentConnections % s->tcpDiedSendingQuery % s->tcpDiedReadingResponse % s->tcpGaveUp % s->tcpReadTimeouts % s->tcpWriteTimeouts % s->tcpConnectTimeouts % s->tcpNewConnections % s->tcpReusedConnections % s->tcpAvgQueriesPerConnection % s->tcpAvgConnectionDuration) << endl;
+        ret << (fmt % counter % s->getName() % s->remote.toStringWithPort() % s->tcpCurrentConnections % s->tcpMaxConcurrentConnections % s->tcpDiedSendingQuery % s->tcpDiedReadingResponse % s->tcpGaveUp % s->tcpReadTimeouts % s->tcpWriteTimeouts % s->tcpConnectTimeouts % s->tcpNewConnections % s->tcpReusedConnections % s->tlsResumptions % s->tcpAvgQueriesPerConnection % s->tcpAvgConnectionDuration) << endl;
         ++counter;
       }
 
index 547908ff4b930e6103f686fb075c801961ec849b..051df2a5872e28195eb1af05504eea9e174b35bb 100644 (file)
@@ -487,6 +487,8 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp)
   output << "# TYPE " << statesbase << "tcpavgqueriesperconn "        << "gauge"                                                             << "\n";
   output << "# HELP " << statesbase << "tcpavgconnduration "          << "The average duration of a TCP connection (ms)"                     << "\n";
   output << "# TYPE " << statesbase << "tcpavgconnduration "          << "gauge"                                                             << "\n";
+  output << "# HELP " << statesbase << "tlsresumptions "              << "The number of times a TLS session has been resumed"                << "\n";
+  output << "# TYPE " << statesbase << "tlsersumptions "              << "counter"                                                           << "\n";
 
   for (const auto& state : *states) {
     string serverName;
@@ -523,6 +525,7 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp)
     output << statesbase << "tcpreusedconnections"         << label << " " << state->tcpReusedConnections        << "\n";
     output << statesbase << "tcpavgqueriesperconn"         << label << " " << state->tcpAvgQueriesPerConnection  << "\n";
     output << statesbase << "tcpavgconnduration"           << label << " " << state->tcpAvgConnectionDuration    << "\n";
+    output << statesbase << "tlsresumptions"               << label << " " << state->tlsResumptions              << "\n";
   }
 
   const string frontsbase = "dnsdist_frontend_";
@@ -916,6 +919,7 @@ static void addServerToJSON(Json::array& servers, int id, const std::shared_ptr<
     {"tcpReusedConnections", (double)a->tcpReusedConnections},
     {"tcpAvgQueriesPerConnection", (double)a->tcpAvgQueriesPerConnection},
     {"tcpAvgConnectionDuration", (double)a->tcpAvgConnectionDuration},
+    {"tlsResumptions", (double)a->tlsResumptions},
     {"dropRate", (double)a->dropRate}
   };
 
index 8a9565c0acd82cd819d8539c4b13aad6b2ce0d91..fdc083baf04a0572175b428b7a64744bdfc9fdee 100644 (file)
@@ -698,6 +698,7 @@ struct DownstreamState
   stat_t tcpMaxConcurrentConnections{0};
   stat_t tcpReusedConnections{0};
   stat_t tcpNewConnections{0};
+  stat_t tlsResumptions{0};
   pdns::stat_t_trait<double> tcpAvgQueriesPerConnection{0.0};
   /* in ms */
   pdns::stat_t_trait<double> tcpAvgConnectionDuration{0.0};
index f07c6aec444510c64d6a2228ec35c1efff66151f..56ab9b21a2b0871188723e17a512a1c60edf0851 100644 (file)
@@ -13,6 +13,9 @@ TCPConnectionToBackend::~TCPConnectionToBackend()
     gettimeofday(&now, nullptr);
 
     if (d_handler->isTLS()) {
+      if (d_handler->hasTLSSessionBeenResumed()) {
+        ++d_ds->tlsResumptions;
+      }
       cerr<<"Closing TLS connection, resumption was "<<d_handler->hasTLSSessionBeenResumed()<<endl;
       auto session = d_handler->getTLSSession();
       if (session) {
@@ -328,6 +331,9 @@ bool TCPConnectionToBackend::reconnect()
   if (d_handler) {
     DEBUGLOG("closing socket "<<d_handler->getDescriptor());
     if (d_handler->isTLS()) {
+      if (d_handler->hasTLSSessionBeenResumed()) {
+        ++d_ds->tlsResumptions;
+      }
       cerr<<"is TLS, getting a session"<<endl;
       tlsSession = d_handler->getTLSSession();
     }
index ff91b18fe2bb0e4250f31eb591e59a2a40191c95..76d13f26e93ffcd078479ea01f01db459108a1c2 100644 (file)
@@ -110,7 +110,7 @@ class TestAPIBasics(DNSDistTest):
                         'reuseds', 'state', 'address', 'pools', 'qps', 'queries', 'order', 'sendErrors',
                         'dropRate', 'responses', 'tcpDiedSendingQuery', 'tcpDiedReadingResponse',
                         'tcpGaveUp', 'tcpReadTimeouts', 'tcpWriteTimeouts', 'tcpCurrentConnections',
-                        'tcpNewConnections', 'tcpReusedConnections', 'tcpAvgQueriesPerConnection',
+                        'tcpNewConnections', 'tcpReusedConnections', 'tlsResumptions', 'tcpAvgQueriesPerConnection',
                         'tcpAvgConnectionDuration']:
                 self.assertIn(key, server)