From ebdd92e2285d93cd516a785f3317eeece6098cd1 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 26 Jan 2026 14:38:57 +0100 Subject: [PATCH] dnsdist: Move sampling-related Ring methods to header Signed-off-by: Remi Gacogne --- pdns/dnsdistdist/dnsdist-rings.cc | 27 --------------------------- pdns/dnsdistdist/dnsdist-rings.hh | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-rings.cc b/pdns/dnsdistdist/dnsdist-rings.cc index 9f1231c30e..4eeae568ef 100644 --- a/pdns/dnsdistdist/dnsdist-rings.cc +++ b/pdns/dnsdistdist/dnsdist-rings.cc @@ -204,30 +204,3 @@ bool Rings::Response::isACacheHit() const } return hit; } - -bool Rings::shouldSkipQueryDueToSampling() -{ - if (d_samplingRate == 0) { - return false; - } - auto counter = t_samplingQueryCounter++; - return (counter % d_samplingRate) != 0; -} - -bool Rings::shouldSkipResponseDueToSampling() -{ - if (d_samplingRate == 0) { - return false; - } - auto counter = t_samplingResponseCounter++; - return (counter % d_samplingRate) != 0; -} - -uint32_t Rings::adjustForSamplingRate(uint32_t count) const -{ - const auto samplingRate = getSamplingRate(); - if (samplingRate > 0) { - return count * samplingRate; - } - return count; -} diff --git a/pdns/dnsdistdist/dnsdist-rings.hh b/pdns/dnsdistdist/dnsdist-rings.hh index a07a04a158..74db1d780c 100644 --- a/pdns/dnsdistdist/dnsdist-rings.hh +++ b/pdns/dnsdistdist/dnsdist-rings.hh @@ -245,7 +245,14 @@ struct Rings return d_samplingRate; } - uint32_t adjustForSamplingRate(uint32_t count) const; + uint32_t adjustForSamplingRate(uint32_t count) const + { + const auto samplingRate = getSamplingRate(); + if (samplingRate > 0) { + return count * samplingRate; + } + return count; + } std::vector> d_shards; pdns::stat_t d_blockingQueryInserts{0}; @@ -290,8 +297,23 @@ private: return wasFull; } - bool shouldSkipQueryDueToSampling(); - bool shouldSkipResponseDueToSampling(); + bool shouldSkipQueryDueToSampling() + { + if (d_samplingRate == 0) { + return false; + } + auto counter = t_samplingQueryCounter++; + return (counter % d_samplingRate) != 0; + } + + bool shouldSkipResponseDueToSampling() + { + if (d_samplingRate == 0) { + return false; + } + auto counter = t_samplingResponseCounter++; + return (counter % d_samplingRate) != 0; + } static constexpr bool s_keepLockingStats{false}; // small hack to reduce contention: this only works because we have a single Rings object in DNSdist -- 2.47.3