From 349c043de57b03355aae399afa36c90acd89f1ab Mon Sep 17 00:00:00 2001 From: Oblivion Date: Fri, 21 Oct 2022 22:08:29 +0000 Subject: [PATCH 1/4] return nostd::unique_ptr for Sync Instruments --- api/include/opentelemetry/metrics/meter.h | 19 +++++++------ api/include/opentelemetry/metrics/noop.h | 24 ++++++++-------- .../sdk/metrics/async_instruments.h | 3 +- sdk/include/opentelemetry/sdk/metrics/meter.h | 12 ++++---- .../sdk/metrics/state/observable_registry.h | 7 +++-- sdk/src/metrics/async_instruments.cc | 4 +-- sdk/src/metrics/meter.cc | 24 ++++++++-------- sdk/src/metrics/state/observable_registry.cc | 28 ++++++++++--------- 8 files changed, 63 insertions(+), 58 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 0bc9b7116c..8b078f42fa 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -9,6 +9,7 @@ # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/span.h" # include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/nostd/unique_ptr.h" # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -28,7 +29,7 @@ class Meter virtual ~Meter() = default; /** - * Creates a Counter with the passed characteristics and returns a shared_ptr to that Counter. + * Creates a Counter with the passed characteristics and returns a unique_ptr to that Counter. * * @param name the name of the new Counter. * @param description a brief description of what the Counter is used for. @@ -36,12 +37,12 @@ class Meter * @return a shared pointer to the created Counter. */ - virtual nostd::shared_ptr> CreateLongCounter( + virtual nostd::unique_ptr> CreateLongCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleCounter( + virtual nostd::unique_ptr> CreateDoubleCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -65,19 +66,19 @@ class Meter nostd::string_view unit = "") noexcept = 0; /** - * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. + * Creates a Histogram with the passed characteristics and returns a unique_ptr to that Histogram. * * @param name the name of the new Histogram. * @param description a brief description of what the Histogram is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @return a shared pointer to the created Histogram. */ - virtual nostd::shared_ptr> CreateLongHistogram( + virtual nostd::unique_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleHistogram( + virtual nostd::unique_ptr> CreateDoubleHistogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -101,7 +102,7 @@ class Meter nostd::string_view unit = "") noexcept = 0; /** - * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that + * Creates an UpDownCounter with the passed characteristics and returns a unique_ptr to that * UpDownCounter. * * @param name the name of the new UpDownCounter. @@ -109,12 +110,12 @@ class Meter * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @return a shared pointer to the created UpDownCounter. */ - virtual nostd::shared_ptr> CreateLongUpDownCounter( + virtual nostd::unique_ptr> CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleUpDownCounter( + virtual nostd::unique_ptr> CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index ce2d8e0cfd..bd444cf85a 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -87,19 +87,19 @@ class NoopObservableInstrument : public ObservableInstrument class NoopMeter final : public Meter { public: - nostd::shared_ptr> CreateLongCounter(nostd::string_view name, + nostd::unique_ptr> CreateLongCounter(nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; + return nostd::unique_ptr>{new NoopCounter(name, description, unit)}; } - nostd::shared_ptr> CreateDoubleCounter( + nostd::unique_ptr> CreateDoubleCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; + return nostd::unique_ptr>{new NoopCounter(name, description, unit)}; } nostd::shared_ptr CreateLongObservableCounter( @@ -120,20 +120,20 @@ class NoopMeter final : public Meter new NoopObservableInstrument(name, description, unit)); } - nostd::shared_ptr> CreateLongHistogram( + nostd::unique_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; + return nostd::unique_ptr>{new NoopHistogram(name, description, unit)}; } - nostd::shared_ptr> CreateDoubleHistogram( + nostd::unique_ptr> CreateDoubleHistogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; + return nostd::unique_ptr>{new NoopHistogram(name, description, unit)}; } nostd::shared_ptr CreateLongObservableGauge( @@ -154,21 +154,21 @@ class NoopMeter final : public Meter new NoopObservableInstrument(name, description, unit)); } - nostd::shared_ptr> CreateLongUpDownCounter( + nostd::unique_ptr> CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new NoopUpDownCounter(name, description, unit)}; } - nostd::shared_ptr> CreateDoubleUpDownCounter( + nostd::unique_ptr> CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new NoopUpDownCounter(name, description, unit)}; } diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index 13a059962c..5c192be73c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -17,7 +17,8 @@ namespace metrics class AsyncWritableMetricStorage; -class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument +class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument, + public std::enable_shared_from_this { public: ObservableInstrument(InstrumentDescriptor instrument_descriptor, diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index b2c86a7e49..183eba3675 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -35,12 +35,12 @@ class Meter final : public opentelemetry::metrics::Meter std::unique_ptr scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept; - nostd::shared_ptr> CreateLongCounter( + nostd::unique_ptr> CreateLongCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateDoubleCounter( + nostd::unique_ptr> CreateDoubleCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -55,12 +55,12 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateLongHistogram( + nostd::unique_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateDoubleHistogram( + nostd::unique_ptr> CreateDoubleHistogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -75,12 +75,12 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateLongUpDownCounter( + nostd::unique_ptr> CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateDoubleUpDownCounter( + nostd::unique_ptr> CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h index bf76145f03..9e54f611bd 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#include #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/timestamp.h" @@ -21,7 +22,7 @@ struct ObservableCallbackRecord { opentelemetry::metrics::ObservableCallbackPtr callback; void *state; - opentelemetry::metrics::ObservableInstrument *instrument; + std::shared_ptr instrument; }; class ObservableRegistry @@ -29,11 +30,11 @@ class ObservableRegistry public: void AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state, - opentelemetry::metrics::ObservableInstrument *instrument); + std::shared_ptr instrument); void RemoveCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state, - opentelemetry::metrics::ObservableInstrument *instrument); + std::shared_ptr instrument); void Observe(opentelemetry::common::SystemTimestamp collection_ts); diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 916ca765af..0a4f1b4081 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -26,13 +26,13 @@ ObservableInstrument::ObservableInstrument(InstrumentDescriptor instrument_descr void ObservableInstrument::AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state) noexcept { - observable_registry_->AddCallback(callback, state, this); + observable_registry_->AddCallback(callback, state, shared_from_this()); } void ObservableInstrument::RemoveCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state) noexcept { - observable_registry_->RemoveCallback(callback, state, this); + observable_registry_->RemoveCallback(callback, state, shared_from_this()); } const InstrumentDescriptor &ObservableInstrument::GetInstrumentDescriptor() diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 8d36509c34..38bfe968e9 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -33,7 +33,7 @@ Meter::Meter( observable_registry_(new ObservableRegistry()) {} -nostd::shared_ptr> Meter::CreateLongCounter(nostd::string_view name, +nostd::unique_ptr> Meter::CreateLongCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept { @@ -41,11 +41,11 @@ nostd::shared_ptr> Meter::CreateLongCounter(nostd::string std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, std::string{unit.data(), unit.size()}, InstrumentType::kCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>( + return nostd::unique_ptr>( new LongCounter(instrument_descriptor, std::move(storage))); } -nostd::shared_ptr> Meter::CreateDoubleCounter( +nostd::unique_ptr> Meter::CreateDoubleCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -55,7 +55,7 @@ nostd::shared_ptr> Meter::CreateDoubleCounter( std::string{unit.data(), unit.size()}, InstrumentType::kCounter, InstrumentValueType::kDouble}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new DoubleCounter(instrument_descriptor, std::move(storage))}; } @@ -87,7 +87,7 @@ Meter::CreateDoubleObservableCounter(nostd::string_view name, new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr> Meter::CreateLongHistogram( +nostd::unique_ptr> Meter::CreateLongHistogram( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -97,11 +97,11 @@ nostd::shared_ptr> Meter::CreateLongHistogram( std::string{unit.data(), unit.size()}, InstrumentType::kHistogram, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new LongHistogram(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr> Meter::CreateDoubleHistogram( +nostd::unique_ptr> Meter::CreateDoubleHistogram( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -111,7 +111,7 @@ nostd::shared_ptr> Meter::CreateDoubleHistogram( std::string{unit.data(), unit.size()}, InstrumentType::kHistogram, InstrumentValueType::kDouble}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new DoubleHistogram(instrument_descriptor, std::move(storage))}; } @@ -143,7 +143,7 @@ nostd::shared_ptr Meter::CreateDou new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr> Meter::CreateLongUpDownCounter( +nostd::unique_ptr> Meter::CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -153,11 +153,11 @@ nostd::shared_ptr> Meter::CreateLongUpDownCounter( std::string{unit.data(), unit.size()}, InstrumentType::kUpDownCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new LongUpDownCounter(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr> Meter::CreateDoubleUpDownCounter( +nostd::unique_ptr> Meter::CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -167,7 +167,7 @@ nostd::shared_ptr> Meter::CreateDoubleUpDownCount std::string{unit.data(), unit.size()}, InstrumentType::kUpDownCounter, InstrumentValueType::kDouble}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ + return nostd::unique_ptr>{ new DoubleUpDownCounter(instrument_descriptor, std::move(storage))}; } diff --git a/sdk/src/metrics/state/observable_registry.cc b/sdk/src/metrics/state/observable_registry.cc index 0d6d770f87..3f2f579449 100644 --- a/sdk/src/metrics/state/observable_registry.cc +++ b/sdk/src/metrics/state/observable_registry.cc @@ -15,9 +15,10 @@ namespace sdk namespace metrics { -void ObservableRegistry::AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, - void *state, - opentelemetry::metrics::ObservableInstrument *instrument) +void ObservableRegistry::AddCallback( + opentelemetry::metrics::ObservableCallbackPtr callback, + void *state, + std::shared_ptr instrument) { // TBD - Check if existing std::unique_ptr record( @@ -26,9 +27,10 @@ void ObservableRegistry::AddCallback(opentelemetry::metrics::ObservableCallbackP callbacks_.push_back(std::move(record)); } -void ObservableRegistry::RemoveCallback(opentelemetry::metrics::ObservableCallbackPtr callback, - void *state, - opentelemetry::metrics::ObservableInstrument *instrument) +void ObservableRegistry::RemoveCallback( + opentelemetry::metrics::ObservableCallbackPtr callback, + void *state, + std::shared_ptr instrument) { std::lock_guard lock_guard{callbacks_m_}; auto new_end = std::remove_if( @@ -45,13 +47,13 @@ void ObservableRegistry::Observe(opentelemetry::common::SystemTimestamp collecti std::lock_guard lock_guard{callbacks_m_}; for (auto &callback_wrap : callbacks_) { - auto value_type = - static_cast(callback_wrap->instrument) - ->GetInstrumentDescriptor() - .value_type_; - auto storage = - static_cast(callback_wrap->instrument) - ->GetMetricStorage(); + auto value_type = std::static_pointer_cast( + callback_wrap->instrument) + ->GetInstrumentDescriptor() + .value_type_; + auto storage = std::static_pointer_cast( + callback_wrap->instrument) + ->GetMetricStorage(); if (!storage) { OTEL_INTERNAL_LOG_ERROR("[ObservableRegistry::Observe] - Error during observe." From b65512e478b74b16ec96c270c2ec4bfe3866bc55 Mon Sep 17 00:00:00 2001 From: Oblivion Date: Sat, 22 Oct 2022 07:10:55 +0000 Subject: [PATCH 2/4] fix --- .../sdk/metrics/async_instruments.h | 3 +- .../sdk/metrics/state/observable_registry.h | 6 ++-- sdk/src/metrics/async_instruments.cc | 4 +-- sdk/src/metrics/state/observable_registry.cc | 28 ++++++++--------- sdk/test/metrics/BUILD | 30 +++++++++++++++++++ 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index 5c192be73c..13a059962c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -17,8 +17,7 @@ namespace metrics class AsyncWritableMetricStorage; -class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument, - public std::enable_shared_from_this +class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument { public: ObservableInstrument(InstrumentDescriptor instrument_descriptor, diff --git a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h index 9e54f611bd..156d6d87cc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h @@ -22,7 +22,7 @@ struct ObservableCallbackRecord { opentelemetry::metrics::ObservableCallbackPtr callback; void *state; - std::shared_ptr instrument; + opentelemetry::metrics::ObservableInstrument *instrument; }; class ObservableRegistry @@ -30,11 +30,11 @@ class ObservableRegistry public: void AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state, - std::shared_ptr instrument); + opentelemetry::metrics::ObservableInstrument *instrument); void RemoveCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state, - std::shared_ptr instrument); + opentelemetry::metrics::ObservableInstrument *instrument); void Observe(opentelemetry::common::SystemTimestamp collection_ts); diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 0a4f1b4081..916ca765af 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -26,13 +26,13 @@ ObservableInstrument::ObservableInstrument(InstrumentDescriptor instrument_descr void ObservableInstrument::AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state) noexcept { - observable_registry_->AddCallback(callback, state, shared_from_this()); + observable_registry_->AddCallback(callback, state, this); } void ObservableInstrument::RemoveCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state) noexcept { - observable_registry_->RemoveCallback(callback, state, shared_from_this()); + observable_registry_->RemoveCallback(callback, state, this); } const InstrumentDescriptor &ObservableInstrument::GetInstrumentDescriptor() diff --git a/sdk/src/metrics/state/observable_registry.cc b/sdk/src/metrics/state/observable_registry.cc index 3f2f579449..0d6d770f87 100644 --- a/sdk/src/metrics/state/observable_registry.cc +++ b/sdk/src/metrics/state/observable_registry.cc @@ -15,10 +15,9 @@ namespace sdk namespace metrics { -void ObservableRegistry::AddCallback( - opentelemetry::metrics::ObservableCallbackPtr callback, - void *state, - std::shared_ptr instrument) +void ObservableRegistry::AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, + void *state, + opentelemetry::metrics::ObservableInstrument *instrument) { // TBD - Check if existing std::unique_ptr record( @@ -27,10 +26,9 @@ void ObservableRegistry::AddCallback( callbacks_.push_back(std::move(record)); } -void ObservableRegistry::RemoveCallback( - opentelemetry::metrics::ObservableCallbackPtr callback, - void *state, - std::shared_ptr instrument) +void ObservableRegistry::RemoveCallback(opentelemetry::metrics::ObservableCallbackPtr callback, + void *state, + opentelemetry::metrics::ObservableInstrument *instrument) { std::lock_guard lock_guard{callbacks_m_}; auto new_end = std::remove_if( @@ -47,13 +45,13 @@ void ObservableRegistry::Observe(opentelemetry::common::SystemTimestamp collecti std::lock_guard lock_guard{callbacks_m_}; for (auto &callback_wrap : callbacks_) { - auto value_type = std::static_pointer_cast( - callback_wrap->instrument) - ->GetInstrumentDescriptor() - .value_type_; - auto storage = std::static_pointer_cast( - callback_wrap->instrument) - ->GetMetricStorage(); + auto value_type = + static_cast(callback_wrap->instrument) + ->GetInstrumentDescriptor() + .value_type_; + auto storage = + static_cast(callback_wrap->instrument) + ->GetMetricStorage(); if (!storage) { OTEL_INTERNAL_LOG_ERROR("[ObservableRegistry::Observe] - Error during observe." diff --git a/sdk/test/metrics/BUILD b/sdk/test/metrics/BUILD index 336fbc8b03..5d3076b8be 100644 --- a/sdk/test/metrics/BUILD +++ b/sdk/test/metrics/BUILD @@ -1,5 +1,20 @@ load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") +cc_test( + name = "meter_test", + srcs = [ + "meter_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "meter_provider_sdk_test", srcs = [ @@ -112,6 +127,21 @@ cc_test( ], ) +cc_test( + name = "async_instruments_test", + srcs = [ + "async_instruments_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "async_metric_storage_test", srcs = [ From bbaaba190d9559e89d32b456e0b8e04eab03a7ed Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:13:25 +0200 Subject: [PATCH 3/4] fix test race --- sdk/test/metrics/meter_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index b4cd12416c..4f412740db 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -82,12 +82,12 @@ TEST(MeterTest, StressMultiThread) MetricReader *metric_reader_ptr = nullptr; auto meter = InitMeter(&metric_reader_ptr, "stress_test_meter"); std::atomic threadCount(0); - size_t numIterations = MAX_ITERATIONS_MT; + std::atomic numIterations(MAX_ITERATIONS_MT); std::atomic do_collect{false}, do_sync_create{true}, do_async_create{false}; std::vector> observable_instruments; std::vector meter_operation_threads; - size_t instrument_id = 0; + std::atomic instrument_id(0); while (numIterations--) { for (size_t i = 0; i < MAX_THREADS; i++) From 10ecb1a7aa37a8dec2bba41fdeba6243b4404541 Mon Sep 17 00:00:00 2001 From: Oblivion Date: Mon, 24 Oct 2022 17:23:12 +0000 Subject: [PATCH 4/4] comment --- .../opentelemetry/sdk/metrics/state/observable_registry.h | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h index 156d6d87cc..bf76145f03 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#include #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/timestamp.h"