From: Pieter Lexis Date: Fri, 17 Oct 2025 12:02:10 +0000 (+0200) Subject: fix(dnsdist): Add `delay` option to `RemoteLogResponseAction` X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=34615610bfbfc07ce670f74ab5269fe4ffe65d10;p=thirdparty%2Fpdns.git fix(dnsdist): Add `delay` option to `RemoteLogResponseAction` This matches the behaviour of the YAML config. --- diff --git a/pdns/dnsdistdist/dnsdist-lua-actions.cc b/pdns/dnsdistdist/dnsdist-lua-actions.cc index 30bfd068a4..92a90b1729 100644 --- a/pdns/dnsdistdist/dnsdist-lua-actions.cc +++ b/pdns/dnsdistdist/dnsdist-lua-actions.cc @@ -335,7 +335,7 @@ void setupLuaActions(LuaContext& luaCtx) return dnsdist::actions::getRemoteLogAction(config); }); - luaCtx.writeFunction("RemoteLogResponseAction", [](std::shared_ptr logger, boost::optional alterFunc, boost::optional includeCNAME, boost::optional> vars, boost::optional> metas) { + luaCtx.writeFunction("RemoteLogResponseAction", [](std::shared_ptr logger, boost::optional alterFunc, boost::optional includeCNAME, boost::optional> vars, boost::optional> metas, boost::optional 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(); if (tags != "*") { diff --git a/pdns/dnsdistdist/docs/reference/actions.rst b/pdns/dnsdistdist/docs/reference/actions.rst index fbc50a9114..272ef80d24 100644 --- a/pdns/dnsdistdist/docs/reference/actions.rst +++ b/pdns/dnsdistdist/docs/reference/actions.rst @@ -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 "", not ":". 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: diff --git a/regression-tests.dnsdist/test_OpenTelemetryTracing.py b/regression-tests.dnsdist/test_OpenTelemetryTracing.py index e309cd02ac..512e973515 100644 --- a/regression-tests.dnsdist/test_OpenTelemetryTracing.py +++ b/regression-tests.dnsdist/test_OpenTelemetryTracing.py @@ -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()