From 35c93554bc9b5dc61e0b2cef6723ac30614d8cc5 Mon Sep 17 00:00:00 2001 From: Oblivion Date: Thu, 11 Aug 2022 21:01:34 +0000 Subject: [PATCH] Fix metrics asan and tsan CI --- sdk/test/metrics/async_metric_storage_test.cc | 5 ++++- .../metrics/attributes_hashmap_benchmark.cc | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 5f4a611a9a..5bda35553d 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -14,6 +14,7 @@ # include "opentelemetry/sdk/metrics/state/observable_registry.h" # include +# include # include using namespace opentelemetry::sdk::metrics; @@ -99,8 +100,10 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) collectors.push_back(collector); size_t count_attributes = 0; + std::unique_ptr default_attributes_processor{ + new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::AsyncMetricStorage storage( - instr_desc, AggregationType::kSum, new DefaultAttributesProcessor(), + instr_desc, AggregationType::kSum, default_attributes_processor.get(), std::shared_ptr{}); long get_count = 20l; long put_count = 10l; diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index 38d515a7ea..2ebf03175a 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -25,19 +25,20 @@ void BM_AttributseHashMap(benchmark::State &state) std::vector attributes = {{{"k1", "v1"}, {"k2", "v2"}}, {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}}; - std::function()> create_default_aggregation = - []() -> std::unique_ptr { - return std::unique_ptr(new DropAggregation); + auto work = [&attributes, &hash_map](const size_t i) { + std::function()> create_default_aggregation = + []() -> std::unique_ptr { + return std::unique_ptr(new DropAggregation); + }; + + hash_map.GetOrSetDefault(attributes[i % 2], create_default_aggregation)->Aggregate(1l); + benchmark::DoNotOptimize(hash_map.Has(attributes[i % 2])); }; - while (state.KeepRunning()) { for (size_t i = 0; i < MAX_THREADS; i++) { - workers.push_back(std::thread([&]() { - hash_map.GetOrSetDefault(attributes[i % 2], create_default_aggregation)->Aggregate(1l); - benchmark::DoNotOptimize(hash_map.Has(attributes[i % 2])); - })); + workers.push_back(std::thread(work, i)); } }