From: Otto Moerbeek Date: Fri, 26 Aug 2022 13:02:46 +0000 (+0200) Subject: Proces review comments by rgacogne, thanks! X-Git-Tag: rec-4.8.0-alpha1~47^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F11881%2Fhead;p=thirdparty%2Fpdns.git Proces review comments by rgacogne, thanks! --- diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 5004d3f1db..cc1ec21d27 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -1433,7 +1433,7 @@ static DnstapMessage::ProtocolType ProtocolToDNSTap(dnsdist::Protocol protocol) throw std::runtime_error("Unhandled protocol for dnstap: " + protocol.toPrettyString()); } -void remoteLoggerQueueData(RemoteLoggerInterface& r, const std::string& data) +static void remoteLoggerQueueData(RemoteLoggerInterface& r, const std::string& data) { auto ret = r.queueData(data); @@ -1441,15 +1441,15 @@ void remoteLoggerQueueData(RemoteLoggerInterface& r, const std::string& data) case RemoteLoggerInterface::Result::Queued: break; case RemoteLoggerInterface::Result::PipeFull: { - vinfolog("%s: queue full, dropping.", r.name().c_str()); + vinfolog("%s: %s", r.name(), RemoteLoggerInterface::toErrorString(ret)); break; } case RemoteLoggerInterface::Result::TooLarge: { - warnlog("%s: Not sending too large protobuf message", r.name().c_str()); + warnlog("%s: %s", r.name(), RemoteLoggerInterface::toErrorString(ret)); break; } case RemoteLoggerInterface::Result::OtherError: - warnlog("%s: submitting to queue failed", r.name().c_str()); + warnlog("%s: %s", r.name(), RemoteLoggerInterface::toErrorString(ret)); } } diff --git a/pdns/fstrm_logger.hh b/pdns/fstrm_logger.hh index 624f67c7eb..21ec298906 100644 --- a/pdns/fstrm_logger.hh +++ b/pdns/fstrm_logger.hh @@ -39,7 +39,7 @@ public: FrameStreamLogger(int family, const std::string& address, bool connect, const std::unordered_map& options = std::unordered_map()); ~FrameStreamLogger(); [[nodiscard]] RemoteLoggerInterface::Result queueData(const std::string& data) override; - std::string name() const override + const std::string name() const override { return "framestream"; } diff --git a/pdns/lwres.cc b/pdns/lwres.cc index d9ae39f14f..422e349063 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -72,22 +72,22 @@ void remoteLoggerQueueData(RemoteLoggerInterface& r, const std::string& data) case RemoteLoggerInterface::Result::Queued: break; case RemoteLoggerInterface::Result::PipeFull: { + const auto msg = RemoteLoggerInterface::toErrorString(ret); const auto name = r.name(); - const auto msg = "queue full, dropping"; SLOG(g_log << Logger::Debug << name << ": " << msg <withName(name)->info(Logr::Debug, msg)); break; } case RemoteLoggerInterface::Result::TooLarge: { + const auto msg = RemoteLoggerInterface::toErrorString(ret); const auto name = r.name(); - const auto msg = "Not sending too large protobuf message"; SLOG(g_log << Logger::Notice << name << ": " << msg <withName(name)->info(Logr::Debug, msg)); break; } case RemoteLoggerInterface::Result::OtherError: { + const auto msg = RemoteLoggerInterface::toErrorString(ret); const auto name = r.name(); - const auto msg = "submitting to queue failed"; SLOG(g_log << Logger::Warning << name << ": " << msg << std::endl, g_slog->withName(name)->info(Logr::Warning, msg)); break; diff --git a/pdns/lwres.hh b/pdns/lwres.hh index 9e0a4599a7..97e8d01598 100644 --- a/pdns/lwres.hh +++ b/pdns/lwres.hh @@ -46,6 +46,9 @@ #include "logging.hh" +// Helper to be defined by main program: queue data and log based on return value of queueData() +void remoteLoggerQueueData(RemoteLoggerInterface&, const std::string&); + extern std::shared_ptr g_slogout; class LWResException : public PDNSException diff --git a/pdns/remote_logger.cc b/pdns/remote_logger.cc index 0d3c37625c..9616511699 100644 --- a/pdns/remote_logger.cc +++ b/pdns/remote_logger.cc @@ -95,6 +95,19 @@ bool CircularWriteBuffer::flush(int fd) return true; } +const std::string& RemoteLoggerInterface::toErrorString(Result r) +{ + static const std::array str = { + "Queued", + "Queue full, dropping", + "Not sending too large protobuf message", + "Submiting to queue failed", + "?" + }; + auto i = static_cast(r); + return str[std::min(i, 4U)]; +} + RemoteLogger::RemoteLogger(const ComboAddress& remote, uint16_t timeout, uint64_t maxQueuedBytes, uint8_t reconnectWaitTime, bool asyncConnect): d_remote(remote), d_timeout(timeout), d_reconnectWaitTime(reconnectWaitTime), d_asyncConnect(asyncConnect), d_runtime({CircularWriteBuffer(maxQueuedBytes), nullptr}) { if (!d_asyncConnect) { @@ -240,3 +253,4 @@ RemoteLogger::~RemoteLogger() d_thread.join(); } + diff --git a/pdns/remote_logger.hh b/pdns/remote_logger.hh index 7c59626343..72b1ec5e31 100644 --- a/pdns/remote_logger.hh +++ b/pdns/remote_logger.hh @@ -61,11 +61,12 @@ class RemoteLoggerInterface { public: enum class Result : uint8_t { Queued, PipeFull, TooLarge, OtherError }; + static const std::string& toErrorString(Result r); virtual ~RemoteLoggerInterface() {}; virtual Result queueData(const std::string& data) = 0; virtual std::string toString() const = 0; - virtual std::string name() const = 0; + virtual const std::string name() const = 0; bool logQueries(void) const { return d_logQueries; } bool logResponses(void) const { return d_logResponses; } void setLogQueries(bool flag) { d_logQueries = flag; } @@ -91,7 +92,7 @@ public: ~RemoteLogger(); [[nodiscard]] Result queueData(const std::string& data) override; - std::string name() const override + const std::string name() const override { return "protobuf"; } @@ -126,5 +127,3 @@ private: std::thread d_thread; }; -// Helper to be defined by main program: queue data and log based on return value of queueData() -void remoteLoggerQueueData(RemoteLoggerInterface&, const std::string&);