diff --git a/exporters/memory/test/in_memory_metric_data_test.cc b/exporters/memory/test/in_memory_metric_data_test.cc index def50be9fc..5bf0866088 100644 --- a/exporters/memory/test/in_memory_metric_data_test.cc +++ b/exporters/memory/test/in_memory_metric_data_test.cc @@ -18,11 +18,11 @@ using opentelemetry::exporter::memory::CircularBufferInMemoryMetricData; using opentelemetry::exporter::memory::SimpleAggregateInMemoryMetricData; +using opentelemetry::sdk::metrics::DoubleSumPointData; using opentelemetry::sdk::metrics::MetricData; using opentelemetry::sdk::metrics::PointDataAttributes; using opentelemetry::sdk::metrics::ResourceMetrics; using opentelemetry::sdk::metrics::ScopeMetrics; -using opentelemetry::sdk::metrics::SumPointData; using opentelemetry::sdk::resource::Resource; TEST(InMemoryMetricDataTest, CircularBuffer) @@ -43,7 +43,7 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "my-scope", "1.0.0", "http://example.com"); - SumPointData spd; + DoubleSumPointData spd; spd.value_ = 42.0; PointDataAttributes pda{{{"hello", "world"}}, spd}; @@ -55,7 +55,7 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) &resource, std::vector{{scope.get(), std::vector{md}}}})); auto it = agg.Get("my-scope", "my-metric").begin(); - auto saved_point = opentelemetry::nostd::get(it->second); + auto saved_point = opentelemetry::nostd::get(it->second); - EXPECT_EQ(opentelemetry::nostd::get(saved_point.value_), 42.0); + EXPECT_EQ(saved_point.value_, 42.0); } diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 3fadbbd84c..ed53f0bf37 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -201,19 +201,18 @@ void OStreamMetricExporter::printInstrumentationInfoMetricData( void OStreamMetricExporter::printPointData(const opentelemetry::sdk::metrics::PointType &point_data) { - if (nostd::holds_alternative(point_data)) + if (auto *long_sum_point_data = nostd::get_if(&point_data)) { - auto sum_point_data = nostd::get(point_data); - sout_ << "\n type\t\t: SumPointData"; + sout_ << "\n type\t\t: LongSumPointData"; sout_ << "\n value\t\t: "; - if (nostd::holds_alternative(sum_point_data.value_)) - { - sout_ << nostd::get(sum_point_data.value_); - } - else if (nostd::holds_alternative(sum_point_data.value_)) - { - sout_ << nostd::get(sum_point_data.value_); - } + sout_ << long_sum_point_data->value_; + } + else if (auto *double_sum_point_data = + nostd::get_if(&point_data)) + { + sout_ << "\n type\t\t: DoubleSumPointData"; + sout_ << "\n value\t\t: "; + sout_ << double_sum_point_data->value_; } else if (nostd::holds_alternative(point_data)) { diff --git a/exporters/ostream/test/ostream_metric_test.cc b/exporters/ostream/test/ostream_metric_test.cc index 613be05667..cdede1473c 100644 --- a/exporters/ostream/test/ostream_metric_test.cc +++ b/exporters/ostream/test/ostream_metric_test.cc @@ -40,9 +40,9 @@ TEST(OStreamMetricsExporter, ExportSumPointData) auto exporter = std::unique_ptr(new exportermetrics::OStreamMetricExporter); - metric_sdk::SumPointData sum_point_data{}; + metric_sdk::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - metric_sdk::SumPointData sum_point_data2{}; + metric_sdk::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; metric_sdk::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -80,11 +80,11 @@ TEST(OStreamMetricsExporter, ExportSumPointData) "\n instrument name\t: library_name" "\n description\t: description" "\n unit\t\t: unit" - "\n type\t\t: SumPointData" + "\n type\t\t: DoubleSumPointData" "\n value\t\t: 10" "\n attributes\t\t: " "\n\ta1: b1" - "\n type\t\t: SumPointData" + "\n type\t\t: DoubleSumPointData" "\n value\t\t: 20" "\n attributes\t\t: " "\n\ta1: b1" diff --git a/exporters/otlp/benchmark/otlp_http_metric_exporter_benchmark.cc b/exporters/otlp/benchmark/otlp_http_metric_exporter_benchmark.cc index 815f0c7849..d2b77424c9 100644 --- a/exporters/otlp/benchmark/otlp_http_metric_exporter_benchmark.cc +++ b/exporters/otlp/benchmark/otlp_http_metric_exporter_benchmark.cc @@ -48,7 +48,7 @@ static ResourceMetrics MakeMetrics(std::size_t n_points) for (std::size_t i = 0; i < n_points; ++i) { - SumPointData sum; + DoubleSumPointData sum; sum.value_ = static_cast(i); sum.is_monotonic_ = true; diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index eba978a17e..13ab4cb297 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -55,7 +55,10 @@ metric_sdk::AggregationType OtlpMetricUtils::GetAggregationType( return metric_sdk::AggregationType::kDrop; } auto point_data_with_attributes = metric_data.point_data_attr_[0]; - if (nostd::holds_alternative(point_data_with_attributes.point_data)) + if (nostd::holds_alternative( + point_data_with_attributes.point_data) || + nostd::holds_alternative( + point_data_with_attributes.point_data)) { return metric_sdk::AggregationType::kSum; } @@ -92,17 +95,23 @@ void OtlpMetricUtils::ConvertSumMetric(const metric_sdk::MetricData &metric_data proto::metrics::v1::NumberDataPoint *proto_sum_point_data = sum->add_data_points(); proto_sum_point_data->set_start_time_unix_nano(start_ts); proto_sum_point_data->set_time_unix_nano(ts); - const auto &sum_data = - nostd::get(point_data_with_attributes.point_data); - if ((nostd::holds_alternative(sum_data.value_))) + const auto *long_sum_data = + nostd::get_if(&point_data_with_attributes.point_data); + + if (long_sum_data != nullptr) { - proto_sum_point_data->set_as_int(nostd::get(sum_data.value_)); + proto_sum_point_data->set_as_int(long_sum_data->value_); } - else + + const auto *double_sum_data = + nostd::get_if(&point_data_with_attributes.point_data); + + if (double_sum_data != nullptr) { - proto_sum_point_data->set_as_double(nostd::get(sum_data.value_)); + proto_sum_point_data->set_as_double(double_sum_data->value_); } + // set attributes for (auto &kv_attr : point_data_with_attributes.attributes) { diff --git a/exporters/otlp/test/otlp_file_metric_exporter_test.cc b/exporters/otlp/test/otlp_file_metric_exporter_test.cc index bc6138c9c1..706989b5c6 100644 --- a/exporters/otlp/test/otlp_file_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_metric_exporter_test.cc @@ -87,9 +87,9 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test auto exporter = OtlpFileMetricExporterFactory::Create(opts); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; opentelemetry::sdk::metrics::ResourceMetrics data; diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc index 9f6deef725..a9571940a8 100644 --- a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc @@ -396,7 +396,7 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ExportPartialSuccess) mock_stub); auto exporter = GetExporter(std::move(stub_interface)); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 787c982bf0..2b2bcf4a21 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -168,9 +168,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -268,9 +268,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -486,9 +486,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -754,9 +754,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -1277,7 +1277,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportPartialSuccess) auto mock_session = std::static_pointer_cast(no_send_client->session_); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -1336,7 +1336,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportPartialSuccessJson) auto mock_session = std::static_pointer_cast(no_send_client->session_); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( @@ -1392,7 +1392,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportParseFailureReturnsFailure) auto mock_session = std::static_pointer_cast(no_send_client->session_); - opentelemetry::sdk::metrics::SumPointData sum_point_data{}; + opentelemetry::sdk::metrics::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index afd0f10fb4..5c9bbb1c2b 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -51,7 +51,7 @@ static metrics_sdk::MetricData CreateSumAggregationData() metrics_sdk::InstrumentDescriptor inst_desc = {"Counter", "desc", "unit", metrics_sdk::InstrumentType::kCounter, metrics_sdk::InstrumentValueType::kDouble}; - metrics_sdk::SumPointData s_data_1, s_data_2; + metrics_sdk::DoubleSumPointData s_data_1, s_data_2; s_data_1.value_ = 10.2; s_data_2.value_ = 20.2; @@ -78,7 +78,7 @@ static metrics_sdk::MetricData CreateUpDownCounterAggregationData() metrics_sdk::InstrumentDescriptor inst_desc = {"UpDownCounter", "Robot Pose Y", "Meter", metrics_sdk::InstrumentType::kUpDownCounter, metrics_sdk::InstrumentValueType::kDouble}; - metrics_sdk::SumPointData s_data_1, s_data_2; + metrics_sdk::DoubleSumPointData s_data_1, s_data_2; s_data_1.value_ = 1.35; s_data_2.value_ = 1.37; @@ -219,7 +219,7 @@ static metrics_sdk::MetricData CreateObservableCounterAggregationData() metrics_sdk::InstrumentDescriptor inst_desc = { "ObservableCounter", "test description", "test unit", metrics_sdk::InstrumentType::kObservableCounter, metrics_sdk::InstrumentValueType::kDouble}; - metrics_sdk::SumPointData s_data_1, s_data_2; + metrics_sdk::DoubleSumPointData s_data_1, s_data_2; s_data_1.value_ = 1.23; s_data_2.value_ = 4.56; @@ -247,7 +247,7 @@ static metrics_sdk::MetricData CreateObservableUpDownCounterAggregationData() "ObservableUpDownCounter", "test description", "test unit", metrics_sdk::InstrumentType::kObservableUpDownCounter, metrics_sdk::InstrumentValueType::kDouble}; - metrics_sdk::SumPointData s_data_1, s_data_2, s_data_3; + metrics_sdk::DoubleSumPointData s_data_1, s_data_2, s_data_3; s_data_1.value_ = 1.23; s_data_2.value_ = 4.56; s_data_3.value_ = 2.34; @@ -468,7 +468,7 @@ TEST(OtlpMetricSerializationTest, AttributeTypes) metrics_sdk::InstrumentType::kCounter, metrics_sdk::InstrumentValueType::kDouble}; - metrics_sdk::SumPointData point; + metrics_sdk::DoubleSumPointData point; point.value_ = 1.0; const std::array byte_values = {0xDE, 0xAD, 0xBE, 0xEF}; diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index b6f817a91b..4222de06bb 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -149,7 +149,16 @@ std::vector PrometheusExporterUtils::TranslateT bool is_monotonic = true; if (kind == sdk::metrics::AggregationType::kSum) { - is_monotonic = nostd::get(front.point_data).is_monotonic_; + if (auto *long_point_data = + nostd::get_if(&front.point_data)) + { + is_monotonic = long_point_data->is_monotonic_; + } + else if (auto *double_point_data = + nostd::get_if(&front.point_data)) + { + is_monotonic = double_point_data->is_monotonic_; + } } const prometheus_client::MetricType type = TranslateType(kind, is_monotonic); metric_family.name = MapToPrometheusName(metric_data.instrument_descriptor.name_, @@ -191,10 +200,20 @@ std::vector PrometheusExporterUtils::TranslateT SetData(values, point_data_attr.attributes, scope, type, &metric_family, data.resource_); } - else if (nostd::holds_alternative(point_data_attr.point_data)) + else if (nostd::holds_alternative( + point_data_attr.point_data)) + { + auto sum_point_data = + nostd::get(point_data_attr.point_data); + std::vector values{sum_point_data.value_}; + SetData(values, point_data_attr.attributes, scope, type, &metric_family, + data.resource_); + } + else if (nostd::holds_alternative( + point_data_attr.point_data)) { auto sum_point_data = - nostd::get(point_data_attr.point_data); + nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; SetData(values, point_data_attr.attributes, scope, type, &metric_family, data.resource_); @@ -208,10 +227,19 @@ std::vector PrometheusExporterUtils::TranslateT } else // Counter, Untyped { - if (nostd::holds_alternative(point_data_attr.point_data)) + if (nostd::holds_alternative(point_data_attr.point_data)) + { + auto sum_point_data = + nostd::get(point_data_attr.point_data); + std::vector values{sum_point_data.value_}; + SetData(values, point_data_attr.attributes, scope, type, &metric_family, + data.resource_); + } + else if (nostd::holds_alternative( + point_data_attr.point_data)) { auto sum_point_data = - nostd::get(point_data_attr.point_data); + nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; SetData(values, point_data_attr.attributes, scope, type, &metric_family, data.resource_); @@ -539,7 +567,8 @@ metric_sdk::AggregationType PrometheusExporterUtils::getAggregationType( const metric_sdk::PointType &point_type) { - if (nostd::holds_alternative(point_type)) + if (nostd::holds_alternative(point_type) || + nostd::holds_alternative(point_type)) { return metric_sdk::AggregationType::kSum; } diff --git a/exporters/prometheus/test/collector_test.cc b/exporters/prometheus/test/collector_test.cc index 9a30d3bb22..ad934636f2 100644 --- a/exporters/prometheus/test/collector_test.cc +++ b/exporters/prometheus/test/collector_test.cc @@ -35,7 +35,7 @@ class MockMetricProducer : public MetricProducer { std::this_thread::sleep_for(sleep_ms_); data_sent_size_++; - ResourceMetrics data = test_data_points_.CreateSumPointData(); + ResourceMetrics data = test_data_points_.CreateDoubleSumPointData(); return {data, MetricProducer::Status::kSuccess}; } diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 4c08a4037b..f03f8027ec 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -169,7 +169,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) {"service.instance.id", "localhost:8000"}, {"custom_resource_attr", "custom_resource_value"}}); TestDataPoints dp; - metric_sdk::ResourceMetrics metrics_data = dp.CreateSumPointData(); + metric_sdk::ResourceMetrics metrics_data = dp.CreateDoubleSumPointData(); metrics_data.resource_ = &resource; auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); diff --git a/exporters/prometheus/test/prometheus_test_helper.h b/exporters/prometheus/test/prometheus_test_helper.h index ae541da223..6e7160a118 100644 --- a/exporters/prometheus/test/prometheus_test_helper.h +++ b/exporters/prometheus/test/prometheus_test_helper.h @@ -31,11 +31,11 @@ struct TestDataPoints /** * Helper function to create ResourceMetrics */ - inline metric_sdk::ResourceMetrics CreateSumPointData() + inline metric_sdk::ResourceMetrics CreateDoubleSumPointData() { - metric_sdk::SumPointData sum_point_data{}; + metric_sdk::DoubleSumPointData sum_point_data{}; sum_point_data.value_ = 10.0; - metric_sdk::SumPointData sum_point_data2{}; + metric_sdk::DoubleSumPointData sum_point_data2{}; sum_point_data2.value_ = 20.0; metric_sdk::ResourceMetrics data; data.resource_ = &resource; @@ -175,10 +175,18 @@ inline bool operator==(const metric_sdk::MetricData &lhs, const metric_sdk::Metr } auto &lhs_point_data = lhs.point_data_attr_.at(idx).point_data; auto &rhs_point_data = rhs.point_data_attr_.at(idx).point_data; - if (nostd::holds_alternative(lhs_point_data)) + if (nostd::holds_alternative(lhs_point_data)) { - if (nostd::get(lhs_point_data).value_ != - nostd::get(rhs_point_data).value_) + if (nostd::get(lhs_point_data).value_ != + nostd::get(rhs_point_data).value_) + { + return false; + } + } + else if (nostd::holds_alternative(lhs_point_data)) + { + if (nostd::get(lhs_point_data).value_ != + nostd::get(rhs_point_data).value_) { return false; } diff --git a/install/test/src/test_exporters_otlp_common.cc b/install/test/src/test_exporters_otlp_common.cc index 0e6a940527..7773af02c5 100644 --- a/install/test/src/test_exporters_otlp_common.cc +++ b/install/test/src/test_exporters_otlp_common.cc @@ -41,7 +41,7 @@ static metrics_sdk::MetricData CreateSumAggregationData() metrics_sdk::InstrumentDescriptor inst_desc = {"Counter", "desc", "unit", metrics_sdk::InstrumentType::kCounter, metrics_sdk::InstrumentValueType::kDouble}; - metrics_sdk::SumPointData s_data_1, s_data_2; + metrics_sdk::DoubleSumPointData s_data_1, s_data_2; s_data_1.value_ = 10.2; s_data_2.value_ = 20.2; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 949e4be85b..8019bbe4ef 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -162,12 +162,12 @@ class DefaultAggregation if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) { return std::unique_ptr( - new LongSumAggregation(nostd::get(point_data))); + new LongSumAggregation(nostd::get(point_data))); } else { return std::unique_ptr( - new DoubleSumAggregation(nostd::get(point_data))); + new DoubleSumAggregation(nostd::get(point_data))); } default: return nullptr; // won't reach here diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h index 9b71790288..2b90101185 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h @@ -22,7 +22,7 @@ class LongSumAggregation : public Aggregation { public: LongSumAggregation(bool is_monotonic); - LongSumAggregation(const SumPointData &); + LongSumAggregation(const LongSumPointData &); void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override; @@ -33,17 +33,18 @@ class LongSumAggregation : public Aggregation std::unique_ptr Diff(const Aggregation &next) const noexcept override; PointType ToPoint() const noexcept override; + LongSumPointData ToPointData() const noexcept; private: mutable opentelemetry::common::SpinLockMutex lock_; - SumPointData point_data_; + LongSumPointData point_data_; }; class DoubleSumAggregation : public Aggregation { public: DoubleSumAggregation(bool is_monotonic); - DoubleSumAggregation(const SumPointData &); + DoubleSumAggregation(const DoubleSumPointData &); void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {} @@ -54,10 +55,11 @@ class DoubleSumAggregation : public Aggregation std::unique_ptr Diff(const Aggregation &next) const noexcept override; PointType ToPoint() const noexcept override; + DoubleSumPointData ToPointData() const noexcept; private: mutable opentelemetry::common::SpinLockMutex lock_; - SumPointData point_data_; + DoubleSumPointData point_data_; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h index 929e56b541..0c1276707d 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h @@ -47,9 +47,16 @@ class ExemplarData */ const opentelemetry::trace::SpanContext &GetSpanContext() const noexcept { return context_; } - static PointType CreateSumPointData(ValueType value) + static PointType CreateLongSumPointData(int64_t value) { - SumPointData sum_point_data{}; + LongSumPointData sum_point_data{}; + sum_point_data.value_ = value; + return sum_point_data; + } + + static PointType CreateDoubleSumPointData(double value) + { + DoubleSumPointData sum_point_data{}; sum_point_data.value_ = value; return sum_point_data; } diff --git a/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h b/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h index 4be493c0ac..662ba3704a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h @@ -18,7 +18,8 @@ namespace metrics { using PointAttributes = opentelemetry::sdk::common::OrderedAttributeMap; -using PointType = opentelemetry::nostd::variant; // TODO: remove ctors and initializers from below classes when GCC<5 stops // shipping on Ubuntu +template class SumPointData { public: @@ -32,10 +33,13 @@ class SumPointData SumPointData &operator=(const SumPointData &other) = default; ~SumPointData() = default; - ValueType value_ = {}; + T value_ = {}; bool is_monotonic_ = true; }; +using LongSumPointData = SumPointData; +using DoubleSumPointData = SumPointData; + class LastValuePointData { public: diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h index 66d07dfb3d..f6480987e3 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h @@ -73,7 +73,7 @@ class ReservoirCell if (const int64_t *value = nostd::get_if(&value_)) { - point_data_attributes.point_data = ExemplarData::CreateSumPointData(*value); + point_data_attributes.point_data = ExemplarData::CreateLongSumPointData(*value); } std::shared_ptr result{ new ExemplarData{ExemplarData::Create(context_, record_time_, point_data_attributes)}}; @@ -97,7 +97,7 @@ class ReservoirCell point_data_attributes.attributes = filtered(attributes, point_attributes); if (const double *value = nostd::get_if(&value_)) { - point_data_attributes.point_data = ExemplarData::CreateSumPointData(*value); + point_data_attributes.point_data = ExemplarData::CreateDoubleSumPointData(*value); } std::shared_ptr result{ new ExemplarData{ExemplarData::Create(context_, record_time_, point_data_attributes)}}; diff --git a/sdk/src/metrics/aggregation/sum_aggregation.cc b/sdk/src/metrics/aggregation/sum_aggregation.cc index 906851b04e..4ad937b699 100644 --- a/sdk/src/metrics/aggregation/sum_aggregation.cc +++ b/sdk/src/metrics/aggregation/sum_aggregation.cc @@ -7,7 +7,6 @@ #include #include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" @@ -27,7 +26,7 @@ LongSumAggregation::LongSumAggregation(bool is_monotonic) point_data_.is_monotonic_ = is_monotonic; } -LongSumAggregation::LongSumAggregation(const SumPointData &data) : point_data_{data} {} +LongSumAggregation::LongSumAggregation(const LongSumPointData &data) : point_data_{data} {} void LongSumAggregation::Aggregate(int64_t value, const PointAttributes & /* attributes */) noexcept { @@ -40,62 +39,42 @@ void LongSumAggregation::Aggregate(int64_t value, const PointAttributes & /* att return; } const std::lock_guard locked(lock_); - point_data_.value_ = nostd::get(point_data_.value_) + value; + point_data_.value_ = point_data_.value_ + value; } std::unique_ptr LongSumAggregation::Merge(const Aggregation &delta) const noexcept { - auto delta_point = static_cast(delta).ToPoint(); - auto curr_point = ToPoint(); + auto delta_sum = static_cast(delta).ToPointData(); + auto curr_sum = ToPointData(); - const auto *delta_sum = nostd::get_if(&delta_point); - const auto *curr_sum = nostd::get_if(&curr_point); - if (delta_sum == nullptr || curr_sum == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("LongSumAggregation::Merge - Loss of type"); - return std::unique_ptr(new LongSumAggregation(point_data_.is_monotonic_)); - } - - const auto *delta_val = nostd::get_if(&delta_sum->value_); - const auto *curr_val = nostd::get_if(&curr_sum->value_); - if (delta_val == nullptr || curr_val == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("LongSumAggregation::Merge - Loss of type"); - return std::unique_ptr(new LongSumAggregation(point_data_.is_monotonic_)); - } + const auto delta_val = delta_sum.value_; + const auto curr_val = curr_sum.value_; std::unique_ptr aggr(new LongSumAggregation(point_data_.is_monotonic_)); - static_cast(aggr.get())->point_data_.value_ = *delta_val + *curr_val; + static_cast(aggr.get())->point_data_.value_ = delta_val + curr_val; return aggr; } std::unique_ptr LongSumAggregation::Diff(const Aggregation &next) const noexcept { - auto next_point = static_cast(next).ToPoint(); - auto curr_point = ToPoint(); + auto next_sum = static_cast(next).ToPointData(); + auto curr_sum = ToPointData(); - const auto *next_sum = nostd::get_if(&next_point); - const auto *curr_sum = nostd::get_if(&curr_point); - if (next_sum == nullptr || curr_sum == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("LongSumAggregation::Diff - Loss of type"); - return std::unique_ptr(new LongSumAggregation(point_data_.is_monotonic_)); - } - - const auto *next_val = nostd::get_if(&next_sum->value_); - const auto *curr_val = nostd::get_if(&curr_sum->value_); - if (next_val == nullptr || curr_val == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("LongSumAggregation::Diff - Loss of type"); - return std::unique_ptr(new LongSumAggregation(point_data_.is_monotonic_)); - } + const auto next_val = next_sum.value_; + const auto curr_val = curr_sum.value_; std::unique_ptr aggr(new LongSumAggregation(point_data_.is_monotonic_)); - static_cast(aggr.get())->point_data_.value_ = *next_val - *curr_val; + static_cast(aggr.get())->point_data_.value_ = next_val - curr_val; return aggr; } PointType LongSumAggregation::ToPoint() const noexcept +{ + // Wrap in a PointType variant + return ToPointData(); +} + +LongSumPointData LongSumAggregation::ToPointData() const noexcept { const std::lock_guard locked(lock_); return point_data_; @@ -107,7 +86,7 @@ DoubleSumAggregation::DoubleSumAggregation(bool is_monotonic) point_data_.is_monotonic_ = is_monotonic; } -DoubleSumAggregation::DoubleSumAggregation(const SumPointData &data) : point_data_(data) {} +DoubleSumAggregation::DoubleSumAggregation(const DoubleSumPointData &data) : point_data_(data) {} void DoubleSumAggregation::Aggregate(double value, const PointAttributes & /* attributes */) noexcept @@ -121,62 +100,42 @@ void DoubleSumAggregation::Aggregate(double value, return; } const std::lock_guard locked(lock_); - point_data_.value_ = nostd::get(point_data_.value_) + value; + point_data_.value_ = point_data_.value_ + value; } std::unique_ptr DoubleSumAggregation::Merge(const Aggregation &delta) const noexcept { - auto delta_point = static_cast(delta).ToPoint(); - auto curr_point = ToPoint(); + auto delta_sum = static_cast(delta).ToPointData(); + auto curr_sum = ToPointData(); - const auto *delta_sum = nostd::get_if(&delta_point); - const auto *curr_sum = nostd::get_if(&curr_point); - if (delta_sum == nullptr || curr_sum == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("DoubleSumAggregation::Merge - Loss of type"); - return std::unique_ptr(new DoubleSumAggregation(point_data_.is_monotonic_)); - } - - const auto *delta_val = nostd::get_if(&delta_sum->value_); - const auto *curr_val = nostd::get_if(&curr_sum->value_); - if (delta_val == nullptr || curr_val == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("DoubleSumAggregation::Merge - Loss of type"); - return std::unique_ptr(new DoubleSumAggregation(point_data_.is_monotonic_)); - } + const auto delta_val = delta_sum.value_; + const auto curr_val = curr_sum.value_; std::unique_ptr aggr(new DoubleSumAggregation(point_data_.is_monotonic_)); - static_cast(aggr.get())->point_data_.value_ = *delta_val + *curr_val; + static_cast(aggr.get())->point_data_.value_ = delta_val + curr_val; return aggr; } std::unique_ptr DoubleSumAggregation::Diff(const Aggregation &next) const noexcept { - auto next_point = static_cast(next).ToPoint(); - auto curr_point = ToPoint(); + auto next_sum = static_cast(next).ToPointData(); + auto curr_sum = ToPointData(); - const auto *next_sum = nostd::get_if(&next_point); - const auto *curr_sum = nostd::get_if(&curr_point); - if (next_sum == nullptr || curr_sum == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("DoubleSumAggregation::Diff - Loss of type"); - return std::unique_ptr(new DoubleSumAggregation(point_data_.is_monotonic_)); - } - - const auto *next_val = nostd::get_if(&next_sum->value_); - const auto *curr_val = nostd::get_if(&curr_sum->value_); - if (next_val == nullptr || curr_val == nullptr) - { - OTEL_INTERNAL_LOG_ERROR("DoubleSumAggregation::Diff - Loss of type"); - return std::unique_ptr(new DoubleSumAggregation(point_data_.is_monotonic_)); - } + const auto next_val = next_sum.value_; + const auto curr_val = curr_sum.value_; std::unique_ptr aggr(new DoubleSumAggregation(point_data_.is_monotonic_)); - static_cast(aggr.get())->point_data_.value_ = *next_val - *curr_val; + static_cast(aggr.get())->point_data_.value_ = next_val - curr_val; return aggr; } PointType DoubleSumAggregation::ToPoint() const noexcept +{ + // Wrap in a PointType variant + return ToPointData(); +} + +DoubleSumPointData DoubleSumAggregation::ToPointData() const noexcept { const std::lock_guard locked(lock_); return point_data_; diff --git a/sdk/test/configuration/programmatic_configuration_test.cc b/sdk/test/configuration/programmatic_configuration_test.cc index a6635250db..891e832b57 100644 --- a/sdk/test/configuration/programmatic_configuration_test.cc +++ b/sdk/test/configuration/programmatic_configuration_test.cc @@ -927,7 +927,7 @@ TEST_F(ProgrammaticConfigTest, MeterProviderWithHistogramAggregationViews) { found_explicit_histogram = true; } - else if (nostd::holds_alternative(point_data)) + else if (nostd::holds_alternative(point_data)) { found_default_counter = true; } diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index 3b67bdf98d..f1b29af8f4 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -140,28 +140,26 @@ TEST(Aggregation, LongSumAggregation) { LongSumAggregation aggr(true); auto data = aggr.ToPoint(); - ASSERT_TRUE(nostd::holds_alternative(data)); - auto sum_data = nostd::get(data); - ASSERT_TRUE(nostd::holds_alternative(sum_data.value_)); - EXPECT_EQ(nostd::get(sum_data.value_), 0); + ASSERT_TRUE(nostd::holds_alternative(data)); + auto sum_data = nostd::get(data); + EXPECT_EQ(sum_data.value_, 0); aggr.Aggregate(static_cast(12), {}); aggr.Aggregate(static_cast(0), {}); - sum_data = nostd::get(aggr.ToPoint()); - EXPECT_EQ(nostd::get(sum_data.value_), 12); + sum_data = nostd::get(aggr.ToPoint()); + EXPECT_EQ(sum_data.value_, 12); } TEST(Aggregation, DoubleSumAggregation) { DoubleSumAggregation aggr(true); auto data = aggr.ToPoint(); - ASSERT_TRUE(nostd::holds_alternative(data)); - auto sum_data = nostd::get(data); - ASSERT_TRUE(nostd::holds_alternative(sum_data.value_)); - EXPECT_EQ(nostd::get(sum_data.value_), 0); + ASSERT_TRUE(nostd::holds_alternative(data)); + auto sum_data = nostd::get(data); + EXPECT_EQ(sum_data.value_, 0); aggr.Aggregate(12.0, {}); aggr.Aggregate(1.0, {}); - sum_data = nostd::get(aggr.ToPoint()); - EXPECT_EQ(nostd::get(sum_data.value_), 13.0); + sum_data = nostd::get(aggr.ToPoint()); + EXPECT_EQ(sum_data.value_, 13.0); } TEST(Aggregation, LongLastValueAggregation) diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index a11a75a104..39824ccded 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -88,16 +88,16 @@ TEST_P(AsyncWritableMetricStorageTestFixture, TestAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count1); + EXPECT_EQ(data.value_, get_count1); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count1); + EXPECT_EQ(data.value_, put_count1); } } return true; @@ -115,17 +115,17 @@ TEST_P(AsyncWritableMetricStorageTestFixture, TestAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2); + EXPECT_EQ(data.value_, get_count2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2 - get_count1); + EXPECT_EQ(data.value_, get_count2 - get_count1); } } else if (opentelemetry::nostd::get( @@ -133,11 +133,11 @@ TEST_P(AsyncWritableMetricStorageTestFixture, TestAggregation) { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2); + EXPECT_EQ(data.value_, put_count2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2 - put_count1); + EXPECT_EQ(data.value_, put_count2 - put_count1); } } } @@ -183,16 +183,16 @@ TEST_P(WritableMetricStorageTestUpDownFixture, TestAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count1); + EXPECT_EQ(data.value_, get_count1); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count1); + EXPECT_EQ(data.value_, put_count1); } } return true; @@ -212,17 +212,17 @@ TEST_P(WritableMetricStorageTestUpDownFixture, TestAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2); + EXPECT_EQ(data.value_, get_count2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2 - get_count1); + EXPECT_EQ(data.value_, get_count2 - get_count1); } } else if (opentelemetry::nostd::get( @@ -230,11 +230,11 @@ TEST_P(WritableMetricStorageTestUpDownFixture, TestAggregation) { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2); + EXPECT_EQ(data.value_, put_count2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2 - put_count1); + EXPECT_EQ(data.value_, put_count2 - put_count1); } } } @@ -373,17 +373,17 @@ TEST_P(WritableMetricStorageTestFilteredAttributesFixture, TestAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); EXPECT_EQ(data_attr.attributes.end(), data_attr.attributes.find("version")); ++collected_points; if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count_v1 + get_count_v2); + EXPECT_EQ(data.value_, get_count_v1 + get_count_v2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count_v1); + EXPECT_EQ(data.value_, put_count_v1); } } return true; @@ -405,19 +405,18 @@ TEST_P(WritableMetricStorageTestFilteredAttributesFixture, TestAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); EXPECT_EQ(data_attr.attributes.end(), data_attr.attributes.find("version")); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), - get_count_v1_2 + get_count_v2_2); + EXPECT_EQ(data.value_, get_count_v1_2 + get_count_v2_2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), + EXPECT_EQ(data.value_, (get_count_v1_2 + get_count_v2_2) - (get_count_v1 + get_count_v2)); } } @@ -425,12 +424,11 @@ TEST_P(WritableMetricStorageTestFilteredAttributesFixture, TestAggregation) { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count_v1_2); + EXPECT_EQ(data.value_, put_count_v1_2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), - put_count_v1_2 - put_count_v1); + EXPECT_EQ(data.value_, put_count_v1_2 - put_count_v1); } } } @@ -478,10 +476,10 @@ TEST(WritableMetricStorageTestFilteredAttributes, TestUpDownCounterAllAttributes collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); ++collected_points; EXPECT_EQ(0, data_attr.attributes.size()); - EXPECT_DOUBLE_EQ(opentelemetry::nostd::get(data.value_), -1.0); + EXPECT_DOUBLE_EQ(data.value_, -1.0); } return true; }); @@ -491,7 +489,7 @@ TEST(WritableMetricStorageTestFilteredAttributes, TestUpDownCounterAllAttributes namespace { // Collects the emitted sum points, so assertions don't depend on iteration order. -template +template std::vector> CollectSumPoints( opentelemetry::sdk::metrics::AsyncMetricStorage &storage, const std::shared_ptr &collector, @@ -504,8 +502,8 @@ std::vector> CollectSumPoints( collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); - points.emplace_back(data_attr.attributes, opentelemetry::nostd::get(data.value_)); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); + points.emplace_back(data_attr.attributes, data.value_); } return true; }); @@ -553,7 +551,7 @@ TEST(WritableMetricStorageMultiCallback, MonotonicSumCombinesAcrossCallbacks) storage.RecordLong(from_second_callback, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); - auto points = CollectSumPoints(storage, collector, collectors); + auto points = CollectSumPoints(storage, collector, collectors); ASSERT_EQ(1, points.size()); EXPECT_EQ(0, points[0].first.size()); EXPECT_EQ(30, points[0].second); @@ -582,7 +580,7 @@ TEST(WritableMetricStorageDisappearingSeries, MonotonicSumKeepsEarlierContributi storage.RecordLong(first_round, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); - auto points = CollectSumPoints(storage, collector, collectors); + auto points = CollectSumPoints(storage, collector, collectors); ASSERT_EQ(1, points.size()); EXPECT_EQ(30, points[0].second); @@ -591,7 +589,7 @@ TEST(WritableMetricStorageDisappearingSeries, MonotonicSumKeepsEarlierContributi storage.RecordLong(second_round, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); - points = CollectSumPoints(storage, collector, collectors); + points = CollectSumPoints(storage, collector, collectors); ASSERT_EQ(1, points.size()); EXPECT_EQ(35, points[0].second); } @@ -624,7 +622,7 @@ TEST(WritableMetricStorageDisappearingSeries, UpDownCounterFollowsTheTotal) storage.RecordLong(second_process, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); - auto points = CollectSumPoints(storage, collector, collectors); + auto points = CollectSumPoints(storage, collector, collectors); ASSERT_EQ(1, points.size()); EXPECT_EQ(1, points[0].first.size()); EXPECT_EQ(150, points[0].second); @@ -632,7 +630,7 @@ TEST(WritableMetricStorageDisappearingSeries, UpDownCounterFollowsTheTotal) storage.RecordLong(first_process, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); - points = CollectSumPoints(storage, collector, collectors); + points = CollectSumPoints(storage, collector, collectors); ASSERT_EQ(1, points.size()); EXPECT_EQ(100, points[0].second); } @@ -669,7 +667,7 @@ TEST(WritableMetricStorageCardinalityLimit, OverflowCombinesContributions) storage.RecordLong(from_second_callback, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); - auto points = CollectSumPoints(storage, collector, collectors); + auto points = CollectSumPoints(storage, collector, collectors); ASSERT_EQ(kCardinalityLimit + 1, points.size()); diff --git a/sdk/test/metrics/bound_sync_instruments_test.cc b/sdk/test/metrics/bound_sync_instruments_test.cc index fe0fb30209..b04d6324e0 100644 --- a/sdk/test/metrics/bound_sync_instruments_test.cc +++ b/sdk/test/metrics/bound_sync_instruments_test.cc @@ -119,8 +119,8 @@ int64_t SumLongFor(SyncMetricStorage &storage, } if (match) { - const auto &sp = opentelemetry::nostd::get(p.point_data); - total += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + total += sp.value_; } } return true; @@ -225,8 +225,8 @@ TEST(BoundSyncInstruments, BoundCounterBindEmptyAttributes) for (const auto &p : md.point_data_attr_) { EXPECT_TRUE(p.attributes.empty()); - const auto &sp = opentelemetry::nostd::get(p.point_data); - EXPECT_EQ(opentelemetry::nostd::get(sp.value_), 5); + const auto &sp = opentelemetry::nostd::get(p.point_data); + EXPECT_EQ(sp.value_, 5); seen = true; } return true; @@ -586,8 +586,8 @@ TEST(BoundSyncInstruments, BoundSurvivesCumulativeCollect) std::chrono::system_clock::now(), [&](const MetricData &md) { for (const auto &p : md.point_data_attr_) { - const auto &sp = opentelemetry::nostd::get(p.point_data); - total += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + total += sp.value_; } return true; }); @@ -627,8 +627,8 @@ TEST(BoundSyncInstruments, BoundAndUnboundShareDatapoint) count += md.point_data_attr_.size(); for (const auto &p : md.point_data_attr_) { - const auto &sp = opentelemetry::nostd::get(p.point_data); - total += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + total += sp.value_; } return true; }); @@ -672,8 +672,8 @@ TEST(BoundSyncInstruments, BindingAtOverflowGoesToOverflowBucket) if (p.attributes.find(kAttributesLimitOverflowKey) != p.attributes.end()) { seen = true; - const auto &sp = opentelemetry::nostd::get(p.point_data); - ov_value += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + ov_value += sp.value_; } } return true; @@ -801,8 +801,8 @@ TEST(BoundSyncInstruments, BindOnExistingUnboundKeyDoesNotOverflow) auto it = p.attributes.find("k"); if (it != p.attributes.end() && opentelemetry::nostd::get(it->second) == "1") { - const auto &sp = opentelemetry::nostd::get(p.point_data); - a1_sum += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + a1_sum += sp.value_; } } return true; @@ -842,8 +842,8 @@ TEST(BoundSyncInstruments, UnboundOnExistingBoundKeyDoesNotOverflow) auto it = p.attributes.find("k"); if (it == p.attributes.end()) continue; - const auto &sp = opentelemetry::nostd::get(p.point_data); - auto v = opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + auto v = sp.value_; auto s = opentelemetry::nostd::get(it->second); if (s == "1") a1_sum += v; @@ -907,8 +907,8 @@ TEST(BoundSyncInstruments, RetainedBoundEntriesOverflowValue) { if (p.attributes.find(kAttributesLimitOverflowKey) == p.attributes.end()) continue; - const auto &sp = opentelemetry::nostd::get(p.point_data); - overflow_sum += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + overflow_sum += sp.value_; } return true; }); @@ -941,8 +941,8 @@ TEST(BoundSyncInstruments, NoAttributeUnboundFollowsUnifiedPolicyLong) { if (p.attributes.find(kAttributesLimitOverflowKey) == p.attributes.end()) continue; - const auto &sp = opentelemetry::nostd::get(p.point_data); - overflow_sum += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + overflow_sum += sp.value_; } return true; }); @@ -972,8 +972,8 @@ TEST(BoundSyncInstruments, NoAttributeUnboundFollowsUnifiedPolicyDouble) { if (p.attributes.find(kAttributesLimitOverflowKey) == p.attributes.end()) continue; - const auto &sp = opentelemetry::nostd::get(p.point_data); - overflow_sum += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + overflow_sum += sp.value_; } return true; }); @@ -1014,8 +1014,8 @@ TEST(BoundSyncInstruments, MixedBoundUnboundAcrossCumulativeCollections) std::chrono::system_clock::now(), [&](const MetricData &md) { for (const auto &p : md.point_data_attr_) { - const auto &sp = opentelemetry::nostd::get(p.point_data); - total += opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + total += sp.value_; } return true; }); @@ -1117,8 +1117,8 @@ TEST(BoundSyncInstruments, OverflowParityAllowsFillingRemainingSlot) opentelemetry::nostd::get(it->second) == "key") { a5_seen = true; - const auto &sp = opentelemetry::nostd::get(p.point_data); - a5_value = opentelemetry::nostd::get(sp.value_); + const auto &sp = opentelemetry::nostd::get(p.point_data); + a5_value = sp.value_; } } return true; diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc index cab5f91209..67617fbd78 100644 --- a/sdk/test/metrics/cardinality_limit_test.cc +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -80,8 +80,7 @@ TEST(CardinalityLimit, AttributesHashMapBasicTests) auto agg1 = hash_map.GetOrSetDefault(GetOverflowAttributes(), aggregation_callback); EXPECT_NE(agg1, nullptr); auto sum_agg1 = static_cast(agg1); - EXPECT_EQ(nostd::get(nostd::get(sum_agg1->ToPoint()).value_), - record_value * 5); + EXPECT_EQ(nostd::get(sum_agg1->ToPoint()).value_, record_value * 5); // get remaining metric points for (auto i = 0; i < 10; i++) { @@ -91,12 +90,12 @@ TEST(CardinalityLimit, AttributesHashMapBasicTests) auto sum_agg2 = static_cast(agg2); if (i < 5) { - EXPECT_EQ(nostd::get(nostd::get(sum_agg2->ToPoint()).value_), + EXPECT_EQ(nostd::get(sum_agg2->ToPoint()).value_, record_value * 2); // 1 from first recording, 1 from third recording } else { - EXPECT_EQ(nostd::get(nostd::get(sum_agg2->ToPoint()).value_), + EXPECT_EQ(nostd::get(sum_agg2->ToPoint()).value_, record_value); // 1 from first recording } } @@ -146,7 +145,7 @@ TEST_P(WritableMetricStorageCardinalityLimitTestFixture, LongCounterSumAggregati collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); count_attributes++; if (data_attr.attributes.begin()->first == kAttributesLimitOverflowKey) { @@ -155,7 +154,7 @@ TEST_P(WritableMetricStorageCardinalityLimitTestFixture, LongCounterSumAggregati // value `true`. EXPECT_EQ(data_attr.attributes.size(), 1u); EXPECT_EQ(nostd::get(data_attr.attributes.begin()->second), true); - EXPECT_EQ(nostd::get(data.value_), record_value * 5); + EXPECT_EQ(data.value_, record_value * 5); overflow_present = true; } } diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index 4b0f2d9c5d..bbac7e472e 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -615,10 +615,10 @@ int64_t CollectCounterSum(MetricReader *reader, } for (const auto &pd : md.point_data_attr_) { - const auto *sum_point = opentelemetry::nostd::get_if(&pd.point_data); + const auto *sum_point = opentelemetry::nostd::get_if(&pd.point_data); if (sum_point != nullptr) { - const auto *value = opentelemetry::nostd::get_if(&sum_point->value_); + const auto *value = (&sum_point->value_); if (value != nullptr) { sum = (sum == -1) ? *value : sum + *value; @@ -648,10 +648,10 @@ std::map CollectCounterSums(MetricReader *reader, { for (const auto &pd : md.point_data_attr_) { - const auto *sum_point = opentelemetry::nostd::get_if(&pd.point_data); + const auto *sum_point = opentelemetry::nostd::get_if(&pd.point_data); if (sum_point != nullptr) { - const auto *value = opentelemetry::nostd::get_if(&sum_point->value_); + const auto *value = (&sum_point->value_); if (value != nullptr) { sums[md.instrument_descriptor.name_] += *value; diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index 42c68d3ee9..717f666af4 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -265,10 +265,14 @@ class MeterCreateInstrumentTest : public ::testing::Test }; auto get_point_data_sum = [&value_to_double](const PointType &point_data) -> PointDataSum { - if (auto *sum_point_data = nostd::get_if(&point_data)) + if (auto *sum_point_data = nostd::get_if(&point_data)) { return PointDataSum{AggregationType::kSum, value_to_double(sum_point_data->value_)}; } + if (auto *sum_point_data = nostd::get_if(&point_data)) + { + return PointDataSum{AggregationType::kSum, sum_point_data->value_}; + } else if (auto *histogram_point_data = nostd::get_if(&point_data)) { diff --git a/sdk/test/metrics/metric_collector_test.cc b/sdk/test/metrics/metric_collector_test.cc index c97f9221f9..05cae757e9 100644 --- a/sdk/test/metrics/metric_collector_test.cc +++ b/sdk/test/metrics/metric_collector_test.cc @@ -315,8 +315,8 @@ TEST_F(MetricCollectorTest, CollectWithMetricFilterTestAttributesTest1) EXPECT_EQ(metric.point_data_attr_.size(), 10); for (const PointDataAttributes &pda : metric.point_data_attr_) { - auto sum_point_data = nostd::get(pda.point_data); - auto value = nostd::get(sum_point_data.value_); + auto sum_point_data = nostd::get(pda.point_data); + auto value = sum_point_data.value_; auto stream = std::stoi(nostd::get(pda.attributes.GetAttributes().at("stream"))); auto river = @@ -396,8 +396,8 @@ TEST_F(MetricCollectorTest, CollectWithMetricFilterTestAttributesTest2) EXPECT_EQ(metric.point_data_attr_.size(), 3); for (const PointDataAttributes &pda : metric.point_data_attr_) { - auto sum_point_data = nostd::get(pda.point_data); - auto value = nostd::get(sum_point_data.value_); + auto sum_point_data = nostd::get(pda.point_data); + auto value = sum_point_data.value_; auto stream = std::stoi(nostd::get(pda.attributes.GetAttributes().at("stream"))); auto river = std::stoi(nostd::get(pda.attributes.GetAttributes().at("river"))); diff --git a/sdk/test/metrics/sum_aggregation_benchmark.cc b/sdk/test/metrics/sum_aggregation_benchmark.cc index 6d118951ba..689cc89b28 100644 --- a/sdk/test/metrics/sum_aggregation_benchmark.cc +++ b/sdk/test/metrics/sum_aggregation_benchmark.cc @@ -51,7 +51,7 @@ void BM_SumAggregation(benchmark::State &state) { measurements[i] = static_cast(distribution(generator)); } - std::vector actuals; + std::vector actuals; std::vector collectionThreads; std::function collectMetrics = [&reader, &actuals]() { reader->Collect([&](ResourceMetrics &rm) { @@ -61,7 +61,7 @@ void BM_SumAggregation(benchmark::State &state) { for (const PointDataAttributes &dp : md.point_data_attr_) { - actuals.push_back(opentelemetry::nostd::get(dp.point_data)); + actuals.push_back(opentelemetry::nostd::get(dp.point_data)); } } } diff --git a/sdk/test/metrics/sum_aggregation_test.cc b/sdk/test/metrics/sum_aggregation_test.cc index 6fd1ba458c..81a2ddd4b1 100644 --- a/sdk/test/metrics/sum_aggregation_test.cc +++ b/sdk/test/metrics/sum_aggregation_test.cc @@ -74,7 +74,7 @@ TEST(HistogramToSum, Double) h->Record(50, {}); h->Record(1e6, {}); - std::vector actuals; + std::vector actuals; reader->Collect([&](ResourceMetrics &rm) { for (const ScopeMetrics &smd : rm.scope_metric_data_) { @@ -82,7 +82,7 @@ TEST(HistogramToSum, Double) { for (const PointDataAttributes &dp : md.point_data_attr_) { - actuals.push_back(opentelemetry::nostd::get(dp.point_data)); + actuals.push_back(opentelemetry::nostd::get(dp.point_data)); } } } @@ -91,7 +91,7 @@ TEST(HistogramToSum, Double) ASSERT_EQ(1, actuals.size()); const auto &actual = actuals.at(0); - ASSERT_EQ(1000275.0, opentelemetry::nostd::get(actual.value_)); + ASSERT_EQ(1000275.0, actual.value_); } TEST(HistogramToSumFilterAttributes, Double) @@ -134,9 +134,9 @@ TEST(HistogramToSumFilterAttributes, Double) EXPECT_EQ(1, md.point_data_attr_.size()); if (md.point_data_attr_.size() == 1) { - EXPECT_EQ(15.0, opentelemetry::nostd::get(opentelemetry::nostd::get( - md.point_data_attr_[0].point_data) - .value_)); + EXPECT_EQ(15.0, + opentelemetry::nostd::get(md.point_data_attr_[0].point_data) + .value_); EXPECT_EQ(1, md.point_data_attr_[0].attributes.size()); EXPECT_NE(md.point_data_attr_[0].attributes.end(), md.point_data_attr_[0].attributes.find("attr1")); @@ -203,10 +203,10 @@ TEST(HistogramToSumFilterAttributesWithCardinalityLimit, Double) if (md.point_data_attr_[i].attributes.end() != md.point_data_attr_[i].attributes.find("attr1")) { - EXPECT_EQ(total_metrics_times * (repeat + 1), - opentelemetry::nostd::get(opentelemetry::nostd::get( - md.point_data_attr_[i].point_data) - .value_)); + EXPECT_EQ( + total_metrics_times * (repeat + 1), + opentelemetry::nostd::get(md.point_data_attr_[i].point_data) + .value_); } else { @@ -257,7 +257,7 @@ TEST(CounterToSum, Double) h->Add(50, {}); h->Add(1e6, {}); - std::vector actuals; + std::vector actuals; reader->Collect([&](ResourceMetrics &rm) { for (const ScopeMetrics &smd : rm.scope_metric_data_) { @@ -265,7 +265,7 @@ TEST(CounterToSum, Double) { for (const PointDataAttributes &dp : md.point_data_attr_) { - actuals.push_back(opentelemetry::nostd::get(dp.point_data)); + actuals.push_back(opentelemetry::nostd::get(dp.point_data)); } } } @@ -274,7 +274,7 @@ TEST(CounterToSum, Double) ASSERT_EQ(1, actuals.size()); const auto &actual = actuals.at(0); - ASSERT_EQ(1000275.0, opentelemetry::nostd::get(actual.value_)); + ASSERT_EQ(1000275.0, actual.value_); } TEST(CounterToSumFilterAttributes, Double) @@ -317,9 +317,9 @@ TEST(CounterToSumFilterAttributes, Double) EXPECT_EQ(1, md.point_data_attr_.size()); if (md.point_data_attr_.size() == 1) { - EXPECT_EQ(15.0, opentelemetry::nostd::get(opentelemetry::nostd::get( - md.point_data_attr_[0].point_data) - .value_)); + EXPECT_EQ(15.0, + opentelemetry::nostd::get(md.point_data_attr_[0].point_data) + .value_); EXPECT_EQ(1, md.point_data_attr_[0].attributes.size()); EXPECT_NE(md.point_data_attr_[0].attributes.end(), md.point_data_attr_[0].attributes.find("attr1")); @@ -388,10 +388,10 @@ TEST(CounterToSumFilterAttributesWithCardinalityLimit, Double) if (md.point_data_attr_[i].attributes.find("attr1") != md.point_data_attr_[i].attributes.end()) { - EXPECT_EQ(total_metrics_times * (repeat + 1), - opentelemetry::nostd::get(opentelemetry::nostd::get( - md.point_data_attr_[i].point_data) - .value_)); + EXPECT_EQ( + total_metrics_times * (repeat + 1), + opentelemetry::nostd::get(md.point_data_attr_[i].point_data) + .value_); } else { @@ -468,8 +468,7 @@ TEST(AsyncCounterToSumFilterAttributes, Double) for (const PointDataAttributes &dp : md.point_data_attr_) { ++collected_points; - EXPECT_EQ(3.0, opentelemetry::nostd::get( - opentelemetry::nostd::get(dp.point_data).value_)); + EXPECT_EQ(3.0, opentelemetry::nostd::get(dp.point_data).value_); EXPECT_EQ(1, dp.attributes.size()); EXPECT_NE(dp.attributes.end(), dp.attributes.find("attr1")); EXPECT_EQ(dp.attributes.end(), dp.attributes.find("version")); @@ -520,7 +519,7 @@ TEST_P(UpDownCounterToSumFixture, Double) h->Add(25, {}); h->Add(-30, {}); - std::vector actuals; + std::vector actuals; reader->Collect([&](ResourceMetrics &rm) { for (const ScopeMetrics &smd : rm.scope_metric_data_) { @@ -528,7 +527,7 @@ TEST_P(UpDownCounterToSumFixture, Double) { for (const PointDataAttributes &dp : md.point_data_attr_) { - actuals.push_back(opentelemetry::nostd::get(dp.point_data)); + actuals.push_back(opentelemetry::nostd::get(dp.point_data)); } } } @@ -537,7 +536,7 @@ TEST_P(UpDownCounterToSumFixture, Double) ASSERT_EQ(1, actuals.size()); const auto &actual = actuals.at(0); - ASSERT_EQ(15.0, opentelemetry::nostd::get(actual.value_)); + ASSERT_EQ(15.0, actual.value_); } INSTANTIATE_TEST_SUITE_P(UpDownCounterToSum, UpDownCounterToSumFixture, diff --git a/sdk/test/metrics/sync_metric_storage_counter_test.cc b/sdk/test/metrics/sync_metric_storage_counter_test.cc index 1c26a2637d..56574124ac 100644 --- a/sdk/test/metrics/sync_metric_storage_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_counter_test.cc @@ -88,17 +88,17 @@ TEST_P(CounterWritableMetricStorageTestFixture, LongCounterSumAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(data.value_, expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(data.value_, expected_total_put_requests); count_attributes++; } } @@ -123,18 +123,18 @@ TEST_P(CounterWritableMetricStorageTestFixture, LongCounterSumAggregation) } for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(data.value_, expected_total_get_requests); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(data.value_, expected_total_put_requests); } } return true; @@ -157,17 +157,17 @@ TEST_P(CounterWritableMetricStorageTestFixture, LongCounterSumAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(data.value_, expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(data.value_, expected_total_put_requests); count_attributes++; } } @@ -232,17 +232,17 @@ TEST_P(CounterWritableMetricStorageTestFixture, DoubleCounterSumAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(data.value_, expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(data.value_, expected_total_put_requests); count_attributes++; } } @@ -269,18 +269,18 @@ TEST_P(CounterWritableMetricStorageTestFixture, DoubleCounterSumAggregation) } for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(data.value_, expected_total_get_requests); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(data.value_, expected_total_put_requests); } } return true; @@ -305,17 +305,17 @@ TEST_P(CounterWritableMetricStorageTestFixture, DoubleCounterSumAggregation) collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (const auto &data_attr : metric_data.point_data_attr_) { - const auto &data = opentelemetry::nostd::get(data_attr.point_data); + const auto &data = opentelemetry::nostd::get(data_attr.point_data); if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(data.value_, expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(data.value_, expected_total_put_requests); count_attributes++; } } diff --git a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc index c4766b6453..ae6d3f8c6f 100644 --- a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc @@ -84,28 +84,26 @@ TEST_P(UpDownCounterWritableMetricStorageTestFixture, LongUpDownCounterSumAggreg // Some computation here auto collection_ts = std::chrono::system_clock::now(); size_t count_attributes = 0; - storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData &data) { - for (auto data_attr : data.point_data_attr_) - { - auto sum_data = opentelemetry::nostd::get(data_attr.point_data); - if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "GET") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_get_requests); - count_attributes++; - } - else if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "PUT") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_put_requests); - count_attributes++; - } - } - return true; - }); + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &data) { + for (auto data_attr : data.point_data_attr_) + { + auto sum_data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + EXPECT_EQ(sum_data.value_, expected_total_active_get_requests); + count_attributes++; + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + EXPECT_EQ(sum_data.value_, expected_total_active_put_requests); + count_attributes++; + } + } + return true; + }); EXPECT_EQ(count_attributes, 2); // GET and PUT // In case of delta temporarily, subsequent collection would contain new data points, so resetting // the counts @@ -118,32 +116,30 @@ TEST_P(UpDownCounterWritableMetricStorageTestFixture, LongUpDownCounterSumAggreg // collect one more time. collection_ts = std::chrono::system_clock::now(); count_attributes = 0; - storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData &data) { - if (temporality == AggregationTemporality::kCumulative) - { - EXPECT_EQ(data.start_ts, sdk_start_ts); - } - for (auto data_attr : data.point_data_attr_) - { - auto sum_data = opentelemetry::nostd::get(data_attr.point_data); - if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "GET") - { - count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_get_requests); - } - else if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "PUT") - { - count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_put_requests); - } - } - return true; - }); + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &data) { + if (temporality == AggregationTemporality::kCumulative) + { + EXPECT_EQ(data.start_ts, sdk_start_ts); + } + for (auto data_attr : data.point_data_attr_) + { + auto sum_data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + count_attributes++; + EXPECT_EQ(sum_data.value_, expected_total_active_get_requests); + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + count_attributes++; + EXPECT_EQ(sum_data.value_, expected_total_active_put_requests); + } + } + return true; + }); if (temporality == AggregationTemporality::kCumulative) { EXPECT_EQ(count_attributes, 2); // GET AND PUT @@ -160,28 +156,26 @@ TEST_P(UpDownCounterWritableMetricStorageTestFixture, LongUpDownCounterSumAggreg collection_ts = std::chrono::system_clock::now(); count_attributes = 0; - storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData &data) { - for (auto data_attr : data.point_data_attr_) - { - auto sum_data = opentelemetry::nostd::get(data_attr.point_data); - if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "GET") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_get_requests); - count_attributes++; - } - else if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "PUT") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_put_requests); - count_attributes++; - } - } - return true; - }); + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &data) { + for (auto data_attr : data.point_data_attr_) + { + auto sum_data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + EXPECT_EQ(sum_data.value_, expected_total_active_get_requests); + count_attributes++; + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + EXPECT_EQ(sum_data.value_, expected_total_active_put_requests); + count_attributes++; + } + } + return true; + }); EXPECT_EQ(count_attributes, 2); // GET and PUT } @@ -237,28 +231,26 @@ TEST_P(UpDownCounterWritableMetricStorageTestFixture, DoubleUpDownCounterSumAggr // Some computation here auto collection_ts = std::chrono::system_clock::now(); size_t count_attributes = 0; - storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData &data) { - for (auto data_attr : data.point_data_attr_) - { - auto sum_data = opentelemetry::nostd::get(data_attr.point_data); - if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "GET") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_get_requests); - count_attributes++; - } - else if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "PUT") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_put_requests); - count_attributes++; - } - } - return true; - }); + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &data) { + for (auto data_attr : data.point_data_attr_) + { + auto sum_data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + EXPECT_EQ(sum_data.value_, expected_total_active_get_requests); + count_attributes++; + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + EXPECT_EQ(sum_data.value_, expected_total_active_put_requests); + count_attributes++; + } + } + return true; + }); EXPECT_EQ(count_attributes, 2); // GET and PUT // In case of delta temporarily, subsequent collection would contain new data points, so resetting @@ -272,32 +264,30 @@ TEST_P(UpDownCounterWritableMetricStorageTestFixture, DoubleUpDownCounterSumAggr // collect one more time. collection_ts = std::chrono::system_clock::now(); count_attributes = 0; - storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData &data) { - if (temporality == AggregationTemporality::kCumulative) - { - EXPECT_EQ(data.start_ts, sdk_start_ts); - } - for (auto data_attr : data.point_data_attr_) - { - auto sum_data = opentelemetry::nostd::get(data_attr.point_data); - if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "GET") - { - count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_get_requests); - } - else if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "PUT") - { - count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_put_requests); - } - } - return true; - }); + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &data) { + if (temporality == AggregationTemporality::kCumulative) + { + EXPECT_EQ(data.start_ts, sdk_start_ts); + } + for (auto data_attr : data.point_data_attr_) + { + auto sum_data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + count_attributes++; + EXPECT_EQ(sum_data.value_, expected_total_active_get_requests); + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + count_attributes++; + EXPECT_EQ(sum_data.value_, expected_total_active_put_requests); + } + } + return true; + }); if (temporality == AggregationTemporality::kCumulative) { EXPECT_EQ(count_attributes, 2); // GET AND PUT @@ -314,28 +304,26 @@ TEST_P(UpDownCounterWritableMetricStorageTestFixture, DoubleUpDownCounterSumAggr collection_ts = std::chrono::system_clock::now(); count_attributes = 0; - storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData &data) { - for (auto data_attr : data.point_data_attr_) - { - auto sum_data = opentelemetry::nostd::get(data_attr.point_data); - if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "GET") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_get_requests); - count_attributes++; - } - else if (opentelemetry::nostd::get( - data_attr.attributes.find("RequestType")->second) == "PUT") - { - EXPECT_EQ(opentelemetry::nostd::get(sum_data.value_), - expected_total_active_put_requests); - count_attributes++; - } - } - return true; - }); + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &data) { + for (auto data_attr : data.point_data_attr_) + { + auto sum_data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + EXPECT_EQ(sum_data.value_, expected_total_active_get_requests); + count_attributes++; + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + EXPECT_EQ(sum_data.value_, expected_total_active_put_requests); + count_attributes++; + } + } + return true; + }); EXPECT_EQ(count_attributes, 2); // GET and PUT } INSTANTIATE_TEST_SUITE_P(WritableMetricStorageTestDouble,