11#pragma once
22
33#include < algorithm>
4+ #include < cassert>
45#include < functional>
56#include < map>
67#include < memory>
1516#include " gauge_builder.h"
1617#include " histogram_builder.h"
1718#include " metric.h"
19+ #include " metric_family.h"
1820
1921namespace prometheus {
2022
@@ -32,7 +34,7 @@ class Family : public Collectable {
3234 void Remove (T* metric);
3335
3436 // Collectable
35- std::vector<io::prometheus::client:: MetricFamily> Collect () override ;
37+ std::vector<MetricFamily> Collect () override ;
3638
3739 private:
3840 std::unordered_map<std::size_t , std::unique_ptr<T>> metrics_;
@@ -44,7 +46,7 @@ class Family : public Collectable {
4446 const std::map<std::string, std::string> constant_labels_;
4547 std::mutex mutex_;
4648
47- io::prometheus::client::Metric CollectMetric (std::size_t hash, T* metric);
49+ ClientMetric CollectMetric (std::size_t hash, T* metric);
4850
4951 static std::size_t hash_labels (
5052 const std::map<std::string, std::string>& labels);
@@ -116,27 +118,27 @@ void Family<T>::Remove(T* metric) {
116118}
117119
118120template <typename T>
119- std::vector<io::prometheus::client:: MetricFamily> Family<T>::Collect() {
121+ std::vector<MetricFamily> Family<T>::Collect() {
120122 std::lock_guard<std::mutex> lock{mutex_};
121- auto family = io::prometheus::client:: MetricFamily{};
122- family.set_name ( name_) ;
123- family.set_help ( help_) ;
124- family.set_type ( T::metric_type) ;
123+ auto family = MetricFamily{};
124+ family.name = name_;
125+ family.help = help_;
126+ family.type = T::metric_type;
125127 for (const auto & m : metrics_) {
126- * family.add_metric () = std::move (CollectMetric (m.first , m.second .get ()));
128+ family.metric . push_back ( std::move (CollectMetric (m.first , m.second .get () )));
127129 }
128130 return {family};
129131}
130132
131133template <typename T>
132- io::prometheus::client::Metric Family<T>::CollectMetric(std::size_t hash,
133- T* metric) {
134+ ClientMetric Family<T>::CollectMetric(std::size_t hash, T* metric) {
134135 auto collected = metric->Collect ();
135136 auto add_label =
136137 [&collected](const std::pair<std::string, std::string>& label_pair) {
137- auto pair = collected.add_label ();
138- pair->set_name (label_pair.first );
139- pair->set_value (label_pair.second );
138+ auto label = ClientMetric::Label{};
139+ label.name = label_pair.first ;
140+ label.value = label_pair.second ;
141+ collected.label .push_back (std::move (label));
140142 };
141143 std::for_each (constant_labels_.cbegin (), constant_labels_.cend (), add_label);
142144 const auto & metric_labels = labels_.at (hash);
0 commit comments