]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Allow for a custom eventtype, with a user-specified name
authorOtto <otto.moerbeek@open-xchange.com>
Wed, 15 Sep 2021 09:02:20 +0000 (11:02 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 13 Oct 2021 12:33:17 +0000 (14:33 +0200)
contrib/ProtobufLogger.py
pdns/dnsmessage.proto
pdns/protozero.hh
pdns/recursordist/rec-eventtrace.cc
pdns/recursordist/rec-eventtrace.hh
pdns/recursordist/rec-protozero.cc

index 0b6a1a52b528ca3c519857cae9b7a37a1aa865d0..36b361bfdae45aedf3771349e026222a81584d20 100644 (file)
@@ -107,7 +107,10 @@ class PDNSPBConnHandler(object):
         if message.trace:
             print("- Event Trace:")
             for event in message.trace:
-                ev = self.getEventAsString(event.event) + '(' + str(event.ts)
+                ev = self.getEventAsString(event.event)
+                if event.event == dnsmessage_pb2.PBDNSMessage.CustomEvent and event.HasField('custom'):
+                    ev += ":" + event.custom
+                ev += '(' + str(event.ts)
                 valstr = ''
                 if event.HasField('boolVal'):
                       valstr = str(event.boolVal)
index a9fd1f07309272d04b3161146490b34dc79462f2..f37a8442bf1ea47d385437d6df3920fd65683249 100644 (file)
@@ -129,6 +129,7 @@ message PBDNSMessage {
 
   // The well known EventTrace event numbers
   enum EventType {
+    CustomEvent = 0;                            // A custom event
     RecRecv = 1;                                // A request was received by the recursor process
     PCacheCheck = 2;                            // A packet cache check was initiated or completed; value: bool cacheHit
     SyncRes = 3;                                // Syncres main function has started or completed; value: int rcode
@@ -152,6 +153,7 @@ message PBDNSMessage {
     optional int64 intVal = 5;
     optional string stringVal = 6;
     optional bytes bytesVal = 7;
+    optional string custom = 8;                 // The name of the event for custom events
   }
   repeated Event trace = 23;
 }
index 665565322f1860140f279926ffd72cb06c75eaeb..c8536dc6d6e9d91a11b8b1e6d34292448c1ffd06 100644 (file)
@@ -35,7 +35,7 @@ namespace pdns {
 
       enum class MetaValueField : protozero::pbf_tag_type { stringVal = 1, intVal = 2 };
       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 };
+      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 };
       enum class QuestionField : protozero::pbf_tag_type { qName = 1, qType = 2, qClass = 3 };
index c2d04c46abd151a399ac8802a1c15bf20987b9d6..040e1629b35baae7beef74330d8ed72eaef9517e 100644 (file)
@@ -27,6 +27,7 @@
   }
 
 const std::unordered_map<RecEventTrace::EventType, std::string> RecEventTrace::s_eventNames = {
+  NameEntry(CustomEvent),
   NameEntry(RecRecv),
   NameEntry(PCacheCheck),
   NameEntry(SyncRes),
index fed756dc66d6cd1a807625c5bc1b801039c72d2f..701cad494faa4f922615a63ab6f72db586d174ed 100644 (file)
@@ -37,6 +37,7 @@ public:
   enum EventType : uint8_t
   {
     // Don't forget to add a new entry to the table in the .cc file!
+    CustomEvent = 0,
     RecRecv = 1,
     PCacheCheck = 2,
     SyncRes = 3,
@@ -120,7 +121,12 @@ public:
       d_value(v), d_ts(ts), d_event(e), d_start(start)
     {
     }
+    Entry(Value_t& v, const std::string& custom, bool start, int64_t ts) :
+      d_value(v), d_custom(custom), d_ts(ts), d_event(CustomEvent), d_start(start)
+    {
+    }
     Value_t d_value;
+    std::string d_custom;
     int64_t d_ts;
     EventType d_event;
     bool d_start;
@@ -131,7 +137,12 @@ public:
       if (!v.empty()) {
         v = "," + v;
       }
-      return RecEventTrace::toString(d_event) + "(" + std::to_string(d_ts) + v + (d_start ? ")" : ",done)");
+      std::string name = RecEventTrace::toString(d_event);
+      if (d_event == EventType::CustomEvent) {
+        name += ":" + d_custom;
+      }
+
+      return name + "(" + std::to_string(d_ts) + v + (d_start ? ")" : ",done)");
     }
   };
 
@@ -146,7 +157,8 @@ public:
     return d_status == Enabled;
   }
 
-  void add(EventType e, Value_t v, bool start)
+  template <class E>
+  void add(E e, Value_t v, bool start)
   {
     assert(d_status != Invalid);
     if (d_status == Disabled) {
@@ -159,24 +171,27 @@ public:
     d_events.emplace_back(v, e, start, stamp);
   }
 
-  void add(EventType e)
+  template <class E>
+  void add(E e)
   {
     add(e, Value_t(std::nullopt), true);
   }
 
   // We store uint32 in an int64_t
-  void add(EventType e, uint32_t v, bool start)
+  template <class E>
+  void add(E e, uint32_t v, bool start)
   {
     add(e, static_cast<int64_t>(v), start);
   }
   // We store int32 in an int64_t
-  void add(EventType e, int32_t v, bool start)
+  template <class E>
+  void add(E e, int32_t v, bool start)
   {
     add(e, static_cast<int64_t>(v), start);
   }
 
-  template <class T>
-  void add(EventType e, T v, bool start)
+  template <class E, class T>
+  void add(E e, T v, bool start)
   {
     add(e, Value_t(v), start);
   }
index 7a153ea74ca3556947320f732d9660086ae7ca5c..375d80b203c335c15fc51710408de8337b483ab5 100644 (file)
@@ -135,5 +135,8 @@ void pdns::ProtoZero::RecMessage::addEvents(const RecEventTrace& trace)
       const PacketBuffer& p = std::get<PacketBuffer>(v);
       pbf_trace.add_bytes(static_cast<protozero::pbf_tag_type>(Event::bytesVal), reinterpret_cast<const char*>(p.data()), p.size());
     }
+    if (!t.d_custom.empty()) {
+      pbf_trace.add_string(static_cast<protozero::pbf_tag_type>(Event::custom), t.d_custom);
+    }
   }
 }