]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
fix(dnsdist): Add `delay` option to `RemoteLogResponseAction`
authorPieter Lexis <pieter.lexis@powerdns.com>
Fri, 17 Oct 2025 12:02:10 +0000 (14:02 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 17 Oct 2025 13:01:27 +0000 (15:01 +0200)
This matches the behaviour of the YAML config.

pdns/dnsdistdist/dnsdist-lua-actions.cc
pdns/dnsdistdist/docs/reference/actions.rst
regression-tests.dnsdist/test_OpenTelemetryTracing.py

index 30bfd068a484faba3eb086d906c569f403bd73eb..92a90b1729a8f1cad31b053e4103f35155c53045 100644 (file)
@@ -335,7 +335,7 @@ void setupLuaActions(LuaContext& luaCtx)
     return dnsdist::actions::getRemoteLogAction(config);
   });
 
-  luaCtx.writeFunction("RemoteLogResponseAction", [](std::shared_ptr<RemoteLoggerInterface> logger, boost::optional<dnsdist::actions::ProtobufAlterResponseFunction> alterFunc, boost::optional<bool> includeCNAME, boost::optional<LuaAssociativeTable<std::string>> vars, boost::optional<LuaAssociativeTable<std::string>> metas) {
+  luaCtx.writeFunction("RemoteLogResponseAction", [](std::shared_ptr<RemoteLoggerInterface> logger, boost::optional<dnsdist::actions::ProtobufAlterResponseFunction> alterFunc, boost::optional<bool> includeCNAME, boost::optional<LuaAssociativeTable<std::string>> vars, boost::optional<LuaAssociativeTable<std::string>> metas, boost::optional<bool> delay) {
     if (logger) {
       // avoids potentially-evaluated-expression warning with clang.
       RemoteLoggerInterface& remoteLoggerRef = *logger;
@@ -364,6 +364,10 @@ void setupLuaActions(LuaContext& luaCtx)
       }
     }
 
+    if (delay) {
+      config.delay = *delay;
+    }
+
     if (!tags.empty()) {
       config.tagsToExport = std::unordered_set<std::string>();
       if (tags != "*") {
index fbc50a91149a8272e4b7960fb12f6d918a51aef4..272ef80d24ece9d2a2ebbb43e306198efbe452de 100644 (file)
@@ -488,7 +488,7 @@ The following actions exist.
   * ``ipEncryptKey=""``: str - A key, that can be generated via the :func:`makeIPCipherKey` function, to encrypt the IP address of the requestor for anonymization purposes. The encryption is done using ipcrypt for IPv4 and a 128-bit AES ECB operation for IPv6.
   * ``exportTags=""``: str - The comma-separated list of keys of internal tags to export into the ``tags`` Protocol Buffer field, as "key:value" strings. Note that a tag with an empty value will be exported as "<key>", not "<key>:". An empty string means that no internal tag will be exported. The special value ``*`` means that all tags will be exported.
 
-.. function:: RemoteLogResponseAction(remoteLogger[, alterFunction[, includeCNAME [, options [, metas]]]])
+.. function:: RemoteLogResponseAction(remoteLogger[, alterFunction[, includeCNAME [, options [, metas [, delay]]]]])
 
   .. versionchanged:: 1.4.0
     ``ipEncryptKey`` optional key added to the options table.
@@ -500,6 +500,9 @@ The following actions exist.
   .. versionchanged:: 1.9.0
     ``exportExtendedErrorsToMeta`` optional key added to the options table.
 
+  .. versionchanged:: 2.1.0
+    ``delay`` optional parameter added.
+
   Send the content of this response to a remote logger via Protocol Buffer.
   ``alterFunction`` is the same callback that receiving a :class:`DNSResponse` and a :class:`DNSDistProtoBufMessage`, that can be used to modify the Protocol Buffer content, for example for anonymization purposes.
   ``includeCNAME`` indicates whether CNAME records inside the response should be parsed and exported.
@@ -512,6 +515,7 @@ The following actions exist.
   :param bool includeCNAME: Whether or not to parse and export CNAMEs. Default false
   :param table options: A table with key: value pairs.
   :param table metas: A list of ``name``=``key`` pairs, for meta-data to be added to Protocol Buffer message.
+  :param bool delay: Delay sending the protobuf until after the DNS response has been sent to the client. Default false.
 
   Options:
 
index e309cd02ac76cc80542eff69fb31e537379277b1..512e973515094bb6cd4ac12e5ce6c96b18004b50 100644 (file)
@@ -232,6 +232,25 @@ response_rules:
         self.doTest(True)
 
 
+class TestOpenTelemetryTracingBaseDelayLua(DNSDistOpenTelemetryProtobufBaseTest):
+    _config_params = [
+        "_testServerPort",
+        "_protobufServerPort",
+    ]
+
+    _config_template = """
+newServer{address="127.0.0.1:%d"}
+rl = newRemoteLogger('127.0.0.1:%d')
+setOpenTelemetryTracing(true)
+
+addAction(AllRule(), SetTraceAction(true))
+addResponseAction(AllRule(), RemoteLogResponseAction(rl, nil, false, {}, {}, true))
+"""
+
+    def testBasic(self):
+        self.doTest(True)
+
+
 class DNSDistOpenTelemetryProtobufNoOTDataTest(DNSDistOpenTelemetryProtobufTest):
     def doTest(self):
         msg = self.sendQueryAndGetProtobuf()