]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add %transport::>connection_id logformat code (#546)
authorChristos Tsantilas <christos@chtsanti.net>
Sun, 26 Jan 2020 20:13:55 +0000 (20:13 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 27 Jan 2020 13:58:02 +0000 (13:58 +0000)
Knowing client transport connection ID can be very helpful in triage,
especially when dealing with multiple requests associated with a
problematic connection (e.g., two access log records associated with a
single TLS connection bumping failure).

The "transport" namespace was added in hope to reduce confusion when/if
other connection_id %codes are added. The shorter and more familiar
"tcp::" namespace was rejected because we want configurations using the
new %code to continue to work well after Squid gains HTTP/3 support, and
HTTP/3 uses UDP for transport connections. Other UDP-based protocols may
have similar "connection" concepts.

This is a Measurement Factory project.

src/cf.data.pre
src/comm/Connection.cc
src/comm/Connection.h
src/format/ByteCode.h
src/format/Format.cc
src/format/Token.cc
src/tests/stub_libcomm.cc

index 615895e2434460086906569311ba2c70dd330dd4..ab485d604048c8a88ce1df88fd2eb4cb6f73a96b 100644 (file)
@@ -4563,6 +4563,19 @@ DOC_START
                >qos    Client connection TOS/DSCP value set by Squid
                >nfmark Client connection netfilter packet MARK set by Squid
 
+               transport::>connection_id Identifies a transport connection
+                       accepted by Squid (e.g., a connection carrying the
+                       logged HTTP request). Currently, Squid only supports
+                       TCP transport connections.
+
+                       The logged identifier is an unsigned integer. These
+                       IDs are guaranteed to monotonically increase within a
+                       single worker process lifetime, with higher values
+                       corresponding to connections that were accepted later.
+                       Many IDs are skipped (i.e. never logged). Concurrent
+                       workers and restarted workers use similar, partially
+                       overlapping sequences of IDs.
+
                la      Local listening IP address the client connection was connected to.
                lp      Local listening port number the client connection was connected to.
 
index 3e36be06e3662a4f75a7a16c3369de36f9016333..1fb1351328628f9950fc44b1d23cca205b9f9f1a 100644 (file)
@@ -19,7 +19,7 @@
 #include "SquidTime.h"
 #include <ostream>
 
-InstanceIdDefinitions(Comm::Connection, "conn");
+InstanceIdDefinitions(Comm::Connection, "conn", uint64_t);
 
 class CachePeer;
 bool
index d5d8c55a9b87147bc9f64499f9ef01010e100c69..b02f23ef109d8356ddd1876f791ef9a43ae72f85 100644 (file)
@@ -175,7 +175,7 @@ public:
     Eui::Eui64 remoteEui64;
 #endif
 
-    InstanceId<Connection> id;
+    InstanceId<Connection, uint64_t> id;
 
 private:
     /** cache_peer data object (if any) */
index 088ac0db3ea0e279b0a4eedb35203ed466339956..a519867e049e3fb7b1e8506b6d17c1ee0d69890c 100644 (file)
@@ -46,6 +46,8 @@ typedef enum {
     LFT_CLIENT_LOCAL_TOS,
     LFT_CLIENT_LOCAL_NFMARK,
 
+    LFT_TRANSPORT_CLIENT_CONNECTION_ID,
+
     LFT_CLIENT_HANDSHAKE,
 
     /* client connection local squid.conf details */
index 2152f6f36c98745440db4f95f7f78e6e35cbb957..76f6011f01115eb7758f5f20be571fe6902999cd 100644 (file)
@@ -508,6 +508,13 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS
             }
             break;
 
+        case LFT_TRANSPORT_CLIENT_CONNECTION_ID:
+            if (al->tcpClient) {
+                outUint64 = al->tcpClient->id.value;
+                doUint64 = true;
+            }
+            break;
+
         case LFT_CLIENT_LOCAL_NFMARK:
             if (al->tcpClient) {
                 sb.appendf("0x%x", al->tcpClient->nfmark);
index 2be31d51e8df63ebea0c07c1d592b28e04f72137..9175bf776af6e1d49418dcf2db039c67ac118a1e 100644 (file)
@@ -183,6 +183,10 @@ static TokenTableEntry TokenTableProxyProtocol[] = {
     TokenTableEntry(">h", LFT_PROXY_PROTOCOL_RECEIVED_HEADER),
 };
 
+static TokenTableEntry TokenTableTransport[] = {
+    TokenTableEntry(">connection_id", LFT_TRANSPORT_CLIENT_CONNECTION_ID),
+};
+
 #if USE_ADAPTATION
 static TokenTableEntry TokenTableAdapt[] = {
     TokenTableEntry("all_trs", LFT_ADAPTATION_ALL_XACT_TIMES),
@@ -259,6 +263,7 @@ Format::Token::Init()
     TheConfig.registerTokens(SBuf("ssl"),::Format::TokenTableSsl);
 #endif
     TheConfig.registerTokens(SBuf("proxy_protocol"), ::Format::TokenTableProxyProtocol);
+    TheConfig.registerTokens(SBuf("transport"), ::Format::TokenTableTransport);
 }
 
 /// Scans a token table to see if the next token exists there
index 4e3edbc09225159c5adfaf3a7331451ee7488525..6c921b3727dbebce7f6650fb769293281f0a1196 100644 (file)
@@ -28,7 +28,7 @@ CachePeer * Comm::Connection::getPeer() const STUB_RETVAL(NULL)
 void Comm::Connection::setPeer(CachePeer * p) STUB
 ScopedId Comm::Connection::codeContextGist() const STUB_RETVAL(id.detach())
 std::ostream &Comm::Connection::detailCodeContext(std::ostream &os) const STUB_RETVAL(os)
-InstanceIdDefinitions(Comm::Connection, "conn");
+InstanceIdDefinitions(Comm::Connection, "conn", uint64_t);
 
 #include "comm/ConnOpener.h"
 CBDATA_NAMESPACED_CLASS_INIT(Comm, ConnOpener);