From 73491fb272a7984b6e86f83a561eb8c2ce096cdf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 5 Feb 2025 20:02:26 +0100 Subject: [PATCH] Add YAML support for multiple logger connections This also fixes a bug with loggers in YAML, which had hardcoded connection status. For `RemoteLogger` that worked by having it always connect, but for `FrameStreamLogger` it never connected. Now the behavior is the same as lua, by checking the client mode flag. --- .../dnsdistdist/dnsdist-configuration-yaml.cc | 27 +++++++++++++++++-- .../dnsdist-rust-lib/rust/src/lib.rs | 4 +++ .../dnsdist-settings-definitions.yml | 8 ++++++ .../docs/reference/yaml-settings.rst | 2 ++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 7a98f939ba..56bac8b462 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -42,6 +42,7 @@ #include "fstrm_logger.hh" #include "iputils.hh" #include "remote_logger.hh" +#include "remote_logger_pool.hh" #include "xsk.hh" #include "rust/cxx.h" @@ -1533,7 +1534,18 @@ void registerProtobufLogger(const ProtobufLoggerConfiguration& config) dnsdist::configuration::yaml::registerType(object, config.name); return; } - auto object = std::shared_ptr(std::make_shared(ComboAddress(std::string(config.address)), config.timeout, config.max_queued_entries * 100, config.reconnect_wait_time, false)); + std::shared_ptr object; + if (config.connection_count > 1) { + std::vector> loggers; + loggers.reserve(config.connection_count); + for (uint64_t i = 0; i < config.connection_count; i++) { + loggers.push_back(std::make_shared(ComboAddress(std::string(config.address)), config.timeout, config.max_queued_entries * 100, config.reconnect_wait_time, dnsdist::configuration::yaml::s_inClientMode)); + } + object = std::shared_ptr(std::make_shared(std::move(loggers))); + } + else { + object = std::shared_ptr(std::make_shared(ComboAddress(std::string(config.address)), config.timeout, config.max_queued_entries * 100, config.reconnect_wait_time, dnsdist::configuration::yaml::s_inClientMode)); + } dnsdist::configuration::yaml::registerType(object, config.name); #endif } @@ -1569,7 +1581,18 @@ void registerDnstapLogger(const DnstapLoggerConfiguration& config) options["queueNotifyThreshold"] = config.queue_notify_threshold; options["reopenInterval"] = config.reopen_interval; - auto object = std::shared_ptr(std::make_shared(family, std::string(config.address), false, options)); + std::shared_ptr object; + if (config.connection_count > 1) { + std::vector> loggers; + loggers.reserve(config.connection_count); + for (uint64_t i = 0; i < config.connection_count; i++) { + loggers.push_back(std::make_shared(family, std::string(config.address), !dnsdist::configuration::yaml::s_inClientMode, options)); + } + object = std::shared_ptr(std::make_shared(std::move(loggers))); + } + else { + object = std::shared_ptr(std::make_shared(family, std::string(config.address), !dnsdist::configuration::yaml::s_inClientMode, options)); + } dnsdist::configuration::yaml::registerType(object, config.name); #endif } diff --git a/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs b/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs index 7366076b88..cbc86e6e86 100644 --- a/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs +++ b/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs @@ -1197,6 +1197,8 @@ mod dnsdistsettings { max_queued_entries: u64, #[serde(default = "crate::U8::<1>::value", skip_serializing_if = "crate::U8::<1>::is_equal")] reconnect_wait_time: u8, + #[serde(default = "crate::U64::<1>::value", skip_serializing_if = "crate::U64::<1>::is_equal")] + connection_count: u64, } #[derive(Deserialize, Serialize, Debug, PartialEq)] @@ -1217,6 +1219,8 @@ mod dnsdistsettings { queue_notify_threshold: u64, #[serde(default, skip_serializing_if = "crate::is_default")] reopen_interval: u64, + #[serde(default = "crate::U64::<1>::value", skip_serializing_if = "crate::U64::<1>::is_equal")] + connection_count: u64, } #[derive(Deserialize, Serialize, Debug, PartialEq)] diff --git a/pdns/dnsdistdist/dnsdist-settings-definitions.yml b/pdns/dnsdistdist/dnsdist-settings-definitions.yml index f46030fe43..02510a3f62 100644 --- a/pdns/dnsdistdist/dnsdist-settings-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-settings-definitions.yml @@ -208,6 +208,10 @@ protobuf_logger: type: "u8" default: 1 description: "Time in seconds between reconnection attempts" + - name: "connection_count" + type: "u64" + default: 1 + description: "Number of connections to open to the endpoint" dnstap_logger: description: "Endpoint to send queries and/or responses data to, using the dnstap format" @@ -248,6 +252,10 @@ dnstap_logger: type: "u64" default: 0 description: "The number of queue entries to allocate for each output queue. According to the libfstrm library, the minimum is 2, the maximum is system-dependent and based on IOV_MAX, and the default is 64" + - name: "connection_count" + type: "u64" + default: 1 + description: "Number of connections to open to the endpoint" proto_buf_meta: description: "Meta-data entry to be added to a Protocol Buffer message" diff --git a/pdns/dnsdistdist/docs/reference/yaml-settings.rst b/pdns/dnsdistdist/docs/reference/yaml-settings.rst index 2a889a5ded..ccdf76da8f 100644 --- a/pdns/dnsdistdist/docs/reference/yaml-settings.rst +++ b/pdns/dnsdistdist/docs/reference/yaml-settings.rst @@ -204,6 +204,7 @@ Endpoint to send queries and/or responses data to, using the dnstap format - **output_queue_size**: Unsigned integer ``(0)`` - The number of queue entries to allocate for each output queue. According to the libfstrm library, the minimum is 2, the maximum is system-dependent and based on ``IOV_MAX``, and the default is 64 - **queue_notify_threshold**: Unsigned integer ``(0)`` - The number of outstanding queue entries to allow on an input queue before waking the I/O thread. According to the libfstrm library, the minimum is 1 and the default is 32 - **reopen_interval**: Unsigned integer ``(0)`` - The number of queue entries to allocate for each output queue. According to the libfstrm library, the minimum is 2, the maximum is system-dependent and based on IOV_MAX, and the default is 64 +- **connection_count**: Unsigned integer ``(1)`` - Number of connections to open to the endpoint .. _yaml-settings-DohTuningConfiguration: @@ -773,6 +774,7 @@ Endpoint to send queries and/or responses data to, using the native PowerDNS for - **timeout**: Unsigned integer ``(2)`` - TCP connect timeout in seconds - **max_queued_entries**: Unsigned integer ``(100)`` - Queue this many messages before dropping new ones (e.g. when the remote listener closes the connection) - **reconnect_wait_time**: Unsigned integer ``(1)`` - Time in seconds between reconnection attempts +- **connection_count**: Unsigned integer ``(1)`` - Number of connections to open to the endpoint .. _yaml-settings-ProxyProtocolConfiguration: -- 2.47.2