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

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

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

80.43
/pdns/dnsdistdist/dnsdist-prometheus.hh
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
#pragma once
23

24
namespace dnsdist::prometheus
25
{
26
struct PrometheusMetricDefinition
27
{
28
  const std::string& name;
29
  const std::string& type;
30
  const std::string& description;
31
  const std::string& customName;
32
};
33
}
34

35
#ifndef DISABLE_PROMETHEUS
36
// Metric types for Prometheus
37
enum class PrometheusMetricType: uint8_t {
38
    counter = 1,
39
    gauge = 2
40
};
41

42
// Keeps additional information about metrics
43
struct MetricDefinition {
44
  MetricDefinition(PrometheusMetricType _prometheusType, const std::string& _description, const std::string& customName_ = ""): description(_description), customName(customName_), prometheusType(_prometheusType) {
62,701✔
45
  }
62,701✔
46

47
  MetricDefinition() = default;
171✔
48

49
  // Metric description
50
  std::string description;
51
  // Custom name, if any
52
  std::string customName;
53
  // Metric type for Prometheus
54
  PrometheusMetricType prometheusType{PrometheusMetricType::counter};
55
};
56

57
struct MetricDefinitionStorage {
58
  // Return metric definition by name
59
  bool getMetricDetails(const std::string& metricName, MetricDefinition& metric) const {
171✔
60
    const auto& metricDetailsIter = metrics.find(metricName);
171✔
61

62
    if (metricDetailsIter == metrics.end()) {
171✔
63
      return false;
12✔
64
    }
12✔
65

66
    metric = metricDetailsIter->second;
159✔
67
    return true;
159✔
68
  };
171✔
69

70
  static bool addMetricDefinition(const dnsdist::prometheus::PrometheusMetricDefinition& def) {
23✔
71
    static const std::map<std::string, PrometheusMetricType> namesToTypes = {
23✔
72
      {"counter", PrometheusMetricType::counter},
23✔
73
      {"gauge",   PrometheusMetricType::gauge},
23✔
74
    };
23✔
75
    auto realtype = namesToTypes.find(def.type);
23✔
76
    if (realtype == namesToTypes.end()) {
23!
77
      return false;
×
78
    }
×
79
    metrics.emplace(def.name, MetricDefinition{realtype->second, def.description, def.customName});
23✔
80
    return true;
23✔
81
  }
23✔
82

83
  // Return string representation of Prometheus metric type
84
  std::string getPrometheusStringMetricType(PrometheusMetricType metricType) const {
159✔
85
    switch (metricType) {
159✔
86
      case PrometheusMetricType::counter:
108✔
87
        return "counter";
108✔
88
        break;
×
89
      case PrometheusMetricType::gauge:
51✔
90
        return "gauge";
51✔
91
        break;
×
92
      default:
×
93
        return "";
×
94
        break;
×
95
    }
159✔
96
  };
159✔
97

98
  static std::map<std::string, MetricDefinition> metrics;
99
};
100
#endif /* DISABLE_PROMETHEUS */
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

© 2025 Coveralls, Inc