From d9ad76f6be2b85d8685c31bbdc470a0fb555baba Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 19 Oct 2023 02:28:12 -0700 Subject: [PATCH] [SDK] Creating DoubleUpDownCounter with no matching view (#2379) --- .../metrics/aggregation/default_aggregation.h | 3 ++- sdk/test/metrics/sum_aggregation_test.cc | 26 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 6ae111fd85..4f3346707f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -35,7 +35,8 @@ class DefaultAggregation case AggregationType::kSum: return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) ? std::move(std::unique_ptr(new LongSumAggregation(is_monotonic))) - : std::move(std::unique_ptr(new DoubleSumAggregation(true))); + : std::move( + std::unique_ptr(new DoubleSumAggregation(is_monotonic))); break; case AggregationType::kHistogram: { if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) diff --git a/sdk/test/metrics/sum_aggregation_test.cc b/sdk/test/metrics/sum_aggregation_test.cc index b355f134ed..403bf34b22 100644 --- a/sdk/test/metrics/sum_aggregation_test.cc +++ b/sdk/test/metrics/sum_aggregation_test.cc @@ -121,8 +121,12 @@ TEST(CounterToSum, Double) ASSERT_EQ(1000275.0, opentelemetry::nostd::get(actual.value_)); } -TEST(UpDownCounterToSum, Double) +class UpDownCounterToSumFixture : public ::testing::TestWithParam +{}; + +TEST_P(UpDownCounterToSumFixture, Double) { + bool is_matching_view = GetParam(); MeterProvider mp; auto m = mp.GetMeter("meter1", "version1", "schema1"); std::string instrument_name = "updowncounter1"; @@ -133,13 +137,16 @@ TEST(UpDownCounterToSum, Double) std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; mp.AddMetricReader(reader); - std::unique_ptr view{ - new View("view1", "view1_description", instrument_unit, AggregationType::kSum)}; - std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)}; - std::unique_ptr meter_selector{new MeterSelector("meter1", "version1", "schema1")}; - mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); - + if (is_matching_view) + { + std::unique_ptr view{ + new View("view1", "view1_description", instrument_unit, AggregationType::kSum)}; + std::unique_ptr instrument_selector{ + new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)}; + std::unique_ptr meter_selector{ + new MeterSelector("meter1", "version1", "schema1")}; + mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); + } auto h = m->CreateDoubleUpDownCounter(instrument_name, instrument_desc, instrument_unit); h->Add(5, {}); @@ -168,4 +175,7 @@ TEST(UpDownCounterToSum, Double) const auto &actual = actuals.at(0); ASSERT_EQ(15.0, opentelemetry::nostd::get(actual.value_)); } +INSTANTIATE_TEST_SUITE_P(UpDownCounterToSum, + UpDownCounterToSumFixture, + ::testing::Values(true, false)); #endif