From: Remi Gacogne Date: Thu, 3 Jan 2019 15:14:28 +0000 (+0100) Subject: dnsdist: Add a 'rise' parameter to 'newServer()' X-Git-Tag: rec-4.2.0-alpha1~21^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b633bec2e1ac8d474be63b9313c55bae2d1d738;p=pdns dnsdist: Add a 'rise' parameter to 'newServer()' --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 091e8e505..49bdde30e 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -368,6 +368,10 @@ void setupLuaConfig(bool client) ret->maxCheckFailures=std::stoi(boost::get(vars["maxCheckFailures"])); } + if(vars.count("rise")) { + ret->minRiseSuccesses=std::stoi(boost::get(vars["rise"])); + } + if(vars.count("cpus")) { for (const auto cpu : boost::get>>(vars["cpus"])) { cpus.insert(std::stoi(cpu.second)); diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index a6c4e7acc..aafe16ac9 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1930,14 +1930,32 @@ static void healthChecksThread() if(dss->availability==DownstreamState::Availability::Auto) { bool newState=upCheck(*dss); if (newState) { - if (dss->currentCheckFailures != 0) { - dss->currentCheckFailures = 0; + /* check succeeded */ + dss->currentCheckFailures = 0; + + if (!dss->upStatus) { + /* we were marked as down */ + dss->consecutiveSuccesfulChecks++; + if (dss->consecutiveSuccesfulChecks < dss->minRiseSuccesses) { + /* if we need more than one successful check to rise + and we didn't reach the threshold yet, + let's stay down */ + newState = false; + } } } - else if (!newState && dss->upStatus) { - dss->currentCheckFailures++; - if (dss->currentCheckFailures < dss->maxCheckFailures) { - newState = true; + else { + /* check failed */ + dss->consecutiveSuccesfulChecks = 0; + + if (dss->upStatus) { + /* we are currently up */ + dss->currentCheckFailures++; + if (dss->currentCheckFailures < dss->maxCheckFailures) { + /* we need more than one failure to be marked as down, + and we did not reach the threshold yet, let's stay down */ + newState = true; + } } } @@ -1954,6 +1972,7 @@ static void healthChecksThread() dss->upStatus = newState; dss->currentCheckFailures = 0; + dss->consecutiveSuccesfulChecks = 0; if (g_snmpAgent && g_snmpTrapsEnabled) { g_snmpAgent->sendBackendStatusChangeTrap(dss); } diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index bbeeb0bcb..0827bcdba 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -711,7 +711,9 @@ struct DownstreamState uint16_t xpfRRCode{0}; uint16_t checkTimeout{1000}; /* in milliseconds */ uint8_t currentCheckFailures{0}; + uint8_t consecutiveSuccesfulChecks{0}; uint8_t maxCheckFailures{1}; + uint8_t minRiseSuccesses{1}; StopWatch sw; set pools; enum class Availability { Up, Down, Auto} availability{Availability::Auto}; diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 6015f7808..193dda46b 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -312,6 +312,7 @@ Servers .. versionchanged:: 1.3.4 - Added ``checkTimeout`` to server_table + - Added ``rise`` to server_table. Add a new backend server. Call this function with either a string:: @@ -339,8 +340,8 @@ Servers checkClass=NUM, -- Use NUM as QCLASS in the health-check query, default: DNSClass.IN checkName=STRING, -- Use STRING as QNAME in the health-check query, default: "a.root-servers.net." checkType=STRING, -- Use STRING as QTYPE in the health-check query, default: "A" - checkFunction=FUNCTION -- Use this function to dynamically set the QNAME, QTYPE and QCLASS to use in the health-check query (see :ref:`Healthcheck`) - checkTimeout=NUM -- The timeout (in milliseconds) of a health-check query, default: 1000 (1s) + checkFunction=FUNCTION,-- Use this function to dynamically set the QNAME, QTYPE and QCLASS to use in the health-check query (see :ref:`Healthcheck`) + checkTimeout=NUM, -- The timeout (in milliseconds) of a health-check query, default: 1000 (1s) setCD=BOOL, -- Set the CD (Checking Disabled) flag in the health-check query, default: false maxCheckFailures=NUM, -- Allow NUM check failures before declaring the backend down, default: 1 mustResolve=BOOL, -- Set to true when the health check MUST return a NOERROR RCODE and an answer @@ -353,7 +354,8 @@ Servers addXPF=NUM, -- Add the client's IP address and port to the query, along with the original destination address and port, -- using the experimental XPF record from `draft-bellis-dnsop-xpf `_ and the specified option code. Default is disabled (0) sockets=NUM, -- Number of sockets (and thus source ports) used toward the backend server, defaults to a single one - disableZeroScope -- Disable the EDNS Client Subnet 'zero scope' feature, which does a cache lookup for an answer valid for all subnets (ECS scope of 0) before adding ECS information to the query and doing the regular lookup + disableZeroScope=BOOL, -- Disable the EDNS Client Subnet 'zero scope' feature, which does a cache lookup for an answer valid for all subnets (ECS scope of 0) before adding ECS information to the query and doing the regular lookup + rise=NUM -- Require NUM consecutive successful checks before declaring the backend up, default: 1 }) :param str server_string: A simple IP:PORT string.