Skip to content

Commit

Permalink
Merge fca8824 into a0d7c52
Browse files Browse the repository at this point in the history
  • Loading branch information
gjasny committed Aug 31, 2019
2 parents a0d7c52 + fca8824 commit 96a6d7a
Show file tree
Hide file tree
Showing 33 changed files with 410 additions and 148 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
@@ -1,8 +1,9 @@

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(prometheus-cpp)
project(prometheus-cpp VERSION 0.8.0)

include(GenerateExportHeader)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand All @@ -20,6 +21,13 @@ if(OVERRIDE_CXX_STANDARD_FLAGS)
set(CMAKE_CXX_EXTENSIONS Off)
endif()

# Hide things by default for shared libraries
if(BUILD_SHARED_LIBS)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads)

Expand Down
18 changes: 16 additions & 2 deletions core/CMakeLists.txt
Expand Up @@ -2,19 +2,27 @@
add_library(core
src/check_names.cc
src/counter.cc
src/detail/builder.impl.h
src/detail/ckms_quantiles.cc
src/detail/time_window_quantiles.cc
src/detail/utils.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
)

add_library(${PROJECT_NAME}::core ALIAS core)

generate_export_header(core
EXPORT_FILE_NAME include/prometheus/detail/core_export.h
PREFIX_NAME PROMETHEUS_CPP_
)

target_link_libraries(core
PRIVATE
Threads::Threads
Expand All @@ -24,9 +32,15 @@ target_link_libraries(core
target_include_directories(core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
)

set_target_properties(core PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-core)
set_target_properties(core
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}-core
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

install(
TARGETS core
Expand All @@ -38,7 +52,7 @@ install(
)

install(
DIRECTORY include/
DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

Expand Down
6 changes: 4 additions & 2 deletions core/include/prometheus/check_names.h
Expand Up @@ -2,8 +2,10 @@

#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

bool CheckMetricName(const std::string& name);
bool CheckLabelName(const std::string& name);
PROMETHEUS_CPP_CORE_EXPORT bool CheckMetricName(const std::string& name);
PROMETHEUS_CPP_CORE_EXPORT bool CheckLabelName(const std::string& name);
} // namespace prometheus
4 changes: 3 additions & 1 deletion core/include/prometheus/client_metric.h
Expand Up @@ -5,9 +5,11 @@
#include <tuple>
#include <vector>

#include "prometheus/detail/core_export.h"

namespace prometheus {

struct ClientMetric {
struct PROMETHEUS_CPP_CORE_EXPORT ClientMetric {
// Label

struct Label {
Expand Down
4 changes: 3 additions & 1 deletion core/include/prometheus/collectable.h
Expand Up @@ -2,6 +2,8 @@

#include <vector>

#include "prometheus/detail/core_export.h"

namespace prometheus {
struct MetricFamily;
}
Expand All @@ -12,7 +14,7 @@ namespace prometheus {
/// collect metrics.
///
/// A Collectable has to be registered for collection. See Registry.
class Collectable {
class PROMETHEUS_CPP_CORE_EXPORT Collectable {
public:
virtual ~Collectable() = default;

Expand Down
5 changes: 3 additions & 2 deletions core/include/prometheus/counter.h
Expand Up @@ -2,6 +2,7 @@

#include "prometheus/client_metric.h"
#include "prometheus/detail/builder.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/gauge.h"
#include "prometheus/metric_type.h"

Expand All @@ -22,7 +23,7 @@ namespace prometheus {
///
/// The class is thread-safe. No concurrent call to any API of this type causes
/// a data race.
class Counter {
class PROMETHEUS_CPP_CORE_EXPORT Counter {
public:
static const MetricType metric_type{MetricType::Counter};

Expand Down Expand Up @@ -76,6 +77,6 @@ class Counter {
///
/// To finish the configuration of the Counter metric, register it with
/// Register(Registry&).
detail::Builder<Counter> BuildCounter();
PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Counter> BuildCounter();

} // namespace prometheus
26 changes: 1 addition & 25 deletions core/include/prometheus/detail/builder.h
Expand Up @@ -26,29 +26,5 @@ class Builder {
std::string help_;
};

template <typename T>
Builder<T>& Builder<T>::Labels(
const std::map<std::string, std::string>& labels) {
labels_ = labels;
return *this;
}

template <typename T>
Builder<T>& Builder<T>::Name(const std::string& name) {
name_ = name;
return *this;
}

template <typename T>
Builder<T>& Builder<T>::Help(const std::string& help) {
help_ = help;
return *this;
}

template <typename T>
Family<T>& Builder<T>::Register(Registry& registry) {
return registry.Add<T>(name_, help_, labels_);
}

} // namespace detail
} // namespace prometheus
} // namespace prometheus
6 changes: 4 additions & 2 deletions core/include/prometheus/detail/ckms_quantiles.h
Expand Up @@ -5,12 +5,14 @@
#include <functional>
#include <vector>

#include "prometheus/detail/core_export.h"

namespace prometheus {
namespace detail {

class CKMSQuantiles {
class PROMETHEUS_CPP_CORE_EXPORT CKMSQuantiles {
public:
struct Quantile {
struct PROMETHEUS_CPP_CORE_EXPORT Quantile {
const double quantile;
const double error;
const double u;
Expand Down
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/counter_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Counter;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT CounterBuilder {
public:
CounterBuilder& Labels(const std::map<std::string, std::string>& labels);
CounterBuilder& Name(const std::string&);
CounterBuilder& Help(const std::string&);
Family<Counter>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/gauge_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Gauge;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT GaugeBuilder {
public:
GaugeBuilder& Labels(const std::map<std::string, std::string>& labels);
GaugeBuilder& Name(const std::string&);
GaugeBuilder& Help(const std::string&);
Family<Gauge>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/histogram_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Histogram;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT HistogramBuilder {
public:
HistogramBuilder& Labels(const std::map<std::string, std::string>& labels);
HistogramBuilder& Name(const std::string&);
HistogramBuilder& Help(const std::string&);
Family<Histogram>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/summary_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Summary;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT SummaryBuilder {
public:
SummaryBuilder& Labels(const std::map<std::string, std::string>& labels);
SummaryBuilder& Name(const std::string&);
SummaryBuilder& Help(const std::string&);
Family<Summary>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
3 changes: 2 additions & 1 deletion core/include/prometheus/detail/time_window_quantiles.h
Expand Up @@ -5,11 +5,12 @@
#include <vector>

#include "prometheus/detail/ckms_quantiles.h"
#include "prometheus/detail/core_export.h"

namespace prometheus {
namespace detail {

class TimeWindowQuantiles {
class PROMETHEUS_CPP_CORE_EXPORT TimeWindowQuantiles {
using Clock = std::chrono::steady_clock;

public:
Expand Down
5 changes: 4 additions & 1 deletion core/include/prometheus/detail/utils.h
Expand Up @@ -4,6 +4,8 @@
#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

namespace detail {
Expand All @@ -13,7 +15,8 @@ namespace detail {
/// \param labels The map that will be computed the hash value.
///
/// \returns The hash value of the given labels.
std::size_t hash_labels(const std::map<std::string, std::string>& labels);
PROMETHEUS_CPP_CORE_EXPORT std::size_t hash_labels(
const std::map<std::string, std::string>& labels);

} // namespace detail

Expand Down

0 comments on commit 96a6d7a

Please sign in to comment.