Skip to content

Commit

Permalink
Merge b68155a into 70a1cfd
Browse files Browse the repository at this point in the history
  • Loading branch information
gjasny committed Oct 18, 2019
2 parents 70a1cfd + b68155a commit 6392f01
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 78 deletions.
5 changes: 2 additions & 3 deletions core/CMakeLists.txt
Expand Up @@ -2,15 +2,14 @@
add_library(core
src/check_names.cc
src/counter.cc
src/detail/builder.impl.h
src/detail/builder.cc
src/detail/ckms_quantiles.cc
src/detail/time_window_quantiles.cc
src/detail/utils.cc
src/family.cc
src/gauge.cc
src/family.impl.h
src/histogram.cc
src/registry.cc
src/registry.impl.h
src/serializer.cc
src/summary.cc
src/text_serializer.cc
Expand Down
3 changes: 1 addition & 2 deletions core/include/prometheus/detail/builder.h
Expand Up @@ -3,12 +3,11 @@
#include <map>
#include <string>

#include "prometheus/registry.h"

namespace prometheus {

template <typename T>
class Family;
class Registry;

namespace detail {

Expand Down
11 changes: 11 additions & 0 deletions core/include/prometheus/registry.h
Expand Up @@ -14,6 +14,11 @@

namespace prometheus {

class Counter;
class Gauge;
class Histogram;
class Summary;

namespace detail {

template <typename T>
Expand All @@ -35,6 +40,12 @@ class Builder;
/// a data race.
class PROMETHEUS_CPP_CORE_EXPORT Registry : public Collectable {
public:
/// \brief name Create a new registry.
Registry();

/// \brief name Destroys a registry.
~Registry();

/// \brief Returns a list of metrics and their samples.
///
/// Every time the Registry is scraped it calls each of the metrics Collect
Expand Down
13 changes: 0 additions & 13 deletions core/src/counter.cc
@@ -1,9 +1,5 @@
#include "prometheus/counter.h"

#include "detail/builder.impl.h"
#include "family.impl.h"
#include "registry.impl.h"

namespace prometheus {

void Counter::Increment() { gauge_.Increment(); }
Expand All @@ -18,13 +14,4 @@ ClientMetric Counter::Collect() const {
return metric;
}

template class PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Counter>;
template class PROMETHEUS_CPP_CORE_EXPORT Family<Counter>;

template Family<Counter>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

detail::Builder<Counter> BuildCounter() { return {}; }

} // namespace prometheus
18 changes: 16 additions & 2 deletions core/src/detail/builder.impl.h → core/src/detail/builder.cc
@@ -1,7 +1,11 @@
#pragma once

#include "prometheus/detail/builder.h"

#include "prometheus/counter.h"
#include "prometheus/gauge.h"
#include "prometheus/histogram.h"
#include "prometheus/registry.h"
#include "prometheus/summary.h"

namespace prometheus {

namespace detail {
Expand Down Expand Up @@ -30,6 +34,16 @@ Family<T>& Builder<T>::Register(Registry& registry) {
return registry.Add<T>(name_, help_, labels_);
}

template class PROMETHEUS_CPP_CORE_EXPORT Builder<Counter>;
template class PROMETHEUS_CPP_CORE_EXPORT Builder<Gauge>;
template class PROMETHEUS_CPP_CORE_EXPORT Builder<Histogram>;
template class PROMETHEUS_CPP_CORE_EXPORT Builder<Summary>;

} // namespace detail

detail::Builder<Counter> BuildCounter() { return {}; }
detail::Builder<Gauge> BuildGauge() { return {}; }
detail::Builder<Histogram> BuildHistogram() { return {}; }
detail::Builder<Summary> BuildSummary() { return {}; }

} // namespace prometheus
12 changes: 10 additions & 2 deletions core/src/family.impl.h → core/src/family.cc
@@ -1,7 +1,10 @@
#pragma once

#include "prometheus/family.h"

#include "prometheus/counter.h"
#include "prometheus/gauge.h"
#include "prometheus/histogram.h"
#include "prometheus/summary.h"

namespace prometheus {

template <typename T>
Expand Down Expand Up @@ -84,4 +87,9 @@ ClientMetric Family<T>::CollectMetric(std::size_t hash, T* metric) {
return collected;
}

template class PROMETHEUS_CPP_CORE_EXPORT Family<Counter>;
template class PROMETHEUS_CPP_CORE_EXPORT Family<Gauge>;
template class PROMETHEUS_CPP_CORE_EXPORT Family<Histogram>;
template class PROMETHEUS_CPP_CORE_EXPORT Family<Summary>;

} // namespace prometheus
13 changes: 0 additions & 13 deletions core/src/gauge.cc
@@ -1,9 +1,5 @@
#include "prometheus/gauge.h"

#include "detail/builder.impl.h"
#include "family.impl.h"
#include "registry.impl.h"

#include <ctime>

namespace prometheus {
Expand Down Expand Up @@ -49,13 +45,4 @@ ClientMetric Gauge::Collect() const {
return metric;
}

template class PROMETHEUS_CPP_CORE_EXPORT Family<Gauge>;
template class PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Gauge>;

template Family<Gauge>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

detail::Builder<Gauge> BuildGauge() { return {}; }

} // namespace prometheus
13 changes: 0 additions & 13 deletions core/src/histogram.cc
@@ -1,9 +1,5 @@
#include "prometheus/histogram.h"

#include "detail/builder.impl.h"
#include "family.impl.h"
#include "registry.impl.h"

#include <algorithm>
#include <cassert>
#include <iterator>
Expand Down Expand Up @@ -64,13 +60,4 @@ ClientMetric Histogram::Collect() const {
return metric;
}

template class PROMETHEUS_CPP_CORE_EXPORT Family<Histogram>;
template class PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Histogram>;

template Family<Histogram>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

detail::Builder<Histogram> BuildHistogram() { return {}; }

} // namespace prometheus
35 changes: 35 additions & 0 deletions core/src/registry.cc
@@ -1,9 +1,18 @@
#include "prometheus/registry.h"

#include "prometheus/counter.h"
#include "prometheus/gauge.h"
#include "prometheus/histogram.h"
#include "prometheus/summary.h"

#include <iterator>

namespace prometheus {

Registry::Registry() = default;

Registry::~Registry() = default;

std::vector<MetricFamily> Registry::Collect() {
std::lock_guard<std::mutex> lock{mutex_};
auto results = std::vector<MetricFamily>{};
Expand All @@ -16,4 +25,30 @@ std::vector<MetricFamily> Registry::Collect() {
return results;
}

template <typename T>
Family<T>& Registry::Add(const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels) {
std::lock_guard<std::mutex> lock{mutex_};
auto family = detail::make_unique<Family<T>>(name, help, labels);
auto& ref = *family;
collectables_.push_back(std::move(family));
return ref;
}

template Family<Counter>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

template Family<Gauge>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

template Family<Summary>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

template Family<Histogram>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

} // namespace prometheus
17 changes: 0 additions & 17 deletions core/src/registry.impl.h

This file was deleted.

13 changes: 0 additions & 13 deletions core/src/summary.cc
@@ -1,9 +1,5 @@
#include "prometheus/summary.h"

#include "detail/builder.impl.h"
#include "family.impl.h"
#include "registry.impl.h"

namespace prometheus {

Summary::Summary(const Quantiles& quantiles,
Expand Down Expand Up @@ -38,13 +34,4 @@ ClientMetric Summary::Collect() {
return metric;
}

template class PROMETHEUS_CPP_CORE_EXPORT Family<Summary>;
template class PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Summary>;

template Family<Summary>& Registry::Add(
const std::string& name, const std::string& help,
const std::map<std::string, std::string>& labels);

detail::Builder<Summary> BuildSummary() { return {}; }

} // namespace prometheus

0 comments on commit 6392f01

Please sign in to comment.