Skip to content

Commit

Permalink
dnsdist: Clean up Dynamic Rules configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Jul 5, 2024
1 parent ad44f79 commit 6603c5c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions pdns/dnsdistdist/dnsdist-configuration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ struct RuntimeConfiguration
dnsdist::QueryCount::Configuration d_queryCountConfig;
std::string d_secPollSuffix{"secpoll.powerdns.com."};
std::string d_apiConfigDirectory;
uint64_t d_dynBlocksPurgeInterval{60};
size_t d_maxTCPQueriesPerConn{0};
size_t d_maxTCPConnectionDuration{0};
size_t d_proxyProtocolMaximumSize{512};
Expand Down
16 changes: 7 additions & 9 deletions pdns/dnsdistdist/dnsdist-dynblocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,6 @@ struct DynBlockEntryStat
std::list<DynBlockMaintenance::MetricsSnapshot> DynBlockMaintenance::s_metricsData;

LockGuarded<DynBlockMaintenance::Tops> DynBlockMaintenance::s_tops;
size_t DynBlockMaintenance::s_topN{20};
time_t DynBlockMaintenance::s_expiredDynBlocksPurgeInterval{60};

void DynBlockMaintenance::collectMetrics()
{
Expand Down Expand Up @@ -773,13 +771,14 @@ void DynBlockMaintenance::run()
static const time_t metricsGenerationInterval = 60;

time_t now = time(nullptr);
time_t nextExpiredPurge = now + s_expiredDynBlocksPurgeInterval;
auto purgeInterval = dnsdist::configuration::getCurrentRuntimeConfiguration().d_dynBlocksPurgeInterval;
time_t nextExpiredPurge = now + purgeInterval;
time_t nextMetricsCollect = now + metricsCollectionInterval;
time_t nextMetricsGeneration = now + metricsGenerationInterval;

while (true) {
time_t sleepDelay = std::numeric_limits<time_t>::max();
if (s_expiredDynBlocksPurgeInterval > 0) {
if (purgeInterval > 0) {
sleepDelay = std::min(sleepDelay, (nextExpiredPurge - now));
}
sleepDelay = std::min(sleepDelay, (nextMetricsCollect - now));
Expand Down Expand Up @@ -807,15 +806,14 @@ void DynBlockMaintenance::run()
nextMetricsGeneration = now + metricsGenerationInterval;
}

if (s_expiredDynBlocksPurgeInterval > 0 && now >= nextExpiredPurge) {
struct timespec tspec
{
};
purgeInterval = dnsdist::configuration::getCurrentRuntimeConfiguration().d_dynBlocksPurgeInterval;
if (purgeInterval > 0 && now >= nextExpiredPurge) {
timespec tspec{};
gettime(&tspec);
purgeExpired(tspec);

now = time(nullptr);
nextExpiredPurge = now + s_expiredDynBlocksPurgeInterval;
nextExpiredPurge = now + purgeInterval;
}
}
catch (const std::exception& e) {
Expand Down
4 changes: 1 addition & 3 deletions pdns/dnsdistdist/dnsdist-dynblocks.hh
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ public:
static std::map<std::string, std::list<std::pair<DNSName, unsigned int>>> getTopSuffixes(size_t topN);
static void purgeExpired(const struct timespec& now);

static time_t s_expiredDynBlocksPurgeInterval;

private:
static void collectMetrics();
static void generateMetrics();
Expand All @@ -380,7 +378,7 @@ private:
/* s_metricsData should only be accessed by the dynamic blocks maintenance thread so it does not need a lock */
// need N+1 datapoints to be able to do the diff after a collection point has been reached
static std::list<MetricsSnapshot> s_metricsData;
static size_t s_topN;
static constexpr size_t s_topN{20};
};

namespace dnsdist::DynamicBlocks
Expand Down
7 changes: 3 additions & 4 deletions pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
config.d_payloadSizeSelfGenAnswers = newValue;
},
std::numeric_limits<uint64_t>::max()},
#ifndef DISABLE_DYNBLOCKS
{"setDynBlocksPurgeInterval", [](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) { config.d_dynBlocksPurgeInterval = newValue; }, std::numeric_limits<uint32_t>::max()},
#endif /* DISABLE_DYNBLOCKS */
};

struct StringConfigurationItems
Expand Down Expand Up @@ -1733,10 +1736,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
}
});
#endif /* DISABLE_DEPRECATED_DYNBLOCK */

luaCtx.writeFunction("setDynBlocksPurgeInterval", [](uint64_t interval) {
DynBlockMaintenance::s_expiredDynBlocksPurgeInterval = static_cast<time_t>(interval);
});
#endif /* DISABLE_DYNBLOCKS */

#ifdef HAVE_DNSCRYPT
Expand Down

0 comments on commit 6603c5c

Please sign in to comment.