From fbdb36d35a84a679433e48d301139361aa4a9ec8 Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 17:26:03 -0500 Subject: [PATCH 01/11] add prometheus-cpp dependency --- cmake/OpenCensusDeps.cmake | 18 +++++++++++ cmake/prometheus-cpp.CMakeLists.txt | 32 +++++++++++++++++++ opencensus/exporters/stats/CMakeLists.txt | 2 +- .../exporters/stats/prometheus/CMakeLists.txt | 30 +++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 cmake/prometheus-cpp.CMakeLists.txt create mode 100644 opencensus/exporters/stats/prometheus/CMakeLists.txt diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index 4c49f167..36faf754 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -58,3 +58,21 @@ if(NOT TARGET absl::base) add_subdirectory(${CMAKE_BINARY_DIR}/abseil-src ${CMAKE_BINARY_DIR}/abseil-build EXCLUDE_FROM_ALL) endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/prometheus-cpp.CMakeLists.txt + ${CMAKE_BINARY_DIR}/prometheus-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download) +if(result) + message(FATAL_ERROR "CMake step failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download) +if(result) + message(FATAL_ERROR "Build step failed: ${result}") +endif() + +add_subdirectory(${CMAKE_BINARY_DIR}/prometheus-src + ${CMAKE_BINARY_DIR}/prometheus-build EXCLUDE_FROM_ALL) diff --git a/cmake/prometheus-cpp.CMakeLists.txt b/cmake/prometheus-cpp.CMakeLists.txt new file mode 100644 index 00000000..687b9aa1 --- /dev/null +++ b/cmake/prometheus-cpp.CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright 2018, OpenCensus Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.5) + +project(prometheus-cpp-download NONE) + +include(ExternalProject) +ExternalProject_Add(prometheus_cpp_project + GIT_REPOSITORY https://github.com/jupp0r/prometheus-cpp + GIT_TAG "v0.6.0" + SOURCE_DIR "${CMAKE_BINARY_DIR}/prometheus-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/prometheus-build" + UPDATE_COMMAND "" + PATCH_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" + LOG_DOWNLOAD ON +) diff --git a/opencensus/exporters/stats/CMakeLists.txt b/opencensus/exporters/stats/CMakeLists.txt index d87a9de4..73dd63f7 100644 --- a/opencensus/exporters/stats/CMakeLists.txt +++ b/opencensus/exporters/stats/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# add_subdirectory(prometheus) TODO +add_subdirectory(prometheus) # add_subdirectory(stackdriver) TODO diff --git a/opencensus/exporters/stats/prometheus/CMakeLists.txt b/opencensus/exporters/stats/prometheus/CMakeLists.txt new file mode 100644 index 00000000..886de519 --- /dev/null +++ b/opencensus/exporters/stats/prometheus/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright 2018, OpenCensus Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +opencensus_lib(exporters_stats_prometheus_exporter + PUBLIC + SRCS + internal/prometheus_exporter.cc + DEPS + exporters_stats_prometheus_utils + stats) + +opencensus_lib(exporters_stats_prometheus_utils + PUBLIC + SRCS + internal/prometheus_utils.cc + DEPS + stats + absl::strings + absl::time) From e44598d766b7e99150a5f3e12ff004d1e861f138 Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 17:36:19 -0500 Subject: [PATCH 02/11] tempt to pass argument to build only core library --- cmake/prometheus-cpp.CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/prometheus-cpp.CMakeLists.txt b/cmake/prometheus-cpp.CMakeLists.txt index 687b9aa1..31e0dd9d 100644 --- a/cmake/prometheus-cpp.CMakeLists.txt +++ b/cmake/prometheus-cpp.CMakeLists.txt @@ -29,4 +29,5 @@ ExternalProject_Add(prometheus_cpp_project INSTALL_COMMAND "" TEST_COMMAND "" LOG_DOWNLOAD ON + CMAKE_ARGS -DENABLE_PUSH=OFF -DENABLE_PULL=OFF -DENABLE_COMPRESSION=OFF -DENABLE_TESTING=OFF ) From f3b6b549247cb5c878141bbcc828c26bfcc73f82 Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 19:50:11 -0500 Subject: [PATCH 03/11] disable couple options for prometheus-cpp - disable building pull/push libraries - disable compression to avoid pulling dependent gzip library - disable test so it would not need to build prometheus-cpp tests --- cmake/OpenCensusDeps.cmake | 4 ++++ cmake/prometheus-cpp.CMakeLists.txt | 1 - .../exporters/stats/prometheus/CMakeLists.txt | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index 36faf754..c8a65633 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -74,5 +74,9 @@ if(result) message(FATAL_ERROR "Build step failed: ${result}") endif() +set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE) +set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE) +set(ENABLE_COMPRESSION OFF CACHE BOOL "Enable gzip compression for prometheus-cpp" FORCE) +set(ENABLE_TESTING OFF CACHE BOOL "Build test for prometheus-cpp" FORCE) add_subdirectory(${CMAKE_BINARY_DIR}/prometheus-src ${CMAKE_BINARY_DIR}/prometheus-build EXCLUDE_FROM_ALL) diff --git a/cmake/prometheus-cpp.CMakeLists.txt b/cmake/prometheus-cpp.CMakeLists.txt index 31e0dd9d..687b9aa1 100644 --- a/cmake/prometheus-cpp.CMakeLists.txt +++ b/cmake/prometheus-cpp.CMakeLists.txt @@ -29,5 +29,4 @@ ExternalProject_Add(prometheus_cpp_project INSTALL_COMMAND "" TEST_COMMAND "" LOG_DOWNLOAD ON - CMAKE_ARGS -DENABLE_PUSH=OFF -DENABLE_PULL=OFF -DENABLE_COMPRESSION=OFF -DENABLE_TESTING=OFF ) diff --git a/opencensus/exporters/stats/prometheus/CMakeLists.txt b/opencensus/exporters/stats/prometheus/CMakeLists.txt index 886de519..23cbf744 100644 --- a/opencensus/exporters/stats/prometheus/CMakeLists.txt +++ b/opencensus/exporters/stats/prometheus/CMakeLists.txt @@ -27,4 +27,17 @@ opencensus_lib(exporters_stats_prometheus_utils DEPS stats absl::strings - absl::time) + absl::time + prometheus-cpp::core) + +opencensus_lib(exporters_stats_prometheus_test_server + internal/exporters_stats_prometheus_test_server.cc + stats + absl::time + prometheus-cpp::core) + +opencensus_test(exporters_stats_prometheus_utils_test + internal/prometheus_utils_test.cc + exporters_stats_prometheus_utils + stats + stats_test_utils) From 2a252dda0b88b4cb997c2c856b2ed5f5f51113ba Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 21:16:58 -0500 Subject: [PATCH 04/11] fix long line --- cmake/OpenCensusDeps.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index c8a65633..82962bfa 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -76,7 +76,9 @@ endif() set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE) set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE) -set(ENABLE_COMPRESSION OFF CACHE BOOL "Enable gzip compression for prometheus-cpp" FORCE) +set(ENABLE_COMPRESSION OFF + CACHE BOOL "Enable gzip compression for prometheus-cpp" + FORCE) set(ENABLE_TESTING OFF CACHE BOOL "Build test for prometheus-cpp" FORCE) add_subdirectory(${CMAKE_BINARY_DIR}/prometheus-src ${CMAKE_BINARY_DIR}/prometheus-build EXCLUDE_FROM_ALL) From 713c14daa58c0924e123c47faf00bdb7bc2f3462 Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 22:35:15 -0500 Subject: [PATCH 05/11] use master for git_tag to build from HEAD --- cmake/prometheus-cpp.CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/prometheus-cpp.CMakeLists.txt b/cmake/prometheus-cpp.CMakeLists.txt index 687b9aa1..f777bf11 100644 --- a/cmake/prometheus-cpp.CMakeLists.txt +++ b/cmake/prometheus-cpp.CMakeLists.txt @@ -19,7 +19,7 @@ project(prometheus-cpp-download NONE) include(ExternalProject) ExternalProject_Add(prometheus_cpp_project GIT_REPOSITORY https://github.com/jupp0r/prometheus-cpp - GIT_TAG "v0.6.0" + GIT_TAG "master" SOURCE_DIR "${CMAKE_BINARY_DIR}/prometheus-src" BINARY_DIR "${CMAKE_BINARY_DIR}/prometheus-build" UPDATE_COMMAND "" From f723526cb0767f26f60e0be589f57f23b95df52c Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 22:37:59 -0500 Subject: [PATCH 06/11] make library name consistent --- opencensus/exporters/stats/prometheus/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencensus/exporters/stats/prometheus/CMakeLists.txt b/opencensus/exporters/stats/prometheus/CMakeLists.txt index 23cbf744..6afe6322 100644 --- a/opencensus/exporters/stats/prometheus/CMakeLists.txt +++ b/opencensus/exporters/stats/prometheus/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -opencensus_lib(exporters_stats_prometheus_exporter +opencensus_lib(exporters_stats_prometheus PUBLIC SRCS internal/prometheus_exporter.cc From a14cbd6dff2ec7e60c3dfcc681f3735cbcf3219d Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 22:39:29 -0500 Subject: [PATCH 07/11] fix: prometheus_utils library is not public library --- opencensus/exporters/stats/prometheus/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/opencensus/exporters/stats/prometheus/CMakeLists.txt b/opencensus/exporters/stats/prometheus/CMakeLists.txt index 6afe6322..40bdeea3 100644 --- a/opencensus/exporters/stats/prometheus/CMakeLists.txt +++ b/opencensus/exporters/stats/prometheus/CMakeLists.txt @@ -21,7 +21,6 @@ opencensus_lib(exporters_stats_prometheus stats) opencensus_lib(exporters_stats_prometheus_utils - PUBLIC SRCS internal/prometheus_utils.cc DEPS From 952778b52b75bb2f585fe24f99b54a226838dbca Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 22:40:21 -0500 Subject: [PATCH 08/11] prometheus-cpp's pull library is needed --- cmake/OpenCensusDeps.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index 82962bfa..978f5423 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -74,7 +74,6 @@ if(result) message(FATAL_ERROR "Build step failed: ${result}") endif() -set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE) set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE) set(ENABLE_COMPRESSION OFF CACHE BOOL "Enable gzip compression for prometheus-cpp" From 35f06422f1043e282633e68261fde46877813994 Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 22:41:39 -0500 Subject: [PATCH 09/11] remove build rule for test_server because it is binary, not library --- opencensus/exporters/stats/prometheus/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/opencensus/exporters/stats/prometheus/CMakeLists.txt b/opencensus/exporters/stats/prometheus/CMakeLists.txt index 40bdeea3..4da7de72 100644 --- a/opencensus/exporters/stats/prometheus/CMakeLists.txt +++ b/opencensus/exporters/stats/prometheus/CMakeLists.txt @@ -29,12 +29,6 @@ opencensus_lib(exporters_stats_prometheus_utils absl::time prometheus-cpp::core) -opencensus_lib(exporters_stats_prometheus_test_server - internal/exporters_stats_prometheus_test_server.cc - stats - absl::time - prometheus-cpp::core) - opencensus_test(exporters_stats_prometheus_utils_test internal/prometheus_utils_test.cc exporters_stats_prometheus_utils From f94d85947a64c595c90bfb73d7a2edc8faeffb9b Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 23:24:56 -0500 Subject: [PATCH 10/11] still remove prometheus-cpp pull library becausewe do not build with binary yet --- cmake/OpenCensusDeps.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index 978f5423..5b36fdde 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -75,6 +75,7 @@ if(result) endif() set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE) +set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE) set(ENABLE_COMPRESSION OFF CACHE BOOL "Enable gzip compression for prometheus-cpp" FORCE) From 647984f9c4e6d755879babcf07cd907751bdf3de Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Tue, 4 Dec 2018 23:26:10 -0500 Subject: [PATCH 11/11] add guard so user of opencensus-cpp can use their own prometheus-cpp if needed --- cmake/OpenCensusDeps.cmake | 48 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index 5b36fdde..35bf8106 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -59,26 +59,30 @@ if(NOT TARGET absl::base) ${CMAKE_BINARY_DIR}/abseil-build EXCLUDE_FROM_ALL) endif() -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/prometheus-cpp.CMakeLists.txt - ${CMAKE_BINARY_DIR}/prometheus-download/CMakeLists.txt) -execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download) -if(result) - message(FATAL_ERROR "CMake step failed: ${result}") -endif() -execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download) -if(result) - message(FATAL_ERROR "Build step failed: ${result}") -endif() +if(NOT TARGET prometheus-cpp::core) + message(STATUS "Dependency: prometheus-cpp") + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/prometheus-cpp.CMakeLists.txt + ${CMAKE_BINARY_DIR}/prometheus-download/CMakeLists.txt) + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download) + if(result) + message(FATAL_ERROR "CMake step failed: ${result}") + endif() + execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prometheus-download) + if(result) + message(FATAL_ERROR "Build step failed: ${result}") + endif() -set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE) -set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE) -set(ENABLE_COMPRESSION OFF - CACHE BOOL "Enable gzip compression for prometheus-cpp" - FORCE) -set(ENABLE_TESTING OFF CACHE BOOL "Build test for prometheus-cpp" FORCE) -add_subdirectory(${CMAKE_BINARY_DIR}/prometheus-src - ${CMAKE_BINARY_DIR}/prometheus-build EXCLUDE_FROM_ALL) + set(ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE) + set(ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE) + set(ENABLE_COMPRESSION OFF + CACHE BOOL "Enable gzip compression for prometheus-cpp" + FORCE) + set(ENABLE_TESTING OFF CACHE BOOL "Build test for prometheus-cpp" FORCE) + add_subdirectory(${CMAKE_BINARY_DIR}/prometheus-src + ${CMAKE_BINARY_DIR}/prometheus-build EXCLUDE_FROM_ALL) +endif()