#include <string>
#include <vector>
-namespace pdns {
+namespace pdns
+{
// By convention, we are using microsecond units
struct Bucket
{
// We need the constructors in this case, since atomics have a disabled copy constructor.
AtomicBucket() {}
- AtomicBucket(std::string name, uint64_t boundary, uint64_t val) : d_name(std::move(name)), d_boundary(boundary), d_count(val) {}
- AtomicBucket(const AtomicBucket& rhs) : d_name(rhs.d_name), d_boundary(rhs.d_boundary), d_count(rhs.d_count.load()) {}
+ AtomicBucket(std::string name, uint64_t boundary, uint64_t val) :
+ d_name(std::move(name)), d_boundary(boundary), d_count(val) {}
+ AtomicBucket(const AtomicBucket& rhs) :
+ d_name(rhs.d_name), d_boundary(rhs.d_boundary), d_count(rhs.d_count.load()) {}
std::string d_name;
uint64_t d_boundary{0};
std::atomic<uint64_t> d_count{0};
};
-template<class B>
+template <class B>
class BaseHistogram
{
public:
}
d_buckets.reserve(boundaries.size() + 1);
uint64_t prev = 0;
- for (auto b: boundaries) {
+ for (auto b : boundaries) {
if (prev == b) {
throw std::invalid_argument("boundary array's elements should be distinct");
}
inline void operator()(uint64_t d)
{
auto index = std::upper_bound(d_buckets.begin(), d_buckets.end(), d, lessOrEqual);
- // out index is always valid
+ // our index is always valid
++index->d_count;
}
std::vector<B> d_buckets;
};
-template<class T>
+template <class T>
using Histogram = BaseHistogram<Bucket>;
-template<class T>
+template <class T>
using AtomicHistogram = BaseHistogram<AtomicBucket>;
} // namespace pdns
elif elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-rcode':
rcode_stats = elem['value']
self.assertIn('A', [e['name'] for e in qtype_stats])
- self.assertIn('60', [e['name'] for e in respsize_stats])
+ self.assertIn('80', [e['name'] for e in respsize_stats])
self.assertIn('example.com/A', [e['name'] for e in queries_stats])
self.assertIn('No Error', [e['name'] for e in rcode_stats])
else:
rcode_stats = elem['value']
self.assertIn('A', [e['name'] for e in qtype_stats])
self.assertIn('60', [e['name'] for e in respsize_stats])
+ self.assertIn('80', [e['name'] for e in respsize_stats])
self.assertIn('No Error', [e['name'] for e in rcode_stats])
-
def test_read_one_statistic(self):
r = self.session.get(self.url("/api/v1/servers/localhost/statistics?statistic=uptime"))
if line.split(" ")[0] == "pdns_recursor_uptime":
found = True
self.assertTrue(found,"pdns_recursor_uptime is missing")
-
+
@unittest.skipIf(is_auth(), "Not applicable")
def test_read_statistics_using_password(self):
r = requests.get(self.url("/api/v1/servers/localhost/statistics"), auth=('admin', self.server_web_password))