From: Otto Moerbeek Date: Tue, 28 May 2024 08:36:10 +0000 (+0200) Subject: rec: add a few more fields to the protobuf messages X-Git-Tag: rec-5.1.0-beta1~17^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f5cb02af033b84c37d09d42dc5e0e2314056b0b;p=thirdparty%2Fpdns.git rec: add a few more fields to the protobuf messages Implements #13020 If/when this is merged, do not forget to update https://github.com/PowerDNS/dnsmessage/blob/master/dnsmessage.proto --- diff --git a/contrib/ProtobufLogger.py b/contrib/ProtobufLogger.py index b4dc9f3d8d..0f7c080415 100644 --- a/contrib/ProtobufLogger.py +++ b/contrib/ProtobufLogger.py @@ -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 = '' diff --git a/pdns/dnsmessage.proto b/pdns/dnsmessage.proto index e02cedb624..8f54867c03 100644 --- a/pdns/dnsmessage.proto +++ b/pdns/dnsmessage.proto @@ -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 { diff --git a/pdns/protozero.hh b/pdns/protozero.hh index 8dd49db0df..245151c8dc 100644 --- a/pdns/protozero.hh +++ b/pdns/protozero.hh @@ -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(Field::response)}; diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index ad3ad7ac61..e792140b03 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -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); } diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 8a5c015d3b..9ef1086558 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -547,6 +547,8 @@ void protobufLogQuery(LocalStateHolder& 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