• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 21361274430

26 Jan 2026 02:28PM UTC coverage: 71.533% (+4.1%) from 67.39%
21361274430

push

github

web-flow
Merge pull request #16768 from rgacogne/and-in-the-darkness-bind-them

dnsdist: Implement sampling in our in-memory ring buffers

44772 of 77566 branches covered (57.72%)

Branch coverage included in aggregate %.

245 of 265 new or added lines in 12 files covered. (92.45%)

43 existing lines in 9 files now uncovered.

129243 of 165698 relevant lines covered (78.0%)

7830511.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.64
/pdns/statnode.cc
1
#include "statnode.hh"
2

3
StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const
4
{
×
5
  if(!silent) {
×
6
    cout<<string(depth, ' ');
×
7
    cout<<name<<": "<<endl;
×
8
  }
×
9
  Stat childstat;
×
10
  childstat.queries += s.queries;
×
11
  childstat.noerrors += s.noerrors;
×
12
  childstat.nxdomains += s.nxdomains;
×
13
  childstat.servfails += s.servfails;
×
14
  childstat.drops += s.drops;
×
15
  childstat.bytes += s.bytes;
×
16
  childstat.hits += s.hits;
×
17

18
  if(children.size()>1024 && !silent) {
×
19
    cout<<string(depth, ' ')<<name<<": too many to print"<<endl;
×
20
  }
×
21
  for(const children_t::value_type& child :  children) {
×
22
    childstat=child.second.print(depth+8, childstat, silent || children.size()>1024);
×
23
  }
×
24
  if(!silent || children.size()>1)
×
25
    cout<<string(depth, ' ')<<childstat.queries<<" queries, " << 
×
26
      childstat.noerrors<<" noerrors, "<< 
×
27
      childstat.nxdomains<<" nxdomains, "<< 
×
28
      childstat.servfails<<" servfails, "<< 
×
29
      childstat.drops<<" drops, "<<
×
30
      childstat.bytes<<" bytes, "<<
×
31
      childstat.hits<<" hits"<<endl;
×
32

33
  newstat+=childstat;
×
34

35
  return newstat;
×
36
}
×
37

38
void StatNode::visit(const visitor_t& visitor, Stat& newstat, unsigned int depth) const
39
{
1,079✔
40
  Stat childstat(s);
1,079✔
41

42
  for (const auto& child : children) {
1,079✔
43
    child.second.visit(visitor, childstat, depth+8);
1,068✔
44
  }
1,068✔
45

46
  visitor(this, s, childstat);
1,079✔
47

48
  newstat += childstat;
1,079✔
49
}
1,079✔
50

51
void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const std::optional<ComboAddress>& remote, size_t samplingRate)
52
{
1,031✔
53
  //  cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
54
  std::vector<string> tmp = domain.getRawLabels();
1,031✔
55
  if (tmp.empty()) {
1,031!
56
    return;
×
57
  }
×
58

59
  auto last = tmp.end() - 1;
1,031✔
60
  children[*last].submit(last, tmp.begin(), "", rcode, bytes, remote, 1, hit, samplingRate);
1,031✔
61
}
1,031✔
62

63
static uint64_t adjustForSampling(uint32_t count, size_t samplingRate)
64
{
3,096✔
65
  if (samplingRate > 0) {
3,096!
NEW
66
    return count * samplingRate;
×
NEW
67
  }
×
68
  return count;
3,096✔
69
}
3,096✔
70

71

72
/* www.powerdns.com. ->
73
   .                 <- fullnames
74
   com.
75
   powerdns.com
76
   www.powerdns.com. 
77
*/
78

79
void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const std::optional<ComboAddress>& remote, unsigned int count, bool hit, size_t samplingRate)
80
{
4,134✔
81
  //  cerr<<"Submit called for domain='"<<domain<<"': ";
82
  //  for(const std::string& n :  labels) 
83
  //    cerr<<n<<".";
84
  //  cerr<<endl;
85
  if (name.empty()) {
4,134✔
86

87
    name=*end;
1,068✔
88
    //    cerr<<"Set short name to '"<<name<<"'"<<endl;
89
  }
1,068✔
90
  else {
3,066✔
91
    //    cerr<<"Short name was already set to '"<<name<<"'"<<endl;
92
  }
3,066✔
93

94
  if (end == begin) {
4,134✔
95
    if (fullname.empty()) {
1,031✔
96
      size_t needed = name.size() + 1 + domain.size();
1,030✔
97
      if (fullname.capacity() < needed) {
1,030!
98
        fullname.reserve(needed);
1,030✔
99
      }
1,030✔
100
      fullname = name;
1,030✔
101
      fullname.append(".");
1,030✔
102
      fullname.append(domain);
1,030✔
103
      labelsCount = count;
1,030✔
104
    }
1,030✔
105
    //    cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
106
    s.queries += adjustForSampling(1U, samplingRate);
1,031✔
107
    s.bytes += adjustForSampling(bytes, samplingRate);
1,031✔
108
    if (rcode < 0) {
1,031!
NEW
109
      s.drops += adjustForSampling(1U, samplingRate);
×
110
    }
×
111
    else if (rcode == RCode::NoError) {
1,031!
112
      s.noerrors += adjustForSampling(1U, samplingRate);
1,031✔
113
    }
1,031✔
114
    else if (rcode == RCode::ServFail) {
×
NEW
115
      s.servfails += adjustForSampling(1U, samplingRate);
×
116
    }
×
117
    else if (rcode == RCode::NXDomain) {
×
NEW
118
      s.nxdomains += adjustForSampling(1U, samplingRate);
×
119
    }
×
120

121
    if (remote) {
1,031!
122
      s.remotes[*remote]++;
×
123
    }
×
124

125
    if (hit) {
1,031✔
126
      s.hits += adjustForSampling(1U, samplingRate);
3✔
127
    }
3✔
128
  }
1,031✔
129
  else {
3,103✔
130
    if (fullname.empty()) {
3,103✔
131
      size_t needed = name.size() + 1 + domain.size();
38✔
132
      if (fullname.capacity() < needed) {
38✔
133
        fullname.reserve(needed);
18✔
134
      }
18✔
135
      fullname = name;
38✔
136
      fullname.append(".");
38✔
137
      fullname.append(domain);
38✔
138
      labelsCount = count;
38✔
139
    }
38✔
140
    //    cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
141
    --end;
3,103✔
142
    children[*end].submit(end, begin, fullname, rcode, bytes, remote, count+1, hit, samplingRate);
3,103✔
143
  }
3,103✔
144
}
4,134✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc