Skip to content

Commit

Permalink
pull: Add support for https and client certificates
Browse files Browse the repository at this point in the history
Issue: #329
  • Loading branch information
gjasny committed Mar 16, 2020
1 parent fca9c7e commit f55961a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 67 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
@@ -1,5 +1,5 @@

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(prometheus-cpp VERSION 0.9.0)

Expand All @@ -15,6 +15,7 @@ option(ENABLE_PUSH "Build prometheus-cpp push library" ON)
option(ENABLE_COMPRESSION "Enable gzip compression" ON)
option(ENABLE_TESTING "Build tests" ON)
option(USE_THIRDPARTY_LIBRARIES "Use 3rdParty submodules" ON)
option(THIRDPARTY_CIVETWEB_WITH_SSL "Enable SSL support for embedded civetweb source code")
option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++11 even if the CXXLFAGS are configured differently" ON)

if(OVERRIDE_CXX_STANDARD_FLAGS)
Expand Down
56 changes: 0 additions & 56 deletions cmake/Findcivetweb.cmake

This file was deleted.

13 changes: 12 additions & 1 deletion cmake/civetweb-3rdparty-config.cmake
Expand Up @@ -26,7 +26,6 @@ target_compile_definitions(civetweb
NDEBUG
NO_CGI
NO_CACHING
NO_SSL
NO_FILES
)

Expand All @@ -41,6 +40,18 @@ target_include_directories(civetweb
${CIVETWEB_INCLUDE_DIRS}
)

if(THIRDPARTY_CIVETWEB_WITH_SSL)
include(CMakeFindDependencyMacro)
find_dependency(OpenSSL)
if(OPENSSL_VERSION VERSION_GREATER_EQUAL 1.1)
target_compile_definitions(civetweb PRIVATE OPENSSL_API_1_1)
endif()
target_compile_definitions(civetweb PRIVATE NO_SSL_DL)
target_link_libraries(civetweb PUBLIC OpenSSL::SSL)
else()
target_compile_definitions(civetweb PRIVATE NO_SSL)
endif()

if(BUILD_SHARED_LIBS)
set_target_properties(civetweb PROPERTIES
POSITION_INDEPENDENT_CODE ON
Expand Down
12 changes: 12 additions & 0 deletions cmake/prometheus-cpp-config.cmake.in
Expand Up @@ -6,11 +6,23 @@ set_and_check(prometheus-cpp_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set(PROMETHEUS_CPP_ENABLE_PULL @ENABLE_PULL@)
set(PROMETHEUS_CPP_ENABLE_PUSH @ENABLE_PUSH@)
set(PROMETHEUS_CPP_USE_COMPRESSION @ENABLE_COMPRESSION@)
set(PROMETHEUS_CPP_USE_THIRDPARTY_LIBRARIES @USE_THIRDPARTY_LIBRARIES@)
set(PROMETHEUS_CPP_THIRDPARTY_CIVETWEB_WITH_SSL @THIRDPARTY_CIVETWEB_WITH_SSL@)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_dependency(Threads)
unset(CMAKE_THREAD_PREFER_PTHREAD)

if(PROMETHEUS_CPP_ENABLE_PULL)
if(PROMETHEUS_CPP_USE_THIRDPARTY_LIBRARIES)
if(PROMETHEUS_CPP_THIRDPARTY_CIVETWEB_WITH_SSL)
find_dependency(OpenSSL)
endif()
else()
find_dependency(civetweb)
endif()
endif()

if(PROMETHEUS_CPP_ENABLE_PULL AND PROMETHEUS_CPP_USE_COMPRESSION)
find_dependency(ZLIB)
endif()
Expand Down
6 changes: 2 additions & 4 deletions pull/CMakeLists.txt
@@ -1,8 +1,7 @@

if(USE_THIRDPARTY_LIBRARIES)
find_package(civetweb-3rdparty CONFIG REQUIRED)
else()
find_package(civetweb REQUIRED)
find_package(civetweb CONFIG REQUIRED)
endif()

if(ENABLE_COMPRESSION)
Expand All @@ -13,7 +12,6 @@ add_library(pull
src/exposer.cc
src/handler.cc
src/handler.h
$<$<BOOL:${USE_THIRDPARTY_LIBRARIES}>:$<TARGET_OBJECTS:civetweb>>
)

add_library(${PROJECT_NAME}::pull ALIAS pull)
Expand All @@ -23,7 +21,7 @@ target_link_libraries(pull
${PROJECT_NAME}::core
PRIVATE
Threads::Threads
${CIVETWEB_LIBRARIES}
$<IF:$<BOOL:${USE_THIRDPARTY_LIBRARIES}>,civetweb,civetweb::civetweb-cpp>
$<$<AND:$<BOOL:UNIX>,$<NOT:$<BOOL:APPLE>>>:rt>
$<$<BOOL:${ENABLE_COMPRESSION}>:ZLIB::ZLIB>
)
Expand Down
2 changes: 2 additions & 0 deletions pull/include/prometheus/exposer.h
Expand Up @@ -23,6 +23,8 @@ class PROMETHEUS_CPP_PULL_EXPORT Exposer {
explicit Exposer(const std::string& bind_address,
const std::string& uri = std::string("/metrics"),
const std::size_t num_threads = 2);
explicit Exposer(std::vector<std::string> options,
const std::string& uri = std::string("/metrics"));
~Exposer();
void RegisterCollectable(const std::weak_ptr<Collectable>& collectable);

Expand Down
14 changes: 9 additions & 5 deletions pull/src/exposer.cc
Expand Up @@ -4,18 +4,22 @@
#include <string>
#include <thread>

#include "prometheus/client_metric.h"

#include "CivetServer.h"
#include "handler.h"
#include "prometheus/client_metric.h"
#include "prometheus/detail/future_std.h"

namespace prometheus {

Exposer::Exposer(const std::string& bind_address, const std::string& uri,
const std::size_t num_threads)
: server_(new CivetServer{std::vector<std::string>{
"listening_ports", bind_address, "num_threads",
std::to_string(num_threads)}}),
: Exposer(
std::vector<std::string>{"listening_ports", bind_address,
"num_threads", std::to_string(num_threads)},
uri) {}

Exposer::Exposer(std::vector<std::string> options, const std::string& uri)
: server_(detail::make_unique<CivetServer>(std::move(options))),
exposer_registry_(std::make_shared<Registry>()),
metrics_handler_(
new detail::MetricsHandler{collectables_, *exposer_registry_}),
Expand Down

0 comments on commit f55961a

Please sign in to comment.