]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/core/include/prometheus/registry.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / core / include / prometheus / registry.h
1 #pragma once
2
3 #include <memory>
4 #include <mutex>
5 #include <string>
6 #include <vector>
7
8 #include "prometheus/collectable.h"
9 #include "prometheus/detail/core_export.h"
10 #include "prometheus/family.h"
11 #include "prometheus/labels.h"
12 #include "prometheus/metric_family.h"
13
14 namespace prometheus {
15
16 class Counter;
17 class Gauge;
18 class Histogram;
19 class Summary;
20
21 namespace detail {
22
23 template <typename T>
24 class Builder; // IWYU pragma: keep
25
26 }
27 /// \brief Manages the collection of a number of metrics.
28 ///
29 /// The Registry is responsible to expose data to a class/method/function
30 /// "bridge", which returns the metrics in a format Prometheus supports.
31 ///
32 /// The key class is the Collectable. This has a method - called Collect() -
33 /// that returns zero or more metrics and their samples. The metrics are
34 /// represented by the class Family<>, which implements the Collectable
35 /// interface. A new metric is registered with BuildCounter(), BuildGauge(),
36 /// BuildHistogram() or BuildSummary().
37 ///
38 /// The class is thread-safe. No concurrent call to any API of this type causes
39 /// a data race.
40 class PROMETHEUS_CPP_CORE_EXPORT Registry : public Collectable {
41 public:
42 /// \brief How to deal with repeatedly added family names for a type.
43 ///
44 /// Adding a family with the same name but different types is always an error
45 /// and will lead to an exception.
46 enum class InsertBehavior {
47 /// \brief If a family with the same name and labels already exists return
48 /// the existing one. If no family with that name exists create it.
49 /// Otherwise throw.
50 Merge,
51 /// \brief Throws if a family with the same name already exists.
52 Throw,
53 };
54
55 /// \brief name Create a new registry.
56 ///
57 /// \param insert_behavior How to handle families with the same name.
58 explicit Registry(InsertBehavior insert_behavior = InsertBehavior::Merge);
59
60 /// \brief Deleted copy constructor.
61 Registry(const Registry&) = delete;
62
63 /// \brief Deleted copy assignment.
64 Registry& operator=(const Registry&) = delete;
65
66 /// \brief Deleted move constructor.
67 Registry(Registry&&) = delete;
68
69 /// \brief Deleted move assignment.
70 Registry& operator=(Registry&&) = delete;
71
72 /// \brief name Destroys a registry.
73 ~Registry() override;
74
75 /// \brief Returns a list of metrics and their samples.
76 ///
77 /// Every time the Registry is scraped it calls each of the metrics Collect
78 /// function.
79 ///
80 /// \return Zero or more metrics and their samples.
81 std::vector<MetricFamily> Collect() const override;
82
83 /// \brief Removes a metrics family from the registry.
84 ///
85 /// Please note that this operation invalidates the previously
86 /// returned reference to the Family and all of their added
87 /// metric objects.
88 ///
89 /// \tparam T One of the metric types Counter, Gauge, Histogram or Summary.
90 /// \param family The family to remove
91 ///
92 /// \return True if the family was found and removed.
93 template <typename T>
94 bool Remove(const Family<T>& family);
95
96 private:
97 template <typename T>
98 friend class detail::Builder;
99
100 template <typename T>
101 std::vector<std::unique_ptr<Family<T>>>& GetFamilies();
102
103 template <typename T>
104 bool NameExistsInOtherType(const std::string& name) const;
105
106 template <typename T>
107 Family<T>& Add(const std::string& name, const std::string& help,
108 const Labels& labels);
109
110 const InsertBehavior insert_behavior_;
111 std::vector<std::unique_ptr<Family<Counter>>> counters_;
112 std::vector<std::unique_ptr<Family<Gauge>>> gauges_;
113 std::vector<std::unique_ptr<Family<Histogram>>> histograms_;
114 std::vector<std::unique_ptr<Family<Summary>>> summaries_;
115 mutable std::mutex mutex_;
116 };
117
118 } // namespace prometheus