]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add YAML support for multiple logger connections
authorEnsar Sarajčić <dev@ensarsarajcic.com>
Wed, 5 Feb 2025 19:02:26 +0000 (20:02 +0100)
committerEnsar Sarajčić <dev@ensarsarajcic.com>
Wed, 5 Feb 2025 19:02:26 +0000 (20:02 +0100)
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.

pdns/dnsdistdist/dnsdist-configuration-yaml.cc
pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs
pdns/dnsdistdist/dnsdist-settings-definitions.yml
pdns/dnsdistdist/docs/reference/yaml-settings.rst

index 7a98f939ba65cd5cf5aea4be50975d09397d428e..56bac8b462f2cb3b511d8dc711eab37f06f67a45 100644 (file)
@@ -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<RemoteLoggerInterface>(object, config.name);
     return;
   }
-  auto object = std::shared_ptr<RemoteLoggerInterface>(std::make_shared<RemoteLogger>(ComboAddress(std::string(config.address)), config.timeout, config.max_queued_entries * 100, config.reconnect_wait_time, false));
+  std::shared_ptr<RemoteLoggerInterface> object;
+  if (config.connection_count > 1) {
+    std::vector<std::shared_ptr<RemoteLoggerInterface>> loggers;
+    loggers.reserve(config.connection_count);
+    for (uint64_t i = 0; i < config.connection_count; i++) {
+      loggers.push_back(std::make_shared<RemoteLogger>(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<RemoteLoggerInterface>(std::make_shared<RemoteLoggerPool>(std::move(loggers)));
+  }
+  else {
+    object = std::shared_ptr<RemoteLoggerInterface>(std::make_shared<RemoteLogger>(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<RemoteLoggerInterface>(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<RemoteLoggerInterface>(std::make_shared<FrameStreamLogger>(family, std::string(config.address), false, options));
+  std::shared_ptr<RemoteLoggerInterface> object;
+  if (config.connection_count > 1) {
+    std::vector<std::shared_ptr<RemoteLoggerInterface>> loggers;
+    loggers.reserve(config.connection_count);
+    for (uint64_t i = 0; i < config.connection_count; i++) {
+      loggers.push_back(std::make_shared<FrameStreamLogger>(family, std::string(config.address), !dnsdist::configuration::yaml::s_inClientMode, options));
+    }
+    object = std::shared_ptr<RemoteLoggerInterface>(std::make_shared<RemoteLoggerPool>(std::move(loggers)));
+  }
+  else {
+    object = std::shared_ptr<RemoteLoggerInterface>(std::make_shared<FrameStreamLogger>(family, std::string(config.address), !dnsdist::configuration::yaml::s_inClientMode, options));
+  }
   dnsdist::configuration::yaml::registerType<RemoteLoggerInterface>(object, config.name);
 #endif
 }
index 7366076b88011171d53d6f98bbf72973e387fc01..cbc86e6e864462be105d3efa71b3619f44b3a688 100644 (file)
@@ -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)]
index f46030fe4384d0a78bc967eb7292b4ca9b543406..02510a3f622a2d868b16564b5f2c72bb66cf41fe 100644 (file)
@@ -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"
index 2a889a5ded373ab23e7d2bc8b72833d53166d4cf..ccdf76da8f6cc9ac580b01820b28fdb18e9ef4a7 100644 (file)
@@ -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: