From 7095cf3802b2854d7a9e90fd3aa4e1a13f4f6d81 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 27 Jun 2023 23:03:32 +0200 Subject: [PATCH 1/8] Fixes #2184 --- CMakeLists.txt | 57 +++++++++++++++++-- api/CMakeLists.txt | 4 ++ .../opentelemetry/metrics/meter_provider.h | 6 ++ api/include/opentelemetry/metrics/noop.h | 7 +++ api/include/opentelemetry/version.h | 5 +- .../otlp_grpc_log_record_exporter_test.cc | 6 +- .../opentelemetry/sdk/metrics/meter_context.h | 4 ++ .../sdk/metrics/meter_provider.h | 11 ++++ sdk/src/metrics/meter_context.cc | 21 +++++++ sdk/src/metrics/meter_provider.cc | 15 +++++ sdk/test/logs/log_record_test.cc | 4 +- 11 files changed, 128 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e0be94a6..cdf774694d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,17 +89,46 @@ if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE) include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") endif() +# +# ABI VERSION 1 is frozen, and can not change. +# +# For fixes or features that causes an API/ABI breaking change, +# the change is implemented in ABI VERSION 2. +# +# ABI VERSION 2 is still experimental, unstable, +# and will by definition change when more breaking changes +# are implemented. +# +# When version 2 is sufficiently mature and contains a coherent +# set of new features, it will be marked stable and published. +# +# The goal is to avoid incrementing the ABI version on individual fixes, +# and release a stable set less frequently, to minimize disruption to users. +# +# Until ABI_VERSION_2 is marked stable, use WITH_ABI_VERSION_2_PREVIEW=ON +# at your own risk, as there are no compatibility guarantees. +# +option(WITH_ABI_VERSION_2_PREVIEW "EXPERIMENTAL: ABI version 2 preview" OFF) + file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" OPENTELEMETRY_CPP_HEADER_VERSION_H) -if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES - "OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?") - math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1}) + +if (WITH_ABI_VERSION_2_PREVIEW) + set(OPENTELEMETRY_ABI_VERSION_NO "2") else() - message( - FATAL_ERROR + if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES + "OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?") + math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1}) + else() + message( + FATAL_ERROR "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" - ) + ) + endif() endif() + +message(STATUS "OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO}") + if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES "OPENTELEMETRY_VERSION[ \t\r\n]+\"?([^\"]+)\"?") set(OPENTELEMETRY_VERSION ${CMAKE_MATCH_1}) @@ -110,6 +139,8 @@ else() ) endif() +message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}") + option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF) option(WITH_STL "Whether to use Standard Library for C++ latest features" OFF) @@ -265,6 +296,20 @@ if(WITH_OTLP_HTTP_SSL_TLS_PREVIEW AND NOT WITH_OTLP_HTTP_SSL_PREVIEW) ) endif() +# +# ABI_VERSION_2 is not stable, do not build shared libraries with it. +# +if(OTELCPP_VERSIONED_LIBS AND WITH_ABI_VERSION_2_PREVIEW) + message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires WITH_ABI_VERSION_2_PREVIEW=OFF") +endif() + +# +# ABI_VERSION_2 is not stable, do not build DLL with it. +# +if(DEFINED OPENTELEMETRY_BUILD_DLL AND WITH_ABI_VERSION_2_PREVIEW) + message(FATAL_ERROR "OPENTELEMETRY_BUILD_DLL requires WITH_ABI_VERSION_2_PREVIEW=OFF") +endif() + find_package(Threads) function(install_windows_deps) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 31863b25e3..591af2bbee 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -98,6 +98,10 @@ if(WITH_ASYNC_EXPORT_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT) endif() +if(WITH_ABI_VERSION_2_PREVIEW) + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_ABI_VERSION_NO=2) +endif() + # A better place should be in sdk, not api if(WITH_OTLP_HTTP_SSL_PREVIEW) target_compile_definitions(opentelemetry_api diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index 654c4022ea..b24263be71 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -29,6 +29,12 @@ class MeterProvider virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + virtual void RemoveMeter(nostd::string_view library_name, + nostd::string_view library_version = "", + nostd::string_view schema_url = "") noexcept = 0; +#endif }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 3a754a6e00..0e373f24a1 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -203,6 +203,13 @@ class NoopMeterProvider final : public MeterProvider return meter_; } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void RemoveMeter(nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */) noexcept override + {} +#endif + private: nostd::shared_ptr meter_; }; diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index 2178591728..0ff8d71d32 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -6,7 +6,10 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/detail/preprocessor.h" -#define OPENTELEMETRY_ABI_VERSION_NO 1 +#ifndef OPENTELEMETRY_ABI_VERSION_NO +# define OPENTELEMETRY_ABI_VERSION_NO 1 +#endif + #define OPENTELEMETRY_VERSION "1.9.1" #define OPENTELEMETRY_VERSION_MAJOR 1 #define OPENTELEMETRY_VERSION_MINOR 9 diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index f2ed416327..518caaba5e 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -154,7 +154,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) std::unique_ptr trace_stub_interface( trace_mock_stub); - auto trace_provider = opentelemetry::nostd::shared_ptr( + auto trace_provider = opentelemetry::nostd::shared_ptr( opentelemetry::sdk::trace::TracerProviderFactory::Create( opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create( GetExporter(trace_stub_interface)))); @@ -174,7 +174,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); - std::unordered_map attributes; + std::unordered_map attributes; attributes["service.name"] = "unit_test_service"; attributes["tenant.id"] = "test_user"; attributes["bool_value"] = true; @@ -197,7 +197,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) opentelemetry::trace::Provider::SetTracerProvider( opentelemetry::nostd::shared_ptr( new opentelemetry::trace::NoopTracerProvider())); - trace_provider = opentelemetry::nostd::shared_ptr(); + trace_provider = opentelemetry::nostd::shared_ptr(); } } // namespace otlp diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context.h b/sdk/include/opentelemetry/sdk/metrics/meter_context.h index 8155b4da9f..336f5da7a0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -115,6 +115,10 @@ class MeterContext : public std::enable_shared_from_this */ void AddMeter(std::shared_ptr meter); + void RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url); + /** * Force all active Collectors to flush any buffered meter data * within the given timeout. diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index fedf6aac61..bf21d3c1da 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -53,6 +53,17 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider nostd::string_view version = "", nostd::string_view schema_url = "") noexcept override; +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) noexcept override; +#else + /* Only in the SDK, not API, for ABI VERSION 1 */ + void RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) noexcept; +#endif + /** * Obtain the resource associated with this meter provider. * @return The resource for this meter provider. diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index eaf82232d6..c6526192ef 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -3,6 +3,7 @@ #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk_config.h" @@ -79,6 +80,26 @@ void MeterContext::AddMeter(std::shared_ptr meter) meters_.push_back(meter); } +void MeterContext::RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) +{ + std::lock_guard guard(meter_lock_); + + std::vector> filtered_meters; + + for (auto &meter : meters_) + { + auto scope = meter->GetInstrumentationScope(); + if (!scope->equal(name, version, schema_url)) + { + filtered_meters.push_back(meter); + } + } + + meters_.swap(filtered_meters); +} + bool MeterContext::Shutdown() noexcept { bool result = true; diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 1e9dc5f434..b8720ded15 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -57,6 +57,21 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } +void MeterProvider::RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) noexcept +{ + if (name.data() == nullptr || name == "") + { + OTEL_INTERNAL_LOG_WARN("[MeterProvider::RemoveMeter] Library name is empty."); + name = ""; + } + + const std::lock_guard guard(lock_); + + context_->RemoveMeter(name, version, schema_url); +} + const resource::Resource &MeterProvider::GetResource() const noexcept { return context_->GetResource(); diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 0e5de03050..4f7deb06d0 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -99,13 +99,13 @@ class TestBodyLogger : public opentelemetry::logs::Logger } } - const opentelemetry::v1::common::AttributeValue &GetLastLogRecord() const noexcept + const opentelemetry::common::AttributeValue &GetLastLogRecord() const noexcept { return last_body_; } private: - opentelemetry::v1::common::AttributeValue last_body_; + opentelemetry::common::AttributeValue last_body_; }; // Define a basic LoggerProvider class that returns an instance of the logger class defined above From 556da00d65547dad1dd10310846c501e68cbc24c Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 30 Jun 2023 10:49:47 +0200 Subject: [PATCH 2/8] Format, CI --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ CMakeLists.txt | 33 ++++++++++++++++++--------------- api/CMakeLists.txt | 3 ++- ci/do_ci.sh | 23 +++++++++++++++++++++++ 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ac8999459..dcff500ca2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -202,6 +202,39 @@ jobs: run: | (cd ./functional/otlp; ./run_test.sh) + cmake_clang_maintainer_abi_v2_test: + name: CMake clang 14 (maintainer mode, abi v2) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + env: + CC: /usr/bin/clang-14 + CXX: /usr/bin/clang++-14 + GOOGLETEST_VERSION: 1.12.1 + PROTOBUF_VERSION: 21.12 + run: | + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/install_protobuf.sh + - name: run cmake clang (maintainer mode, sync) + env: + CC: /usr/bin/clang-14 + CXX: /usr/bin/clang++-14 + run: | + ./ci/do_ci.sh cmake.maintainer.abiv2.test + - name: generate test cert + env: + CFSSL_VERSION: 1.6.3 + run: | + sudo -E ./tools/setup-cfssl.sh + (cd ./functional/cert; ./generate_cert.sh) + - name: run func test + run: | + (cd ./functional/otlp; ./run_test.sh) + cmake_msvc_maintainer_test: name: CMake msvc (maintainer mode) runs-on: windows-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index 33acd0695f..b9a2a5bc52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,28 +92,27 @@ endif() # # ABI VERSION 1 is frozen, and can not change. # -# For fixes or features that causes an API/ABI breaking change, -# the change is implemented in ABI VERSION 2. +# For fixes or features that causes an API/ABI breaking change, the change is +# implemented in ABI VERSION 2. # -# ABI VERSION 2 is still experimental, unstable, -# and will by definition change when more breaking changes -# are implemented. +# ABI VERSION 2 is still experimental, unstable, and will by definition change +# when more breaking changes are implemented. # -# When version 2 is sufficiently mature and contains a coherent -# set of new features, it will be marked stable and published. +# When version 2 is sufficiently mature and contains a coherent set of new +# features, it will be marked stable and published. # -# The goal is to avoid incrementing the ABI version on individual fixes, -# and release a stable set less frequently, to minimize disruption to users. +# The goal is to avoid incrementing the ABI version on individual fixes, and +# release a stable set less frequently, to minimize disruption to users. # -# Until ABI_VERSION_2 is marked stable, use WITH_ABI_VERSION_2_PREVIEW=ON -# at your own risk, as there are no compatibility guarantees. +# Until ABI_VERSION_2 is marked stable, use WITH_ABI_VERSION_2_PREVIEW=ON at +# your own risk, as there are no compatibility guarantees. # option(WITH_ABI_VERSION_2_PREVIEW "EXPERIMENTAL: ABI version 2 preview" OFF) file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" OPENTELEMETRY_CPP_HEADER_VERSION_H) -if (WITH_ABI_VERSION_2_PREVIEW) +if(WITH_ABI_VERSION_2_PREVIEW) set(OPENTELEMETRY_ABI_VERSION_NO "2") else() if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES @@ -122,7 +121,7 @@ else() else() message( FATAL_ERROR - "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" + "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" ) endif() endif() @@ -300,14 +299,18 @@ endif() # ABI_VERSION_2 is not stable, do not build shared libraries with it. # if(OTELCPP_VERSIONED_LIBS AND WITH_ABI_VERSION_2_PREVIEW) - message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires WITH_ABI_VERSION_2_PREVIEW=OFF") + message( + FATAL_ERROR + "OTELCPP_VERSIONED_LIBS=ON requires WITH_ABI_VERSION_2_PREVIEW=OFF") endif() # # ABI_VERSION_2 is not stable, do not build DLL with it. # if(DEFINED OPENTELEMETRY_BUILD_DLL AND WITH_ABI_VERSION_2_PREVIEW) - message(FATAL_ERROR "OPENTELEMETRY_BUILD_DLL requires WITH_ABI_VERSION_2_PREVIEW=OFF") + message( + FATAL_ERROR + "OPENTELEMETRY_BUILD_DLL requires WITH_ABI_VERSION_2_PREVIEW=OFF") endif() find_package(Threads) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 591af2bbee..b0dedc6232 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -99,7 +99,8 @@ if(WITH_ASYNC_EXPORT_PREVIEW) endif() if(WITH_ABI_VERSION_2_PREVIEW) - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_ABI_VERSION_NO=2) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_ABI_VERSION_NO=2) endif() # A better place should be in sdk, not api diff --git a/ci/do_ci.sh b/ci/do_ci.sh index d504b33ae8..7e23a4e1aa 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -136,6 +136,29 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then make -k -j $(nproc) make test exit 0 +elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ + -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_PROMETHEUS=ON \ + -DWITH_EXAMPLES=ON \ + -DWITH_EXAMPLES_HTTP=ON \ + -DWITH_ZIPKIN=ON \ + -DBUILD_W3CTRACECONTEXT_TEST=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_LOGS_PREVIEW=ON \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ + -DOTELCPP_MAINTAINER_MODE=ON \ + -DWITH_NO_DEPRECATED_CODE=ON \ + -DWITH_ABI_VERSION_2_PREVIEW=ON \ + "${SRC_DIR}" + make -k + make test + exit 0 elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then cd "${BUILD_DIR}" rm -rf * From febe93f25d27e748b61cdde4d9c32943711f5258 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Jul 2023 14:32:06 +0200 Subject: [PATCH 3/8] Cleanup --- .github/workflows/ci.yml | 33 ---------- CMakeLists.txt | 64 +++---------------- api/CMakeLists.txt | 4 +- .../opentelemetry/metrics/meter_provider.h | 3 +- api/include/opentelemetry/metrics/noop.h | 2 +- ci/do_ci.sh | 23 ------- 6 files changed, 13 insertions(+), 116 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2941d61850..e1666dabbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -197,39 +197,6 @@ jobs: run: | (cd ./functional/otlp; ./run_test.sh) - cmake_clang_maintainer_abi_v2_test: - name: CMake clang 14 (maintainer mode, abi v2) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - name: setup - env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 - GOOGLETEST_VERSION: 1.12.1 - PROTOBUF_VERSION: 21.12 - run: | - sudo -E ./ci/setup_cmake.sh - sudo -E ./ci/setup_ci_environment.sh - sudo -E ./ci/install_protobuf.sh - - name: run cmake clang (maintainer mode, sync) - env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 - run: | - ./ci/do_ci.sh cmake.maintainer.abiv2.test - - name: generate test cert - env: - CFSSL_VERSION: 1.6.3 - run: | - sudo -E ./tools/setup-cfssl.sh - (cd ./functional/cert; ./generate_cert.sh) - - name: run func test - run: | - (cd ./functional/otlp; ./run_test.sh) - cmake_msvc_maintainer_test: name: CMake msvc (maintainer mode) runs-on: windows-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index c81c693741..2ab09fc0dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,45 +89,17 @@ if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE) include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") endif() -# -# ABI VERSION 1 is frozen, and can not change. -# -# For fixes or features that causes an API/ABI breaking change, the change is -# implemented in ABI VERSION 2. -# -# ABI VERSION 2 is still experimental, unstable, and will by definition change -# when more breaking changes are implemented. -# -# When version 2 is sufficiently mature and contains a coherent set of new -# features, it will be marked stable and published. -# -# The goal is to avoid incrementing the ABI version on individual fixes, and -# release a stable set less frequently, to minimize disruption to users. -# -# Until ABI_VERSION_2 is marked stable, use WITH_ABI_VERSION_2_PREVIEW=ON at -# your own risk, as there are no compatibility guarantees. -# -option(WITH_ABI_VERSION_2_PREVIEW "EXPERIMENTAL: ABI version 2 preview" OFF) - file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" OPENTELEMETRY_CPP_HEADER_VERSION_H) - -if(WITH_ABI_VERSION_2_PREVIEW) - set(OPENTELEMETRY_ABI_VERSION_NO "2") +if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES + "OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?") + math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1}) else() - if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES - "OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?") - math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1}) - else() - message( - FATAL_ERROR - "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" - ) - endif() + message( + FATAL_ERROR + "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" + ) endif() - -message(STATUS "OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO}") - if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES "OPENTELEMETRY_VERSION[ \t\r\n]+\"?([^\"]+)\"?") set(OPENTELEMETRY_VERSION ${CMAKE_MATCH_1}) @@ -138,8 +110,6 @@ else() ) endif() -message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}") - option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF) option(WITH_STL "Whether to use Standard Library for C++ latest features" OFF) @@ -227,6 +197,8 @@ option(WITH_OPENTRACING "Whether to include the Opentracing shim" OFF) option(OTELCPP_VERSIONED_LIBS "Whether to generate the versioned shared libs" OFF) +option(WITH_REMOVE_METERS_PREVIEW "EXPERIMENTAL, ABI BREAKING: Allow to remove meters" OFF) + if(OTELCPP_VERSIONED_LIBS AND NOT BUILD_SHARED_LIBS) message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires BUILD_SHARED_LIBS=ON") endif() @@ -293,24 +265,6 @@ if(WITH_OTLP_HTTP_SSL_TLS_PREVIEW AND NOT WITH_OTLP_HTTP_SSL_PREVIEW) ) endif() -# -# ABI_VERSION_2 is not stable, do not build shared libraries with it. -# -if(OTELCPP_VERSIONED_LIBS AND WITH_ABI_VERSION_2_PREVIEW) - message( - FATAL_ERROR - "OTELCPP_VERSIONED_LIBS=ON requires WITH_ABI_VERSION_2_PREVIEW=OFF") -endif() - -# -# ABI_VERSION_2 is not stable, do not build DLL with it. -# -if(DEFINED OPENTELEMETRY_BUILD_DLL AND WITH_ABI_VERSION_2_PREVIEW) - message( - FATAL_ERROR - "OPENTELEMETRY_BUILD_DLL requires WITH_ABI_VERSION_2_PREVIEW=OFF") -endif() - find_package(Threads) function(install_windows_deps) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 3a6b908f81..88e0da46fa 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -98,9 +98,9 @@ if(WITH_ASYNC_EXPORT_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT) endif() -if(WITH_ABI_VERSION_2_PREVIEW) +if(WITH_REMOVE_METERS_PREVIEW) target_compile_definitions(opentelemetry_api - INTERFACE OPENTELEMETRY_ABI_VERSION_NO=2) + INTERFACE ENABLE_REMOVE_METERS_PREVIEW) endif() # A better place should be in sdk, not api diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index b24263be71..e1015cb2e3 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -29,8 +29,7 @@ class MeterProvider virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; - -#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +#ifdef ENABLE_REMOVE_METERS_PREVIEW virtual void RemoveMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 0e373f24a1..a4b3e10ae9 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -203,7 +203,7 @@ class NoopMeterProvider final : public MeterProvider return meter_; } -#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +#ifdef ENABLE_REMOVE_METERS_PREVIEW void RemoveMeter(nostd::string_view /* name */, nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 170c4bb493..e4e4807c82 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -133,29 +133,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then make -k -j $(nproc) make test exit 0 -elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then - cd "${BUILD_DIR}" - rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP_HTTP=ON \ - -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ - -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ - -DWITH_PROMETHEUS=ON \ - -DWITH_EXAMPLES=ON \ - -DWITH_EXAMPLES_HTTP=ON \ - -DWITH_ZIPKIN=ON \ - -DBUILD_W3CTRACECONTEXT_TEST=ON \ - -DWITH_ELASTICSEARCH=ON \ - -DWITH_LOGS_PREVIEW=ON \ - -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ - -DOTELCPP_MAINTAINER_MODE=ON \ - -DWITH_NO_DEPRECATED_CODE=ON \ - -DWITH_ABI_VERSION_2_PREVIEW=ON \ - "${SRC_DIR}" - make -k - make test - exit 0 elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then cd "${BUILD_DIR}" rm -rf * From e1d8c5b86fbf024cb071d907bc019f75009cfc2f Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Jul 2023 14:41:32 +0200 Subject: [PATCH 4/8] Cleanup --- CMakeLists.txt | 3 ++- api/include/opentelemetry/version.h | 5 +---- sdk/include/opentelemetry/sdk/metrics/meter_provider.h | 7 +------ sdk/src/metrics/meter_provider.cc | 2 ++ 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ab09fc0dc..698489a3f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,8 @@ option(WITH_OPENTRACING "Whether to include the Opentracing shim" OFF) option(OTELCPP_VERSIONED_LIBS "Whether to generate the versioned shared libs" OFF) -option(WITH_REMOVE_METERS_PREVIEW "EXPERIMENTAL, ABI BREAKING: Allow to remove meters" OFF) +option(WITH_REMOVE_METERS_PREVIEW + "EXPERIMENTAL, ABI BREAKING: Allow to remove meters" OFF) if(OTELCPP_VERSIONED_LIBS AND NOT BUILD_SHARED_LIBS) message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires BUILD_SHARED_LIBS=ON") diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index 0ff8d71d32..2178591728 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -6,10 +6,7 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/detail/preprocessor.h" -#ifndef OPENTELEMETRY_ABI_VERSION_NO -# define OPENTELEMETRY_ABI_VERSION_NO 1 -#endif - +#define OPENTELEMETRY_ABI_VERSION_NO 1 #define OPENTELEMETRY_VERSION "1.9.1" #define OPENTELEMETRY_VERSION_MAJOR 1 #define OPENTELEMETRY_VERSION_MINOR 9 diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index bf21d3c1da..a7e0b370d6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -53,15 +53,10 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider nostd::string_view version = "", nostd::string_view schema_url = "") noexcept override; -#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +#ifdef ENABLE_REMOVE_METERS_PREVIEW void RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept override; -#else - /* Only in the SDK, not API, for ABI VERSION 1 */ - void RemoveMeter(nostd::string_view name, - nostd::string_view version, - nostd::string_view schema_url) noexcept; #endif /** diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index b8720ded15..66d651cce4 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -57,6 +57,7 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } +#ifdef ENABLE_REMOVE_METERS_PREVIEW void MeterProvider::RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept @@ -71,6 +72,7 @@ void MeterProvider::RemoveMeter(nostd::string_view name, context_->RemoveMeter(name, version, schema_url); } +#endif const resource::Resource &MeterProvider::GetResource() const noexcept { From 84d2758136f45cf52217df38f5365bad8252daf9 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Jul 2023 15:13:18 +0200 Subject: [PATCH 5/8] CHANGELOG --- CHANGELOG.md | 9 +++++++++ CMakeLists.txt | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a9e19f26..e5d15773a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ Increment the: * [API] Remove include_trace_context [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) +* [API] Remove Meters + [#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205) + Important changes: * [REMOVAL] Remove the jaeger exporter @@ -28,6 +31,12 @@ Important changes: * The CMake `WITH_JAEGER` option has been removed * Please remove usage of `WITH_JAEGER` from user scripts and makefiles. +* [API] Remove Meters + [#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205) + * The CMake option `WITH_REMOVE_METERS_PREVIEW` was added. + * This option is experimental, and may change in the future. + * Enabling it is an ABI breaking change. + ## [1.9.1] 2023-05-26 * [DEPRECATION] Drop C++11 support diff --git a/CMakeLists.txt b/CMakeLists.txt index 698489a3f1..c5dbb5029b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,11 @@ option(WITH_OPENTRACING "Whether to include the Opentracing shim" OFF) option(OTELCPP_VERSIONED_LIBS "Whether to generate the versioned shared libs" OFF) +# +# This option is experimental, subject to change in the spec: +# +# - https://github.com/open-telemetry/opentelemetry-specification/issues/2232 +# option(WITH_REMOVE_METERS_PREVIEW "EXPERIMENTAL, ABI BREAKING: Allow to remove meters" OFF) From 8bd16592cf4acac4b79d86aa104b591ae7e84543 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Jul 2023 15:50:31 +0200 Subject: [PATCH 6/8] Format --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5dbb5029b..5acce0d72d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,7 +200,7 @@ option(OTELCPP_VERSIONED_LIBS "Whether to generate the versioned shared libs" # # This option is experimental, subject to change in the spec: # -# - https://github.com/open-telemetry/opentelemetry-specification/issues/2232 +# * https://github.com/open-telemetry/opentelemetry-specification/issues/2232 # option(WITH_REMOVE_METERS_PREVIEW "EXPERIMENTAL, ABI BREAKING: Allow to remove meters" OFF) From 819d3cf4bd3965cd7695dfff3cd1adce85aa0175 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Jul 2023 16:01:59 +0200 Subject: [PATCH 7/8] Rename to REMOVE_METER (singular) --- CHANGELOG.md | 2 +- CMakeLists.txt | 4 ++-- api/CMakeLists.txt | 4 ++-- api/include/opentelemetry/metrics/meter_provider.h | 2 +- api/include/opentelemetry/metrics/noop.h | 2 +- sdk/include/opentelemetry/sdk/metrics/meter_provider.h | 2 +- sdk/src/metrics/meter_provider.cc | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d15773a3..09da1ca55a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ Important changes: * [API] Remove Meters [#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205) - * The CMake option `WITH_REMOVE_METERS_PREVIEW` was added. + * The CMake option `WITH_REMOVE_METER_PREVIEW` was added. * This option is experimental, and may change in the future. * Enabling it is an ABI breaking change. diff --git a/CMakeLists.txt b/CMakeLists.txt index 5acce0d72d..997c9440e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,8 +202,8 @@ option(OTELCPP_VERSIONED_LIBS "Whether to generate the versioned shared libs" # # * https://github.com/open-telemetry/opentelemetry-specification/issues/2232 # -option(WITH_REMOVE_METERS_PREVIEW - "EXPERIMENTAL, ABI BREAKING: Allow to remove meters" OFF) +option(WITH_REMOVE_METER_PREVIEW + "EXPERIMENTAL, ABI BREAKING: Allow to remove a meter" OFF) if(OTELCPP_VERSIONED_LIBS AND NOT BUILD_SHARED_LIBS) message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires BUILD_SHARED_LIBS=ON") diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 88e0da46fa..d1a6a77fa3 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -98,9 +98,9 @@ if(WITH_ASYNC_EXPORT_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT) endif() -if(WITH_REMOVE_METERS_PREVIEW) +if(WITH_REMOVE_METER_PREVIEW) target_compile_definitions(opentelemetry_api - INTERFACE ENABLE_REMOVE_METERS_PREVIEW) + INTERFACE ENABLE_REMOVE_METER_PREVIEW) endif() # A better place should be in sdk, not api diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index e1015cb2e3..e0b0285ef4 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -29,7 +29,7 @@ class MeterProvider virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; -#ifdef ENABLE_REMOVE_METERS_PREVIEW +#ifdef ENABLE_REMOVE_METER_PREVIEW virtual void RemoveMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index a4b3e10ae9..c5802f3dd3 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -203,7 +203,7 @@ class NoopMeterProvider final : public MeterProvider return meter_; } -#ifdef ENABLE_REMOVE_METERS_PREVIEW +#ifdef ENABLE_REMOVE_METER_PREVIEW void RemoveMeter(nostd::string_view /* name */, nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index a7e0b370d6..4453b5b924 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -53,7 +53,7 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider nostd::string_view version = "", nostd::string_view schema_url = "") noexcept override; -#ifdef ENABLE_REMOVE_METERS_PREVIEW +#ifdef ENABLE_REMOVE_METER_PREVIEW void RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept override; diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 66d651cce4..4b89a5b9b5 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -57,7 +57,7 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } -#ifdef ENABLE_REMOVE_METERS_PREVIEW +#ifdef ENABLE_REMOVE_METER_PREVIEW void MeterProvider::RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept From c894d5bb4dc5e7f37b500800c04a3ba58ac07da2 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 10 Jul 2023 10:02:24 +0200 Subject: [PATCH 8/8] Fixed review comments. --- ci/do_ci.sh | 3 ++ sdk/src/metrics/meter_context.cc | 8 ++++- sdk/test/metrics/meter_provider_sdk_test.cc | 37 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 42bf3df416..69a6eef0c9 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -106,6 +106,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -129,6 +130,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -153,6 +155,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index c6526192ef..7a299bfc63 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -91,7 +91,13 @@ void MeterContext::RemoveMeter(nostd::string_view name, for (auto &meter : meters_) { auto scope = meter->GetInstrumentationScope(); - if (!scope->equal(name, version, schema_url)) + if (scope->equal(name, version, schema_url)) + { + OTEL_INTERNAL_LOG_INFO("[MeterContext::RemoveMeter] removing meter name <" + << name << ">, version <" << version << ">, URL <" << schema_url + << ">"); + } + else { filtered_meters.push_back(meter); } diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index bcdc6c4b79..da75916555 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -16,7 +16,6 @@ using namespace opentelemetry::sdk::metrics; TEST(MeterProvider, GetMeter) { - MeterProvider mp1; // std::unique_ptr view{std::unique_ptr()}; // MeterProvider mp1(std::move(exporters), std::move(readers), std::move(views); @@ -59,3 +58,39 @@ TEST(MeterProvider, GetMeter) mp1.ForceFlush(); mp1.Shutdown(); } + +#ifdef ENABLE_REMOVE_METER_PREVIEW +TEST(MeterProvider, RemoveMeter) +{ + MeterProvider mp; + + auto m1 = mp.GetMeter("test", "1", "URL"); + ASSERT_NE(nullptr, m1); + + // Will return the same meter + auto m2 = mp.GetMeter("test", "1", "URL"); + ASSERT_NE(nullptr, m2); + ASSERT_EQ(m1, m2); + + mp.RemoveMeter("unknown", "0", ""); + + // Will decrease use_count() on m1 and m2 + mp.RemoveMeter("test", "1", "URL"); + + // Will create a different meter + auto m3 = mp.GetMeter("test", "1", "URL"); + ASSERT_NE(nullptr, m3); + ASSERT_NE(m1, m3); + ASSERT_NE(m2, m3); + + // Will decrease use_count() on m3 + mp.RemoveMeter("test", "1", "URL"); + + // Will do nothing + mp.RemoveMeter("test", "1", "URL"); + + // cleanup properly without crash + mp.ForceFlush(); + mp.Shutdown(); +} +#endif