Skip to content

Commit

Permalink
auth: Add a new 'backend-queries' metric
Browse files Browse the repository at this point in the history
Counting the numbers of queries sent to the backend(s), instead of
relying on the number of cache misses.
  • Loading branch information
rgacogne committed Apr 6, 2020
1 parent 22ec979 commit 301779c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pdns/dnsbackend.cc
Expand Up @@ -32,6 +32,9 @@
#include "pdns/packetcache.hh"
#include "dnspacket.hh"
#include "dns.hh"
#include "statbag.hh"

extern StatBag S;

// this has to be somewhere central, and not in a file that requires Lua
// this is so the geoipbackend can set this pointer if loaded for lua-record.cc
Expand Down Expand Up @@ -223,6 +226,7 @@ vector<DNSBackend *>BackendMakerClass::all(bool metadataOnly)
bool DNSBackend::getSOA(const DNSName &domain, SOAData &sd)
{
this->lookup(QType(QType::SOA),domain,-1);
S.inc("backend-queries");

DNSResourceRecord rr;
rr.auth = true;
Expand Down
11 changes: 8 additions & 3 deletions pdns/ueberbackend.cc
Expand Up @@ -50,10 +50,11 @@
extern StatBag S;

vector<UeberBackend *>UeberBackend::instances;
pthread_mutex_t UeberBackend::instances_lock=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t UeberBackend::instances_lock = PTHREAD_MUTEX_INITIALIZER;

// initially we are blocked
bool UeberBackend::d_go=false;
bool UeberBackend::d_go = false;
AtomicCounter* UeberBackend::s_backendQueries = nullptr;
pthread_mutex_t UeberBackend::d_mut = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t UeberBackend::d_cond = PTHREAD_COND_INITIALIZER;

Expand Down Expand Up @@ -95,7 +96,9 @@ bool UeberBackend::loadModules(const vector<string>& modules, const string& path
void UeberBackend::go(void)
{
pthread_mutex_lock(&d_mut);
d_go=true;
d_go = true;
S.declare("backend-queries", "Number of queries sent to the backend(s)");
s_backendQueries = S.getPointer("backend-queries");
pthread_cond_broadcast(&d_cond);
pthread_mutex_unlock(&d_mut);
}
Expand Down Expand Up @@ -632,6 +635,7 @@ void UeberBackend::lookup(const QType &qtype,const DNSName &qname, int zoneId, D
d_answers.clear();
d_handle.d_hinterBackend = backends.at(d_handle.i++);
d_handle.d_hinterBackend->lookup(QType::ANY, qname, zoneId, pkt_p);
++(*s_backendQueries);
}
else if (cstat == 0) {
// cout<<"UeberBackend::lookup("<<qname<<"|"<<DNSRecordContent::NumberToType(qtype.getCode())<<"): NEGcached"<<endl;
Expand Down Expand Up @@ -755,6 +759,7 @@ bool UeberBackend::handle::get(DNSZoneRecord &r)

d_hinterBackend = parent->backends.at(i++);
d_hinterBackend->lookup(qtype, qname, parent->d_domain_id, pkt_p);
++(*s_backendQueries);
}
else {
break;
Expand Down
1 change: 1 addition & 0 deletions pdns/ueberbackend.hh
Expand Up @@ -158,6 +158,7 @@ private:
bool d_cached{false};
bool d_stale{false};

static AtomicCounter* s_backendQueries;
static bool d_go;

int cacheHas(const Question &q, vector<DNSZoneRecord> &rrs);
Expand Down
2 changes: 1 addition & 1 deletion regression-tests.nobackend/counters/command
Expand Up @@ -27,7 +27,7 @@ $SDIG ::1 $port example.com SOA >&2 >/dev/null
$SDIG ::1 $port example.com SOA tcp >&2 >/dev/null

$PDNSCONTROL --config-name= --no-config --socket-dir=./ 'show *' | \
tr ',' '\n'| grep -v -E '(user-msec|sys-msec|cpu-iowait|cpu-steal|uptime|udp-noport-errors|udp-in-errors|real-memory-usage|special-memory-usage|udp-recvbuf-errors|udp-sndbuf-errors|-hit|-miss|fd-usage|latency)' | LC_ALL=C sort
tr ',' '\n'| grep -v -E '(user-msec|sys-msec|cpu-iowait|cpu-steal|uptime|udp-noport-errors|udp-in-errors|real-memory-usage|special-memory-usage|udp-recvbuf-errors|udp-sndbuf-errors|-hit|-miss|fd-usage|latency|backend-queries)' | LC_ALL=C sort

kill $(cat pdns*.pid)
rm pdns*.pid

0 comments on commit 301779c

Please sign in to comment.