]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: add a few more fields to the protobuf messages
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 28 May 2024 08:36:10 +0000 (10:36 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 28 May 2024 09:39:02 +0000 (11:39 +0200)
Implements #13020

If/when this is merged, do not forget to update https://github.com/PowerDNS/dnsmessage/blob/master/dnsmessage.proto

contrib/ProtobufLogger.py
pdns/dnsmessage.proto
pdns/protozero.hh
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-main.cc
regression-tests.recursor-dnssec/test_Protobuf.py

index b4dc9f3d8d76875933183409b83147c31a494c97..0f7c080415e423a3d0e743ea97e659b40a192035 100644 (file)
@@ -245,8 +245,21 @@ class PDNSPBConnHandler(object):
         if msg.HasField('newlyObservedDomain'):
             nod = msg.newlyObservedDomain
 
+        workerId = 'N/A'
+        if msg.HasField('workerId'):
+           workerId = str(msg.workerId)
+        pcCacheHit = 'N/A'
+        if msg.HasField('packetCacheHit'):
+           pcCacheHit = str(msg.packetCacheHit)
+
+        outgoingQs = 'N/A'
+        if msg.HasField('outgoingQueries'):
+           outgoingQs = str(msg.outgoingQueries)
+       
+
         print('[%s] %s of size %d: %s%s%s -> %s%s(%s) id: %d uuid: %s%s '
-                  'requestorid: %s deviceid: %s devicename: %s serverid: %s nod: %d' % (datestr,
+                  'requestorid: %s deviceid: %s devicename: %s serverid: %s nod: %d workerId: %s pcCacheHit: %s outgoingQueries: %s' % (datestr,
                                                     typestr,
                                                     msg.inBytes,
                                                     ipfromstr,
@@ -262,7 +275,10 @@ class PDNSPBConnHandler(object):
                                                     deviceId,
                                                     deviceName,
                                                     serveridstr,
-                                                    nod))
+                                                    nod,
+                                                    workerId,
+                                                    pcCacheHit,
+                                                    outgoingQs))
 
         for mt in msg.meta:
             values = ''
index e02cedb6240b3c0a5eca007542ccd6f2469a1fed..8f54867c03acc0f183b36d1ebdd3bc8b5f964103 100644 (file)
@@ -2,19 +2,19 @@
  * This file describes the message format used by the protobuf logging feature in PowerDNS and dnsdist.
  *
  * MIT License
- * 
+ *
  * Copyright (c) 2016-now PowerDNS.COM B.V. and its contributors.
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in all
  * copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -183,7 +183,11 @@ message PBDNSMessage {
     optional string custom = 8;                 // The name of the event for custom events
   }
   repeated Event trace = 23;
+
   optional HTTPVersion httpVersion = 24;        // HTTP version used for DNS over HTTP
