Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
[submodule "logdevice/external/fbthrift"]
path = logdevice/external/fbthrift
url = https://github.com/facebook/fbthrift/
[submodule "logdevice/external/prometheus-cpp"]
path = logdevice/external/prometheus-cpp
url = https://github.com/jupp0r/prometheus-cpp/
1 change: 0 additions & 1 deletion logdevice/CMake/build-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ set(LOGDEVICE_PYTHON_CLIENT_DIR "${LOGDEVICE_DIR}/clients/python")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(UNIT_TEST_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
set(LOGDEVICE_PY_OUT ${CMAKE_BINARY_DIR}/python-out)
6 changes: 6 additions & 0 deletions logdevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ include(build-config)

option(BUILD_TESTS "If enabled, compile the tests." ON)
option(BUILD_SUBMODULES "Build using Git submodules, to fulfill dependencies" ON)
option(BUILD_PLUGINS "If enabled, build standard plugins." ON)

if(${BUILD_SUBMODULES})
message("Building with submodules enabled")
include(build-fmt)
Expand Down Expand Up @@ -226,3 +228,7 @@ endif()
add_subdirectory(examples)
add_subdirectory(clients/python)
add_subdirectory(ops)

if (${BUILD_PLUGINS})
add_subdirectory(plugins/prometheus)
endif()
1 change: 1 addition & 0 deletions logdevice/external/prometheus-cpp
Submodule prometheus-cpp added at 3ec526
14 changes: 14 additions & 0 deletions logdevice/plugins/prometheus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2017-present, Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_THREAD_PREFER_PTHREAD ON)

include(build-prometheus-cpp)

add_subdirectory(src)
40 changes: 40 additions & 0 deletions logdevice/plugins/prometheus/cmake/build-prometheus-cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2017-present, Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set(PROMETHEUS_ROOT_DIR ${LOGDEVICE_DIR}/external/prometheus-cpp)

include(ExternalProject)

ExternalProject_Add(prometheus
SOURCE_DIR "${PROMETHEUS_ROOT_DIR}"
DOWNLOAD_COMMAND ""
CMAKE_ARGS
-DBUILD_SHARED_LIBS=OFF
-DENABLE_TESTING=OFF
-DENABLE_PUSH=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_PREFIX_PATH=${LOGDEVICE_STAGING_DIR}/usr/local
INSTALL_COMMAND make install DESTDIR=${LOGDEVICE_STAGING_DIR}
)

ExternalProject_Get_Property(prometheus SOURCE_DIR)
ExternalProject_Get_Property(prometheus BINARY_DIR)

set(PROMETHEUS_LIBRARIES
${LOGDEVICE_STAGING_DIR}/usr/local/lib/libprometheus-cpp-core.a
${LOGDEVICE_STAGING_DIR}/usr/local/lib/libprometheus-cpp-pull.a)

set(PROMETHEUS_INCLUDE_DIR ${LOGDEVICE_STAGING_DIR}/usr/local/include)

message(STATUS "Prometheus Library: ${PROMETHEUS_LIBRARIES}")
message(STATUS "Prometheus Includes: ${PROMETHEUS_INCLUDE_DIR}")

mark_as_advanced(
PROMETHEUS_ROOT_DIR
PROMETHEUS_LIBRARIES
PROMETHEUS_INCLUDE_DIR
)
80 changes: 80 additions & 0 deletions logdevice/plugins/prometheus/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2017-present, Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# The plugin's main shared library
add_library(ldprometheus
SHARED
PrometheusPublisherFactory
PrometheusStatsPublisher
PrometheusSettings
main
)

add_dependencies(ldprometheus prometheus folly)

target_include_directories(
ldprometheus
PUBLIC
${LOGDEVICE_INCLUDE_DIRS}
${PROMETHEUS_INCLUDE_DIR}
)

# Build our shared library with -fPIC
set_target_properties(
ldprometheus
PROPERTIES
POSITION_INDEPENDENT_CODE True
)

# Link the prometheus library statically
target_link_libraries(
ldprometheus
"-Wl,--whole-archive"
${PROMETHEUS_LIBRARIES}
"-Wl,--no-whole-archive"
)


# Building the tests
if(${BUILD_TESTS})
add_executable(prometheus_test tests/PublisherTest.cpp)
add_dependencies(prometheus_test ldprometheus)
target_include_directories(
prometheus_test
PUBLIC
${GTEST_INCLUDE_DIRS})
target_link_libraries(
prometheus_test
ldprometheus
common
logdevice_server
${GTEST_LIBRARY}
${PROMETHEUS_LIBRARIES}
${LOGDEVICE_EXTERNAL_DEPS}
glog
Threads::Threads)

if (HAVE_CMAKE_GTEST)
gtest_discover_tests(prometheus_test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
else()
add_test(
NAME PrometheusTest
COMMAND ${UNIT_TEST_OUTPUT_DIRECTORY}/prometheus_test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

add_test(NAME prometheus_test COMMAND prometheus_test)

set_target_properties(prometheus_test
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${UNIT_TEST_OUTPUT_DIRECTORY})

target_compile_definitions(prometheus_test
PRIVATE
GTEST_USE_OWN_TR1_TUPLE=0
)
endif(${BUILD_TESTS})
58 changes: 58 additions & 0 deletions logdevice/plugins/prometheus/src/PrometheusPublisherFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2017-present, Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @author Mohamed Bassem
*/

#include <logdevice/common/plugin/StatsPublisherFactory.h>
#include <logdevice/common/settings/Settings.h>
#include <logdevice/common/settings/SettingsUpdater.h>
#include <logdevice/common/settings/UpdateableSettings.h>

#include "PrometheusSettings.h"
#include "PrometheusStatsPublisher.h"

namespace facebook { namespace logdevice {

class PrometheusStatsPublisherFactory : public StatsPublisherFactory {
public:
virtual ~PrometheusStatsPublisherFactory() = default;

PluginType type() const override {
return PluginType::STATS_PUBLISHER_FACTORY;
}

std::unique_ptr<StatsPublisher> operator()(UpdateableSettings<Settings>,
int num_db_shards) override {
if (prometheus_settings_->prometheus_listen_addr.empty()) {
ld_error("Prometheus was used as the stats publisher, but the listen "
"address is not set. Will not load the plugin.");
return nullptr;
}
return std::make_unique<PrometheusStatsPublisher>(
prometheus_settings_->prometheus_listen_addr);
}

std::string identifier() const override {
return "logdevice-prometheus";
}

std::string displayName() const override {
return "Logdevice Prometheus";
}

virtual void addOptions(SettingsUpdater* updater) override {
updater->registerSettings(prometheus_settings_);
}

private:
UpdateableSettings<PrometheusSettings> prometheus_settings_;
};

}} // namespace facebook::logdevice
41 changes: 41 additions & 0 deletions logdevice/plugins/prometheus/src/PrometheusSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2017-present, Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @author Mohamed Bassem
*/

#include <logdevice/common/settings/UpdateableSettings.h>

namespace facebook { namespace logdevice {

class PrometheusSettings : public SettingsBundle {
public:
virtual const char* getName() const override {
return "Prometheus";
}

virtual void defineSettings(SettingEasyInit& init) {
using namespace SettingFlag;

// TODO add support for push model for clients
init("prometheus-listen-addr",
&prometheus_listen_addr,
"",
nullptr,
"The address that the prometheus exposer will listen on",
SERVER | CLIENT | REQUIRES_RESTART,
SettingsCategory::Monitoring);
}

virtual ~PrometheusSettings() override {}

std::string prometheus_listen_addr;
};

}} // namespace facebook::logdevice
Loading