]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Rule for outstanding limits
authorph1 <ph1@slurpee2.phoned.ca>
Sun, 10 Oct 2021 02:35:23 +0000 (20:35 -0600)
committerph1 <ph1@slurpee2.phoned.ca>
Sun, 10 Oct 2021 02:35:23 +0000 (20:35 -0600)
pdns/dnsdist-console.cc
pdns/dnsdist.hh
pdns/dnsdistdist/dnsdist-backend.cc
pdns/dnsdistdist/dnsdist-rules.hh
pdns/dnsdistdist/docs/rules-actions.rst

index 72e97189138edd9c8d242d63cbe9c7b6f6a7d6f6..e20018dc098c54592fb4ee84994bebe35a293905 100644 (file)
@@ -541,6 +541,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "OrRule", true, "selectors", "Matches the traffic if one or more of the the selectors rules does match" },
   { "PoolAction", true, "poolname", "set the packet into the specified pool" },
   { "PoolAvailableRule", true, "poolname", "Check whether a pool has any servers available to handle queries" },
+  { "PoolOutstandingRule", true, "poolname, limit", "Check weather a pool has outstanding queries above limit" },
   { "printDNSCryptProviderFingerprint", true, "\"/path/to/providerPublic.key\"", "display the fingerprint of the provided resolver public key" },
   { "ProbaRule", true, "probability", "Matches queries with a given probability. 1.0 means always" },
   { "ProxyProtocolValueRule", true, "type [, value]", "matches queries with a specified Proxy Protocol TLV value of that type, optionally matching the content of the option as well" },
index 2f4d6480fc666620328ebbdde81015946259360d..d823c600de662c5f1cb740fa3723f677fdef20a0 100644 (file)
@@ -913,6 +913,7 @@ struct ServerPool
   std::shared_ptr<DNSDistPacketCache> packetCache{nullptr};
   std::shared_ptr<ServerPolicy> policy{nullptr};
 
+  size_t poolLoad();
   size_t countServers(bool upOnly);
   const std::shared_ptr<ServerPolicy::NumberedServerVector> getServers();
   void addServer(shared_ptr<DownstreamState>& server);
index ceef5574b4001c19dbf63e121d389ffe14bb56af..d72605794bc09dde8ff17eb070003245350d30ba 100644 (file)
@@ -218,6 +218,17 @@ size_t ServerPool::countServers(bool upOnly)
   return count;
 }
 
+size_t ServerPool::poolLoad()
+{
+  size_t load = 0;
+  auto servers = d_servers.read_lock();
+  for (const auto& server : **servers) {
+    size_t serverOutstanding = std::get<1>(server)->outstanding.load();
+    load += serverOutstanding;
+  }
+  return load;
+}
+
 const std::shared_ptr<ServerPolicy::NumberedServerVector> ServerPool::getServers()
 {
   std::shared_ptr<ServerPolicy::NumberedServerVector> result;
index 6e0e5d92322dd964837b448cc730b9a1ad87eb5c..dda702e4356b3dfbc0f6e6e47246418948791df6 100644 (file)
@@ -1082,6 +1082,28 @@ private:
   std::string d_poolname;
 };
 
+class PoolOutstandingRule : public DNSRule
+{
+public:
+  PoolOutstandingRule(const std::string& poolname, const size_t limit) : d_pools(&g_pools), d_poolname(poolname), d_limit(limit)
+  {
+  }
+
+  bool matches(const DNSQuestion* dq) const override
+  {
+    return (getPool(*d_pools, d_poolname)->poolLoad()) > d_limit;
+  }
+
+  string toString() const override
+  {
+    return "pool '" + d_poolname + "' outstanding > " + std::to_string(d_limit);
+  }
+private:
+  mutable LocalStateHolder<pools_t> d_pools;
+  std::string d_poolname;
+  size_t d_limit;
+};
+
 class KeyValueStoreLookupRule: public DNSRule
 {
 public:
index 3493d7f67c79bd5293f763fd1cde471eff607286..e408e56ee4a989a074ac3c09ac8f61c88695ef50 100644 (file)
@@ -761,6 +761,19 @@ These ``DNSRule``\ s be one of the following items:
 
   :param string poolname: Pool to check
 
+.. function:: PoolOutstandingRule(poolname, limit)
+
+  Check whether a pool has total outstanding queries above limit
+
+  .. code-block:: Lua
+
+    --- Send queries to spill over pool if default pool is under pressure
+    addAction(PoolOutstandingRule("", 5000), PoolAction("spillover"))
+
+  :param string poolname: Pool to check
+  :param int limit: Total outstanding limit
+
+
 Combining Rules
 ~~~~~~~~~~~~~~~