+  optional uint64 workerId = 25;                // Thread id
+  optional bool packetCacheHit = 26;            // Was it a packet cache hit?
+  optional uint32 outgoingQueries = 27;         // NUmber of outgoing queries used to answer the query
 }
 
 message PBDNSMessageList {
index 8dd49db0df9a8073bac3f4fb41d5dd12dfca066a..245151c8dc15d0443cc428535cbc406c1ec38687 100644 (file)
@@ -41,7 +41,7 @@ namespace pdns {
       enum class MetaField : protozero::pbf_tag_type { key = 1, value = 2 };
       enum class Event : protozero::pbf_tag_type { ts = 1, event = 2, start = 3, boolVal = 4, intVal = 5, stringVal = 6, bytesVal = 7, custom = 8 };
       enum class MessageType : int32_t { DNSQueryType = 1, DNSResponseType = 2, DNSOutgoingQueryType = 3, DNSIncomingResponseType = 4 };
-      enum class Field : protozero::pbf_tag_type { type = 1, messageId = 2, serverIdentity = 3, socketFamily = 4, socketProtocol = 5, from = 6, to = 7, inBytes = 8, timeSec = 9, timeUsec = 10, id = 11, question = 12, response = 13, originalRequestorSubnet = 14, requestorId = 15, initialRequestId = 16, deviceId = 17, newlyObservedDomain = 18, deviceName = 19, fromPort = 20, toPort = 21, meta = 22, trace = 23, httpVersion = 24 };
+      enum class Field : protozero::pbf_tag_type { type = 1, messageId = 2, serverIdentity = 3, socketFamily = 4, socketProtocol = 5, from = 6, to = 7, inBytes = 8, timeSec = 9, timeUsec = 10, id = 11, question = 12, response = 13, originalRequestorSubnet = 14, requestorId = 15, initialRequestId = 16, deviceId = 17, newlyObservedDomain = 18, deviceName = 19, fromPort = 20, toPort = 21, meta = 22, trace = 23, httpVersion = 24, workerId = 25, packetCacheHit = 26, outgoingQueries = 27};
       enum class QuestionField : protozero::pbf_tag_type { qName = 1, qType = 2, qClass = 3 };
       enum class ResponseField : protozero::pbf_tag_type { rcode = 1, rrs = 2, appliedPolicy = 3, tags = 4, queryTimeSec = 5, queryTimeUsec = 6, appliedPolicyType = 7, appliedPolicyTrigger = 8, appliedPolicyHit = 9, appliedPolicyKind = 10, validationState = 11 };
       enum class RRField : protozero::pbf_tag_type { name = 1, type = 2, class_ = 3, ttl = 4, rdata = 5, udr = 6 };
@@ -191,6 +191,21 @@ namespace pdns {
         add_uint32(d_message, Field::toPort, port);
       }
 
+      void setWorkerId(uint64_t wid)
+      {
+        add_uint64(d_message, Field::workerId, wid);
+      }
+
+      void setPacketCacheHit(bool hit)
+      {
+        add_bool(d_message, Field::packetCacheHit, hit);
+      }
+
+      void setOutgoingQueries(uint32_t num)
+      {
+        add_uint32(d_message, Field::outgoingQueries, num);
+      }
+
       void startResponse()
       {
         d_response = protozero::pbf_writer{d_message, static_cast<protozero::pbf_tag_type>(Field::response)};
index ad3ad7ac61430264c788a46fd3d0d441c3a691ba..e792140b038ec755dcf778a5f14ce705dbea75fb 100644 (file)
@@ -1823,7 +1823,9 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       pbMessage.setDeviceName(dnsQuestion.deviceName);
       pbMessage.setToPort(comboWriter->d_destination.getPort());
       pbMessage.addPolicyTags(comboWriter->d_gettagPolicyTags);
-
+      pbMessage.setWorkerId(RecThreadInfo::id());
+      pbMessage.setPacketCacheHit(false);
+      pbMessage.setOutgoingQueries(resolver.d_outqueries);
       for (const auto& metaValue : dnsQuestion.meta) {
         pbMessage.setMeta(metaValue.first, metaValue.second.stringVal, metaValue.second.intVal);
       }
index 8a5c015d3be63d0399e6e0607a067997de11a209..9ef10865587ba1b6d9ab0f8cf70782b198d95cba 100644 (file)
@@ -547,6 +547,8 @@ void protobufLogQuery(LocalStateHolder<LuaConfigItems>& luaconfsLocal, const boo
   msg.setRequestorId(requestorId);
   msg.setDeviceId(deviceId);
   msg.setDeviceName(deviceName);
+  msg.setWorkerId(RecThreadInfo::id());
+  // For queries, packetCacheHit and outgoingQueries are not relevant
 
   if (!policyTags.empty()) {
     msg.addPolicyTags(policyTags);
@@ -625,6 +627,11 @@ void protobufLogResponse(const struct dnsheader* header, LocalStateHolder<LuaCon
   pbMessage.setDeviceId(deviceId);
   pbMessage.setDeviceName(deviceName);
   pbMessage.setToPort(destination.getPort());
+  pbMessage.setWorkerId(RecThreadInfo::id());
+  // this method is only used for PC cache hits
+  pbMessage.setPacketCacheHit(true);
+  // we do not set outgoingQueries, it is not relevant for PC cache hits
+
   for (const auto& metaItem : meta) {
     pbMessage.setMeta(metaItem.first, metaItem.second.stringVal, metaItem.second.intVal);
   }
index a3cf75404b4c766978c894b493dcf1a026679f8b..b83d9c95a07367c563e0db371913210d4d6933a9 100644 (file)
@@ -190,6 +190,7 @@ class TestRecursorProtobuf(RecursorTest):
         # because it doesn't keep the information around.
         self.assertTrue(msg.HasField('to'))
         self.assertEqual(socket.inet_ntop(socket.AF_INET, msg.to), to)
+        self.assertTrue(msg.HasField('workerId'))
         self.assertTrue(msg.HasField('question'))
         self.assertTrue(msg.question.HasField('qClass'))
         self.assertEqual(msg.question.qClass, qclass)
@@ -201,6 +202,8 @@ class TestRecursorProtobuf(RecursorTest):
     def checkProtobufResponse(self, msg, protocol, response, initiator='127.0.0.1', receivedSize=None, vstate=dnsmessage_pb2.PBDNSMessage.VState.Indeterminate):
         self.assertEqual(msg.type, dnsmessage_pb2.PBDNSMessage.DNSResponseType)
         self.checkProtobufBase(msg, protocol, response, initiator, receivedSize=receivedSize)
+        self.assertTrue(msg.HasField('workerId'))
+        self.assertTrue(msg.HasField('packetCacheHit'))
         self.assertTrue(msg.HasField('response'))
         self.assertTrue(msg.response.HasField('queryTimeSec'))
         self.assertTrue(msg.response.HasField('validationState'))