From: Remi Gacogne Date: Mon, 19 Jan 2026 11:24:04 +0000 (+0100) Subject: dnsdist: Enable structured logging by default X-Git-Tag: rec-5.4.0-beta1~33^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba030fb8b020a1126e3b8e30f1249ce4c6878f69;p=thirdparty%2Fpdns.git dnsdist: Enable structured logging by default Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist-configuration.hh b/pdns/dnsdistdist/dnsdist-configuration.hh index 9fc3987bbf..eefdcf308f 100644 --- a/pdns/dnsdistdist/dnsdist-configuration.hh +++ b/pdns/dnsdistdist/dnsdist-configuration.hh @@ -116,7 +116,7 @@ struct ImmutableConfiguration bool d_ringsRecordResponses{true}; bool d_snmpEnabled{false}; bool d_snmpTrapsEnabled{false}; - bool d_structuredLogging{false}; + bool d_structuredLogging{true}; bool d_structuredLoggingUseServerID{false}; }; diff --git a/pdns/dnsdistdist/dnsdist-settings-definitions.yml b/pdns/dnsdistdist/dnsdist-settings-definitions.yml index cd1e1b68ab..fc65b77751 100644 --- a/pdns/dnsdistdist/dnsdist-settings-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-settings-definitions.yml @@ -1777,7 +1777,7 @@ structured_logging: parameters: - name: "enabled" type: "bool" - default: "false" + default: "true" description: | Set whether log messages should be in structured-logging format." changes: diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 5a7f41636c..6e773d4816 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -2968,7 +2968,7 @@ struct CommandLineParameters bool checkConfig{false}; bool beClient{false}; bool beSupervised{false}; - bool useStructuredLogging{false}; + bool useStructuredLogging{true}; }; static void usage() @@ -3001,7 +3001,7 @@ static void usage() cout << "--disable-syslog Don't log to syslog, only to stdout\n"; cout << " (use with e.g. systemd)\n"; cout << "--log-timestamps Prepend timestamps to messages logged to stdout\n"; - cout << "--structured-logging Enable structured logging\n"; + cout << "--structured-logging true|false Whether to enable structured logging\n"; cout << "--structured-logging-backend BACKEND The backend to use when structured logging is enabled\n"; cout << " Supported values are 'default', 'json' and 'systemd-journal'\n"; cout << "-u,--uid uid Change the process user ID after binding sockets\n"; @@ -3194,7 +3194,7 @@ static void parseParameters(int argc, char** argv, CommandLineParameters& cmdLin {"local", required_argument, nullptr, 'l'}, {"log-timestamps", no_argument, nullptr, 4}, {"setkey", required_argument, nullptr, 'k'}, - {"structured-logging", no_argument, nullptr, 's'}, + {"structured-logging", required_argument, nullptr, 's'}, {"structured-logging-backend", required_argument, nullptr, 5}, {"supervised", no_argument, nullptr, 3}, {"uid", required_argument, nullptr, 'u'}, @@ -3273,7 +3273,7 @@ static void parseParameters(int argc, char** argv, CommandLineParameters& cmdLin cmdLine.locals.push_back(boost::trim_copy(string(optarg))); break; case 's': - cmdLine.useStructuredLogging = true; + cmdLine.useStructuredLogging = (boost::to_lower_copy(std::string(optarg)) == "true"); break; case 'u': cmdLine.uid = optarg; diff --git a/pdns/dnsdistdist/docs/manpages/dnsdist.1.rst b/pdns/dnsdistdist/docs/manpages/dnsdist.1.rst index 59164abb3b..7221ce5bed 100644 --- a/pdns/dnsdistdist/docs/manpages/dnsdist.1.rst +++ b/pdns/dnsdistdist/docs/manpages/dnsdist.1.rst @@ -70,7 +70,7 @@ Options --disable-syslog Disable logging to syslog. Use this when running inside a supervisor that handles logging (like systemd). --log-timestamps Prepend timestamps to messages logged to standard out. ---structured-logging Enable structured logging. +--structured-logging Whether to enable structured logging. --structured-logging-backend The backend to use when structured logging is enabled. Supported values are 'default', 'json' and 'systemd-journal'. -u, --uid Change the process user to *uid* after binding sockets. *uid* can be diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 793e751e67..b2bf9e5ebd 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -1406,8 +1406,9 @@ Status, Statistics and More The ``backend`` option has been added. The ``setInstanceFromServerID`` option has been added The ``levelPrefix`` option has no longer any effect because it was confusing. The log level is now always logged as ``level`` and the syslog priority, if any, as ``priority`` in all backends except the default one where it is named ``prio`` + Structured logging is now enabled by default. - Set whether log messages should be in structured-logging format. This is turned off by default. See :doc:`../advanced/structured-logging-dictionary` for more details. + Set whether log messages should be in structured-logging format. This is enabled by default since 2.1.0. See :doc:`../advanced/structured-logging-dictionary` for more details. The resulting format looks like this (when timestamps are enabled via ``--log-timestamps`` and ``timeFormat="ISO8601"``):: diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index 400eb92e31..a53c58092d 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -105,6 +105,7 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): _UDPResponder = None _TCPResponder = None _extraStartupSleep = 0 + _disableStructuredLoggingOnCL = False _dnsDistPort = pickAvailablePort() _consolePort = pickAvailablePort() _testServerPort = pickAvailablePort() @@ -182,6 +183,11 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): if cls._verboseMode: dnsdistcmd.append('-v') + + if cls._disableStructuredLoggingOnCL: + dnsdistcmd.append('--structured-logging') + dnsdistcmd.append('false') + if cls._sudoMode: preserve_env_values = ['LD_LIBRARY_PATH', 'LLVM_PROFILE_FILE'] for value in preserve_env_values: @@ -206,11 +212,17 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): else: if cls._checkConfigExpectedOutput is not None: expectedOutput = cls._checkConfigExpectedOutput - else: - expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode() - - if not cls._verboseMode and output != expectedOutput: - raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput)) + if not cls._verboseMode and output != expectedOutput: + raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput)) + elif not cls._verboseMode: + if not cls._disableStructuredLoggingOnCL: + expectedPrefix = b'msg="Configuration OK" subsystem="setup" level="0" prio="Info" ts="' + if not output.startswith(expectedPrefix): + raise AssertionError('dnsdist --check-config failed: %s (expected prefix %s)' % (output, expectedPrefix)) + else: + expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode() + if output != expectedOutput: + raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput)) logFile = os.path.join('configs', 'dnsdist_%s.log' % (cls.__name__)) with open(logFile, 'w') as fdLog: diff --git a/regression-tests.dnsdist/test_ConfigurationUpdates.py b/regression-tests.dnsdist/test_ConfigurationUpdates.py index d0414cc0f3..56c6ccb038 100644 --- a/regression-tests.dnsdist/test_ConfigurationUpdates.py +++ b/regression-tests.dnsdist/test_ConfigurationUpdates.py @@ -7,6 +7,10 @@ import extendederrors class TestConfigurationUpdates(DNSDistTest): _yaml_config_template = """--- +logging: + structured: + enabled: false + console: listen_address: "127.0.0.1:%d" key: "%s" diff --git a/regression-tests.dnsdist/test_DOH.py b/regression-tests.dnsdist/test_DOH.py index be16466bfa..e38e410c84 100644 --- a/regression-tests.dnsdist/test_DOH.py +++ b/regression-tests.dnsdist/test_DOH.py @@ -1144,9 +1144,7 @@ class DOHOverHTTP(object): class TestDOHOverHTTPNGHTTP2(DOHOverHTTP, DNSDistDOHTest): _dohLibrary = 'nghttp2' - _checkConfigExpectedOutput = b"""No certificate provided for DoH endpoint 127.0.0.1:%d, running in DNS over HTTP mode instead of DNS over HTTPS -Configuration 'configs/dnsdist_TestDOHOverHTTPNGHTTP2.conf' OK! -""" % (DOHOverHTTP._dohServerPort) + _checkConfigExpectedOutputPrefix = b'msg="No certificate provided for DoH frontend, running in DNS over HTTP mode instead of DNS over HTTPS"' class DOHWithCache(object): diff --git a/regression-tests.dnsdist/test_IncomingProtocol.py b/regression-tests.dnsdist/test_IncomingProtocol.py index 71de323054..d221aae63a 100644 --- a/regression-tests.dnsdist/test_IncomingProtocol.py +++ b/regression-tests.dnsdist/test_IncomingProtocol.py @@ -59,6 +59,9 @@ class IncomingProtocolLuaConfig(DNSDistTest, IncomingProtocol): class IncomingProtocolYAMLConfig(DNSDistTest, IncomingProtocol): _yaml_config_template = """ +logging: + structured: + enabled: false backends: - address: "127.0.0.1:%d" protocol: Do53 diff --git a/regression-tests.dnsdist/test_Lua.py b/regression-tests.dnsdist/test_Lua.py index 2a33a7084d..d390bf7b0d 100644 --- a/regression-tests.dnsdist/test_Lua.py +++ b/regression-tests.dnsdist/test_Lua.py @@ -95,6 +95,7 @@ class TestLuaDNSHeaderBindings(DNSDistTest): class TestLuaFrontendBindings(DNSDistTest): _config_template = """ + setStructuredLogging(false) newServer{address="127.0.0.1:%d"} -- check that all these methods return nil on a non-existing entry diff --git a/regression-tests.dnsdist/test_Yaml.py b/regression-tests.dnsdist/test_Yaml.py index d95bfef32d..e98a084c96 100644 --- a/regression-tests.dnsdist/test_Yaml.py +++ b/regression-tests.dnsdist/test_Yaml.py @@ -528,6 +528,10 @@ query_rules: class TestYamlUnknownSelectorName(DNSDistTest): _yaml_config_template = """--- +logging: + structured: + enabled: false + binds: - listen_address: "127.0.0.1:%d" protocol: Do53 @@ -552,6 +556,9 @@ query_rules: """ _yaml_config_params = ['_dnsDistPort', '_testServerPort'] _config_params = [] + # we need this because the error is triggered during the parsing of the YAML configuration, + # too early for the logging for the logging configuration to have been applied + _disableStructuredLoggingOnCL = True def testFailToStart(self): """ @@ -580,6 +587,10 @@ query_rules: class TestYamlUnknownPolicyName(DNSDistTest): _yaml_config_template = """--- +logging: + structured: + enabled: false + binds: - listen_address: "127.0.0.1:%d" protocol: Do53