Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit f449234

Browse files
StevenYCChoug-easy
authored andcommitted
Add CMake support for prometheus exporter (#249)
This resolved only part of #249, because the build rule for prometheus_test_server is not added yet.
1 parent 11f65c8 commit f449234

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

cmake/OpenCensusDeps.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,31 @@ if(NOT TARGET absl::base)
5858
add_subdirectory(${CMAKE_BINARY_DIR}/abseil-src
5959
${CMAKE_BINARY_DIR}/abseil-build EXCLUDE_FROM_ALL)
6060
endif()
61+
62+
if(NOT TARGET prometheus-cpp::core)
63+
message(STATUS "Dependency: prometheus-cpp")
64+
65+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/prometheus-cpp.CMakeLists.txt
66+
${CMAKE_BINARY_DIR}/prometheus-download/CMakeLists.txt)
67+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
68+
RESULT_VARIABLE result
69+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download)
70+
if(result)
71+
message(FATAL_ERROR "CMake step failed: ${result}")
72+
endif()
73+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
74+
RESULT_VARIABLE result
75+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download)
76+
if(result)
77+
message(FATAL_ERROR "Build step failed: ${result}")
78+
endif()
79+
80+
set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE)
81+
set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE)
82+
set(ENABLE_COMPRESSION OFF
83+
CACHE BOOL "Enable gzip compression for prometheus-cpp"
84+
FORCE)
85+
set(ENABLE_TESTING OFF CACHE BOOL "Build test for prometheus-cpp" FORCE)
86+
add_subdirectory(${CMAKE_BINARY_DIR}/prometheus-src
87+
${CMAKE_BINARY_DIR}/prometheus-build EXCLUDE_FROM_ALL)
88+
endif()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cmake_minimum_required(VERSION 3.5)
16+
17+
project(prometheus-cpp-download NONE)
18+
19+
include(ExternalProject)
20+
ExternalProject_Add(prometheus_cpp_project
21+
GIT_REPOSITORY https://github.com/jupp0r/prometheus-cpp
22+
GIT_TAG "master"
23+
SOURCE_DIR "${CMAKE_BINARY_DIR}/prometheus-src"
24+
BINARY_DIR "${CMAKE_BINARY_DIR}/prometheus-build"
25+
UPDATE_COMMAND ""
26+
PATCH_COMMAND ""
27+
CONFIGURE_COMMAND ""
28+
BUILD_COMMAND ""
29+
INSTALL_COMMAND ""
30+
TEST_COMMAND ""
31+
LOG_DOWNLOAD ON
32+
)

opencensus/exporters/stats/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# add_subdirectory(prometheus) TODO
15+
add_subdirectory(prometheus)
1616

1717
# add_subdirectory(stackdriver) TODO
1818

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2018, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
opencensus_lib(exporters_stats_prometheus
16+
PUBLIC
17+
SRCS
18+
internal/prometheus_exporter.cc
19+
DEPS
20+
exporters_stats_prometheus_utils
21+
stats)
22+
23+
opencensus_lib(exporters_stats_prometheus_utils
24+
SRCS
25+
internal/prometheus_utils.cc
26+
DEPS
27+
stats
28+
absl::strings
29+
absl::time
30+
prometheus-cpp::core)
31+
32+
opencensus_test(exporters_stats_prometheus_utils_test
33+
internal/prometheus_utils_test.cc
34+
exporters_stats_prometheus_utils
35+
stats
36+
stats_test_utils)

0 commit comments

Comments
 (0)