diff --git a/exporters/geneva/CMakeLists.txt b/exporters/geneva/CMakeLists.txt index 57f3eba7c..b3d6a32b4 100644 --- a/exporters/geneva/CMakeLists.txt +++ b/exporters/geneva/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.12) # (using add_subdirectory) or if it is the main project # set(MAIN_PROJECT OFF) -set(MAIN_PROJECT OFF) + if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(opentelemetry-geneva-metrics) set(MAIN_PROJECT ON) @@ -13,6 +13,7 @@ endif() if(NOT WIN32) find_package(CURL REQUIRED) endif() + add_definitions(-DHAVE_CONSOLE_LOG) if(MAIN_PROJECT) find_package(opentelemetry-cpp REQUIRED) @@ -31,13 +32,18 @@ else() src/exporter.cc src/unix_domain_socket_data_transport.cc) endif() -target_include_directories(opentelemetry_exporter_geneva_metrics - PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) -target_link_libraries(opentelemetry_exporter_geneva_metrics +if(MAIN_PROJECT) + target_include_directories(opentelemetry_exporter_geneva_metrics + PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) + target_link_libraries(opentelemetry_exporter_geneva_metrics PUBLIC ${OPENTELEMETRY_CPP_LIBRARIES}) +else() + target_link_libraries(opentelemetry_exporter_geneva_metrics + PUBLIC opentelemetry_metrics opentelemetry_resources opentelemetry_common) +endif() + set_target_properties(opentelemetry_exporter_geneva_metrics PROPERTIES EXPORT_NAME metrics) - if(BUILD_TESTING) if(EXISTS ${CMAKE_BINARY_DIR}/lib/libgtest.a) # Prefer GTest from build tree. GTest is not always working with @@ -90,3 +96,7 @@ if(BUILD_EXAMPLE) example/foo_library.cc) target_link_libraries(example_metrics opentelemetry_exporter_geneva_metrics) endif() +if(MAIN_PROJECT AND BUILD_PACKAGE) + include(cmake/package.cmake) + include(CPack) +endif() \ No newline at end of file diff --git a/exporters/geneva/cmake/ParseOsRelease.cmake b/exporters/geneva/cmake/ParseOsRelease.cmake new file mode 100644 index 000000000..fafbfd57f --- /dev/null +++ b/exporters/geneva/cmake/ParseOsRelease.cmake @@ -0,0 +1,22 @@ +# Parse /etc/os-release to determine Linux distro + +if(EXISTS /etc/os-release) +file(STRINGS /etc/os-release OS_RELEASE) +foreach(NameAndValue ${OS_RELEASE}) + # Strip leading spaces + string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) + # Find variable name + string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) + # Find the value + string(REPLACE "${Name}=" "" Value ${NameAndValue}) + # Strip quotes from value + string(REPLACE "\"" "" Value ${Value}) + # Set the variable + message("-- /etc/os-release : ${Name}=${Value}") + set("OS_RELEASE_${Name}" "${Value}") +endforeach() +else() + set("OS_RELEASE_NAME" ${CMAKE_SYSTEM_NAME}) + set("OS_RELEASE_ID" ${CMAKE_SYSTEM_NAME}) + set("OS_RELEASE_VERSION_ID" "1.0") +endif() \ No newline at end of file diff --git a/exporters/geneva/cmake/package.cmake b/exporters/geneva/cmake/package.cmake new file mode 100644 index 000000000..3f134a4fb --- /dev/null +++ b/exporters/geneva/cmake/package.cmake @@ -0,0 +1,71 @@ +set(CPACK_PACKAGE_DESCRIPTION "OpenTelemetry C++ Geneva Exporter for Metrics") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenTelemetry C++ Geneva Exporter for Metrics - C++ Implementation of OpenTelemetry C++ Exporter to Upload Metics to Geneva") +set(CPACK_PACKAGE_VENDOR "OpenTelemetry") +set(CPACK_PACKAGE_CONTACT "OpenTelemetry-cpp") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://opentelemetry.io/") +set(CMAKE_PROJECT_NAME "opentelemetry-cpp-geneva-metrics") +set(OPENTELEMETRY_GENEVA_METRICS_VERSION "1.0.0") + +option(TARBALL "Build a tarball package" OFF) + +if (UNIX AND NOT APPLE) + include(cmake/ParseOsRelease.cmake) + set(CPACK_SYSTEM_NAME "${OS_RELEASE_ID}-${OS_RELEASE_VERSION_ID}") + #set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") + set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENTELEMETRY_GENEVA_METRICS_VERSION}-${CPACK_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") + + # Check if system is deb or rpm capable + find_program(RPMCAPABLE rpmbuild) + find_program(DEBCAPABLE dpkg-buildpackage) + if (TARBALL) + set(CPACK_GENERATOR "TGZ") + message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.tar.gz") + elseif (DEBCAPABLE MATCHES "NOTFOUND" AND RPMCAPABLE MATCHES "NOTFOUND") + message(FATAL_ERROR "Required Package generator not found for either deb or rpm." + " Install required package generation software and try again") + elseif (NOT DEBCAPABLE MATCHES "NOTFOUND") + if (NOT RPMCAPABLE MATCHES "NOTFOUND") + message(WARNING "Both deb and rpm package generator found." + "Selecting deb as default packager.") + endif() + set(CPACK_GENERATOR "DEB") + set(INSTALL_LIB_DIR + ${CMAKE_INSTALL_PREFIX}/lib/${CPACK_DEBIAN_ARCHITECTURE}-linux-gnu) + set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") + set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + #set(CPACK_COMPONENTS_ALL headers libraries) + set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.deb") + elseif(NOT RPMCAPABLE MATCHES "NOTFOUND") + set(CPACK_GENERATOR "RPM") + set(INSTALL_LIB_DIR + ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) + list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib64/cmake") + list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib64/pkgconfig") + set(CPACK_RPM_PACKAGE_LICENSE "Apache-2.0") + message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.rpm") + endif() +elseif(APPLE) + if (TARBALL) + set(CPACK_GENERATOR "TGZ") + message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.tar.gz") + endif() +elseif(WIN32) + find_program(NUGETCAPABLE nuget) + if(NOT NUGETCAPABLE MATCHES "NOTFOUND") + set(CPACK_NUGET_PACKAGE_NAME "${CPACK_PROJECT_NAME}") + set(CPACK_NUGET_PACKAGE_VERSION "${OPENTELEMETRY_GENEVA_METRICS_VERSION}") + set(CPACK_NUGET_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}") + set(CPACK_NUGET_PACKAGE_AUTHORS "${CPACK_PACKAGE_VENDOR}") + set(CPACK_NUGET_PACKAGE_TITLE "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") + set(CPACK_NUGET_PACKAGE_OWNERS "${CPACK_PACKAGE_VENDOR}") + set(CPACK_NUGET_PACKAGE_HOMEPAGE_URL "${CPACK_PACKAGE_HOMEPAGE_URL}") + set(CPACK_NUGET_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") + set(CPACK_NUGET_PACKAGE_COPYRIGHT "${CPACK_PACKAGE_VENDOR}") + set(CPACK_NUGET_PACKAGE_LICENSEURL "https://www.apache.org/licenses/LICENSE-2.0.txt") + set(CPACK_NUGET_PACKAGE_LANGUAGE "en_US") + set(CPACK_GENERATOR NuGet) + else() + set(CPACK_GENERATOR ZIP) + endif() +endif() \ No newline at end of file diff --git a/exporters/geneva/include/opentelemetry/exporters/geneva/metrics/exporter.h b/exporters/geneva/include/opentelemetry/exporters/geneva/metrics/exporter.h index e780c5acd..855eb9467 100644 --- a/exporters/geneva/include/opentelemetry/exporters/geneva/metrics/exporter.h +++ b/exporters/geneva/include/opentelemetry/exporters/geneva/metrics/exporter.h @@ -81,7 +81,7 @@ class Exporter final : public opentelemetry::sdk::metrics::PushMetricExporter { size_t SerializeHistogramMetrics( sdk::metrics::AggregationType, MetricsEventType, uint64_t, const sdk::metrics::ValueType &, const sdk::metrics::ValueType &, - const sdk::metrics::ValueType &, const std::list &boundaries, + const sdk::metrics::ValueType &, const std::vector &boundaries, const std::vector &counts, common::SystemTimestamp, const std::string &, const sdk::metrics::PointAttributes &); }; diff --git a/exporters/geneva/src/exporter.cc b/exporters/geneva/src/exporter.cc index 32a66c8d3..8bc4e91fb 100644 --- a/exporters/geneva/src/exporter.cc +++ b/exporters/geneva/src/exporter.cc @@ -275,7 +275,7 @@ size_t Exporter::SerializeHistogramMetrics( sdk::metrics::AggregationType agg_type, MetricsEventType event_type, uint64_t count, const sdk::metrics::ValueType &sum, const sdk::metrics::ValueType &min, const sdk::metrics::ValueType &max, - const std::list &boundaries, const std::vector &counts, + const std::vector &boundaries, const std::vector &counts, common::SystemTimestamp ts, const std::string &metric_name, const sdk::metrics::PointAttributes &attributes) { diff --git a/exporters/geneva/test/common/generate_metrics.h b/exporters/geneva/test/common/generate_metrics.h index ac5e1604f..588e3c26e 100644 --- a/exporters/geneva/test/common/generate_metrics.h +++ b/exporters/geneva/test/common/generate_metrics.h @@ -3,6 +3,8 @@ #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/resource/resource.h" +#include + namespace { // Instrument Scope @@ -222,7 +224,7 @@ const uint16_t kHistogramLongBucketSize = 10; const uint16_t kHistogramLongNonEmptyBucketSize = 8; const std::vector kHistogramLongCounts = {1, 2, 1, 0, 0, 1, 2, 3, 4, 1}; -const std::list kHistogramLongBoundaries = std::list{ +const std::vector kHistogramLongBoundaries = std::vector{ 0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0}; const std::string kHistogramLongAttributeKey1 = "histogram_long_key1"; @@ -269,4 +271,4 @@ GenerateHistogramDataLongMetrics() { return data; } -} // namespace \ No newline at end of file +} // namespace