Skip to content

Commit

Permalink
build: Get Prometheus externally
Browse files Browse the repository at this point in the history
Previously it required you to have the library installed on the system.
Using FetchContent in CMake, it is now acquired externally if the CMake
config doesnot exist on the system and the build option is correctly set
(which it is by default). This will statically compile the library into
the binary.
  • Loading branch information
uristdwarf committed Dec 13, 2024
1 parent 891575b commit c2e4813
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 33 deletions.
61 changes: 33 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,32 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
)
endif()

option(ENABLE_WERROR "Enable treating compilation warnings as errors" OFF)
option(ENABLE_LIGHTSFS "Enable light version of SaunaFS" OFF)
option(ENABLE_UTILS "Enable building additional binaries used e.g. in tests" OFF)
option(ENABLE_TESTS "Enable building unit and functional tests" OFF)
option(ENABLE_DOCS "Enable building the documentation" ON)
option(ENABLE_EXIT_ON_USR1 "Enable handler for SIGUSR1 which calls exit()" OFF)
option(THROW_INSTEAD_OF_ABORT "Throw std::exception instead of calling abort" OFF)
option(ENABLE_DEBUG_LOG "Enable prefix based debug logs" OFF)
option(ENABLE_URAFT "Enable installation of uraft util" ON)
option(ENABLE_VERBOSE_ASCIIDOC "Enable verbose output of asciidoc" OFF)
option(ENABLE_TCMALLOC "Enable use of tcmalloc-minimal library" OFF)
option(ENABLE_JEMALLOC "Enable use of jemalloc library" OFF)
option(ENABLE_POLONAISE "Enable polonaise" ON)
option(ENABLE_CLIENT_LIB "Enable dynamic client library (libsaunafs-client)" OFF)
option(ENABLE_WERROR "Enable treating compilation warnings as errors" OFF)
option(ENABLE_LIGHTSFS "Enable light version of SaunaFS" OFF)
option(ENABLE_UTILS "Enable building additional binaries used e.g. in tests" OFF)
option(ENABLE_TESTS "Enable building unit and functional tests" OFF)
option(ENABLE_DOCS "Enable building the documentation" ON)
option(ENABLE_EXIT_ON_USR1 "Enable handler for SIGUSR1 which calls exit()" OFF)
option(THROW_INSTEAD_OF_ABORT "Throw std::exception instead of calling abort" OFF)
option(ENABLE_DEBUG_LOG "Enable prefix based debug logs" OFF)
option(ENABLE_URAFT "Enable installation of uraft util" ON)
option(ENABLE_VERBOSE_ASCIIDOC "Enable verbose output of asciidoc" OFF)
option(ENABLE_TCMALLOC "Enable use of tcmalloc-minimal library" OFF)
option(ENABLE_JEMALLOC "Enable use of jemalloc library" OFF)
option(ENABLE_POLONAISE "Enable polonaise" ON)
option(ENABLE_CLIENT_LIB "Enable dynamic client library (libsaunafs-client)" OFF)
# end of SaunaFS options
option(ENABLE_TRACES "Enable traces" OFF)
option(ENABLE_SYSLOG_FOR_TRACES "Enable usage of syslog instead of stdout for traces" OFF)
option(ENABLE_CRC "Enable checksums" ON)
option(ENABLE_REQUEST_LOG "Enable logging request times" OFF)
option(USE_LEGACY_READ_MESSAGES "Enable sending old type of messages by mount" OFF)
option(ENABLE_NFS_GANESHA "Enable nfs-ganesha plugin" OFF)
option(ENABLE_CCACHE "Enable ccache during compilation" ON)
option(ENABLE_NFS_ACL_SUPPORT "Enable nfs-ganesha ACL support" ON)
option(ENABLE_COMPILE_COMMANDS "Enable generation of compile_commands.json" ON)
option(ENABLE_PROMETHEUS "Enable prometheus metrics" ON)
option(ENABLE_TRACES "Enable traces" OFF)
option(ENABLE_SYSLOG_FOR_TRACES "Enable usage of syslog instead of stdout for traces" OFF)
option(ENABLE_CRC "Enable checksums" ON)
option(ENABLE_REQUEST_LOG "Enable logging request times" OFF)
option(USE_LEGACY_READ_MESSAGES "Enable sending old type of messages by mount" OFF)
option(ENABLE_NFS_GANESHA "Enable nfs-ganesha plugin" OFF)
option(ENABLE_CCACHE "Enable ccache during compilation" ON)
option(ENABLE_NFS_ACL_SUPPORT "Enable nfs-ganesha ACL support" ON)
option(ENABLE_COMPILE_COMMANDS "Enable generation of compile_commands.json" ON)
option(ENABLE_PROMETHEUS "Enable prometheus metrics" ON)
option(USE_SYSTEM_PROMETHEUS "If prometheus is enabled, use system external library if possible" ON)

option(GENERATE_GIT_INFO "Generate git info from current repository (for version commands)" ON)

Expand Down Expand Up @@ -351,11 +352,15 @@ set(CHARTS_CSV_CHARTID_BASE 90000)
# Internal capability required by some FSALs
set(GSH_CAN_HOST_LOCAL_FS ${ENABLE_NFS_GANESHA})

if (ENABLE_PROMETHEUS AND NOT PROMETHEUS_CPP_ENABLE_PULL)
message(STATUS "Prometheus C++ Client Library: Enabled but not found")
elseif(ENABLE_PROMETHEUS)
if (ENABLE_PROMETHEUS AND NOT PROMETHEUS_CPP_ENABLE_PULL AND NOT USE_SYSTEM_PROMETHEUS)
message(STATUS "Prometheus C++ Client Library: Enabled (but getting it externally)")
add_definitions(-DHAVE_PROMETHEUS)
message(STATUS "Prometheus C++ Client Library: Enabled")
elseif(ENABLE_PROMETHEUS AND PROMETHEUS_CPP_ENABLE_PULL)
add_definitions(-DHAVE_PROMETHEUS)
message(STATUS "Prometheus C++ Client Library: Enabled (using system)")
elseif(ENABLE_PROMETHEUS AND NOT SYSTEM_PROMETHEUS)
add_definitions(-DHAVE_PROMETHEUS)
message(STATUS "Prometheus C++ Client Library: Could not find system, using external")
else()
message(STATUS "Prometheus C++ Client Library: Disabled")
endif()
Expand Down
11 changes: 8 additions & 3 deletions cmake/Libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,14 @@ if(ENABLE_NFS_GANESHA)
"https://github.com/nfs-ganesha/ntirpc/archive/v4.3.zip")
endif()

# Get prometheus-cpp
find_package(prometheus-cpp CONFIG)
if (PROMETHEUS_CPP_ENABLE_PULL)
message(STATUS "Found Prometheus C++ Client Library")
if (PROMETHEUS_CPP_ENABLE_PULL AND USE_SYSTEM_PROMETHEUS)
set(SYSTEM_PROMETHEUS true)
message(STATUS "Found system Prometheus C++ Client Library (using it)")
elseif(PROMETHEUS_CPP_ENABLE_PULL AND NOT USE_SYSTEM_PROMETHEUS)
message(STATUS "Found system Prometheus C++ Client Library (however not using it)")
else()
message(STATUS "Did not find Prometheus C++ Client Library (but not needed)")
set(SYSTEM_PROMETHEUS false)
message(STATUS "Did not find system Prometheus C++ Client Library")
endif()
2 changes: 1 addition & 1 deletion src/metarestore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_library(metarestore ${METARESTORE_SOURCES} ${METARESTORE_MASTER_SOURCES} ${M
../master/restore.cc ../master/locks.cc ../master/task_manager.cc ../master/snapshot_task.cc
../master/metadata_loader.cc ../master/setgoal_task.cc ../master/settrashtime_task.cc)

target_link_libraries(metarestore sfscommon)
target_link_libraries(metarestore metrics sfscommon)
if(JUDY_LIBRARY)
target_link_libraries(metarestore ${JUDY_LIBRARY})
endif()
Expand Down
22 changes: 21 additions & 1 deletion src/metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,31 @@
# along with SaunaFS If not, see <http://www.gnu.org/licenses/>.

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if (ENABLE_PROMETHEUS AND NOT SYSTEM_PROMETHEUS)
include(FetchContent)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(ENABLE_PULL ON CACHE BOOL "" FORCE)
set(ENABLE_PUSH OFF CACHE BOOL "" FORCE)
set(ENABLE_COMPRESSION ON CACHE BOOL "" FORCE)

FetchContent_Declare(
prometheus-cpp
GIT_REPOSITORY https://github.com/jupp0r/prometheus-cpp.git
GIT_TAG e5fada43131d251e9c4786b04263ce98b6767ba5 # v.1.3.0
)
FetchContent_MakeAvailable(prometheus-cpp)

unset(BUILD_SHARED_LIBS)
unset(ENABLE_PULL)
unset(ENABLE_PUSH)
unset(ENABLE_COMPRESSION)

endif()

collect_sources(METRICS)

add_library(metrics ${METRICS_SOURCES})

if (PROMETHEUS_CPP_ENABLE_PULL)
if (ENABLE_PROMETHEUS)
target_link_libraries(metrics slogger prometheus-cpp::pull)
endif()

0 comments on commit c2e4813

Please sign in to comment.