Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove throw check from metrics with noexcept #1560

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions api/test/metrics/noop_sync_instrument_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ TEST(Counter, Add)
new opentelemetry::metrics::NoopCounter<long>("test", "none", "unitless")};

std::map<std::string, std::string> labels = {{"k1", "v1"}};
EXPECT_NO_THROW(counter->Add(10l, labels));
EXPECT_NO_THROW(counter->Add(10l, labels, opentelemetry::context::Context{}));
EXPECT_NO_THROW(counter->Add(2l));
EXPECT_NO_THROW(counter->Add(2l, opentelemetry::context::Context{}));
EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}}));
EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}));
counter->Add(10l, labels);
counter->Add(10l, labels, opentelemetry::context::Context{});
counter->Add(2l);
counter->Add(2l, opentelemetry::context::Context{});
counter->Add(10l, {{"k1", "1"}, {"k2", 2}});
counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{});
}

TEST(histogram, Record)
Expand All @@ -27,10 +27,10 @@ TEST(histogram, Record)
new opentelemetry::metrics::NoopHistogram<long>("test", "none", "unitless")};

std::map<std::string, std::string> labels = {{"k1", "v1"}};
EXPECT_NO_THROW(counter->Record(10l, labels, opentelemetry::context::Context{}));
EXPECT_NO_THROW(counter->Record(2l, opentelemetry::context::Context{}));
EXPECT_NO_THROW(
counter->Record(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}));
counter->Record(10l, labels, opentelemetry::context::Context{});
counter->Record(2l, opentelemetry::context::Context{});

counter->Record(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{});
}

TEST(UpDownCountr, Record)
Expand All @@ -39,12 +39,12 @@ TEST(UpDownCountr, Record)
new opentelemetry::metrics::NoopUpDownCounter<long>("test", "none", "unitless")};

std::map<std::string, std::string> labels = {{"k1", "v1"}};
EXPECT_NO_THROW(counter->Add(10l, labels));
EXPECT_NO_THROW(counter->Add(10l, labels, opentelemetry::context::Context{}));
EXPECT_NO_THROW(counter->Add(2l));
EXPECT_NO_THROW(counter->Add(2l, opentelemetry::context::Context{}));
EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}}));
EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}));
counter->Add(10l, labels);
counter->Add(10l, labels, opentelemetry::context::Context{});
counter->Add(2l);
counter->Add(2l, opentelemetry::context::Context{});
counter->Add(10l, {{"k1", "1"}, {"k2", 2}});
counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{});
}

#endif
32 changes: 16 additions & 16 deletions sdk/test/metrics/aggregation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ TEST(Aggregation, LongSumAggregation)
auto sum_data = nostd::get<SumPointData>(data);
ASSERT_TRUE(nostd::holds_alternative<long>(sum_data.value_));
EXPECT_EQ(nostd::get<long>(sum_data.value_), 0l);
EXPECT_NO_THROW(aggr.Aggregate(12l, {}));
EXPECT_NO_THROW(aggr.Aggregate(0l, {}));
aggr.Aggregate(12l, {});
aggr.Aggregate(0l, {});
sum_data = nostd::get<SumPointData>(aggr.ToPoint());
EXPECT_EQ(nostd::get<long>(sum_data.value_), 12l);
}
Expand All @@ -34,8 +34,8 @@ TEST(Aggregation, DoubleSumAggregation)
auto sum_data = nostd::get<SumPointData>(data);
ASSERT_TRUE(nostd::holds_alternative<double>(sum_data.value_));
EXPECT_EQ(nostd::get<double>(sum_data.value_), 0);
EXPECT_NO_THROW(aggr.Aggregate(12.0, {}));
EXPECT_NO_THROW(aggr.Aggregate(1.0, {}));
aggr.Aggregate(12.0, {});
aggr.Aggregate(1.0, {});
sum_data = nostd::get<SumPointData>(aggr.ToPoint());
EXPECT_EQ(nostd::get<double>(sum_data.value_), 13.0);
}
Expand All @@ -48,8 +48,8 @@ TEST(Aggregation, LongLastValueAggregation)
auto lastvalue_data = nostd::get<LastValuePointData>(data);
ASSERT_TRUE(nostd::holds_alternative<long>(lastvalue_data.value_));
EXPECT_EQ(lastvalue_data.is_lastvalue_valid_, false);
EXPECT_NO_THROW(aggr.Aggregate(12l, {}));
EXPECT_NO_THROW(aggr.Aggregate(1l, {}));
aggr.Aggregate(12l, {});
aggr.Aggregate(1l, {});
lastvalue_data = nostd::get<LastValuePointData>(aggr.ToPoint());
EXPECT_EQ(nostd::get<long>(lastvalue_data.value_), 1.0);
}
Expand All @@ -62,8 +62,8 @@ TEST(Aggregation, DoubleLastValueAggregation)
auto lastvalue_data = nostd::get<LastValuePointData>(data);
ASSERT_TRUE(nostd::holds_alternative<double>(lastvalue_data.value_));
EXPECT_EQ(lastvalue_data.is_lastvalue_valid_, false);
EXPECT_NO_THROW(aggr.Aggregate(12.0, {}));
EXPECT_NO_THROW(aggr.Aggregate(1.0, {}));
aggr.Aggregate(12.0, {});
aggr.Aggregate(1.0, {});
lastvalue_data = nostd::get<LastValuePointData>(aggr.ToPoint());
EXPECT_EQ(nostd::get<double>(lastvalue_data.value_), 1.0);
}
Expand All @@ -78,17 +78,17 @@ TEST(Aggregation, LongHistogramAggregation)
ASSERT_TRUE(nostd::holds_alternative<std::list<long>>(histogram_data.boundaries_));
EXPECT_EQ(nostd::get<long>(histogram_data.sum_), 0);
EXPECT_EQ(histogram_data.count_, 0);
EXPECT_NO_THROW(aggr.Aggregate(12l, {})); // lies in fourth bucket
EXPECT_NO_THROW(aggr.Aggregate(100l, {})); // lies in eight bucket
aggr.Aggregate(12l, {}); // lies in fourth bucket
aggr.Aggregate(100l, {}); // lies in eight bucket
histogram_data = nostd::get<HistogramPointData>(aggr.ToPoint());
EXPECT_EQ(nostd::get<long>(histogram_data.min_), 12);
EXPECT_EQ(nostd::get<long>(histogram_data.max_), 100);
EXPECT_EQ(nostd::get<long>(histogram_data.sum_), 112);
EXPECT_EQ(histogram_data.count_, 2);
EXPECT_EQ(histogram_data.counts_[3], 1);
EXPECT_EQ(histogram_data.counts_[7], 1);
EXPECT_NO_THROW(aggr.Aggregate(13l, {})); // lies in fourth bucket
EXPECT_NO_THROW(aggr.Aggregate(252l, {})); // lies in ninth bucket
aggr.Aggregate(13l, {}); // lies in fourth bucket
aggr.Aggregate(252l, {}); // lies in ninth bucket
histogram_data = nostd::get<HistogramPointData>(aggr.ToPoint());
EXPECT_EQ(histogram_data.count_, 4);
EXPECT_EQ(histogram_data.counts_[3], 2);
Expand Down Expand Up @@ -169,17 +169,17 @@ TEST(Aggregation, DoubleHistogramAggregation)
ASSERT_TRUE(nostd::holds_alternative<std::list<double>>(histogram_data.boundaries_));
EXPECT_EQ(nostd::get<double>(histogram_data.sum_), 0);
EXPECT_EQ(histogram_data.count_, 0);
EXPECT_NO_THROW(aggr.Aggregate(12.0, {})); // lies in fourth bucket
EXPECT_NO_THROW(aggr.Aggregate(100.0, {})); // lies in eight bucket
aggr.Aggregate(12.0, {}); // lies in fourth bucket
aggr.Aggregate(100.0, {}); // lies in eight bucket
histogram_data = nostd::get<HistogramPointData>(aggr.ToPoint());
EXPECT_EQ(nostd::get<double>(histogram_data.sum_), 112);
EXPECT_EQ(histogram_data.count_, 2);
EXPECT_EQ(histogram_data.counts_[3], 1);
EXPECT_EQ(histogram_data.counts_[7], 1);
EXPECT_EQ(nostd::get<double>(histogram_data.min_), 12);
EXPECT_EQ(nostd::get<double>(histogram_data.max_), 100);
EXPECT_NO_THROW(aggr.Aggregate(13.0, {})); // lies in fourth bucket
EXPECT_NO_THROW(aggr.Aggregate(252.0, {})); // lies in ninth bucket
aggr.Aggregate(13.0, {}); // lies in fourth bucket
aggr.Aggregate(252.0, {}); // lies in ninth bucket
histogram_data = nostd::get<HistogramPointData>(aggr.ToPoint());
EXPECT_EQ(histogram_data.count_, 4);
EXPECT_EQ(histogram_data.counts_[3], 2);
Expand Down
4 changes: 2 additions & 2 deletions sdk/test/metrics/async_metric_storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation)
return true;
});
// subsequent recording after collection shouldn't fail
EXPECT_NO_THROW(storage.RecordLong(
measurements, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())));
storage.RecordLong(measurements,
opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()));
EXPECT_EQ(MeasurementFetcher::number_of_attributes, attribute_count);
}

Expand Down
9 changes: 4 additions & 5 deletions sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ using namespace opentelemetry::sdk::metrics;
TEST(NoExemplarReservoir, OfferMeasurement)
{
auto reservoir = opentelemetry::sdk::metrics::NoExemplarReservoir::GetNoExemplarReservoir();
EXPECT_NO_THROW(reservoir->OfferMeasurement(1.0, MetricAttributes{},
opentelemetry::context::Context{},
std::chrono::system_clock::now()));
EXPECT_NO_THROW(reservoir->OfferMeasurement(
1l, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()));
reservoir->OfferMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{},
std::chrono::system_clock::now());
reservoir->OfferMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{},
std::chrono::system_clock::now());
auto exemplar_data = reservoir->CollectAndReset(MetricAttributes{});
ASSERT_TRUE(exemplar_data.empty());
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/test/metrics/meter_provider_sdk_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ TEST(MeterProvider, GetMeter)
ASSERT_NE(nullptr, sdkMeter1);
std::unique_ptr<MockMetricExporter> exporter(new MockMetricExporter());
std::unique_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
ASSERT_NO_THROW(mp1.AddMetricReader(std::move(reader)));
mp1.AddMetricReader(std::move(reader));

std::unique_ptr<View> view{std::unique_ptr<View>()};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kCounter, "instru1")};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("name1", "version1", "schema1")};
ASSERT_NO_THROW(
mp1.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)));

mp1.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));
}
#endif
4 changes: 2 additions & 2 deletions sdk/test/metrics/metric_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ TEST(MetricReaderTest, BasicTests)
AggregationTemporality::kCumulative);

std::shared_ptr<MeterContext> meter_context1(new MeterContext());
EXPECT_NO_THROW(meter_context1->AddMetricReader(std::move(metric_reader1)));
meter_context1->AddMetricReader(std::move(metric_reader1));

std::unique_ptr<MetricReader> metric_reader2(new MockMetricReader());
std::shared_ptr<MeterContext> meter_context2(new MeterContext());
std::shared_ptr<MetricProducer> metric_producer{
new MetricCollector(meter_context2.get(), std::move(metric_reader2))};
EXPECT_NO_THROW(metric_producer->Collect([](ResourceMetrics &metric_data) { return true; }));
metric_producer->Collect([](ResourceMetrics &metric_data) { return true; });
}
#endif
8 changes: 4 additions & 4 deletions sdk/test/metrics/multi_metric_storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ TEST(MultiMetricStorageTest, BasicTests)
new TestMetricStorage());
SyncMultiMetricStorage storages{};
storages.AddStorage(storage);
EXPECT_NO_THROW(storages.RecordLong(10l, opentelemetry::context::Context{}));
EXPECT_NO_THROW(storages.RecordLong(20l, opentelemetry::context::Context{}));
storages.RecordLong(10l, opentelemetry::context::Context{});
storages.RecordLong(20l, opentelemetry::context::Context{});

EXPECT_NO_THROW(storages.RecordDouble(10.0, opentelemetry::context::Context{}));
EXPECT_NO_THROW(storages.RecordLong(30l, opentelemetry::context::Context{}));
storages.RecordDouble(10.0, opentelemetry::context::Context{});
storages.RecordLong(30l, opentelemetry::context::Context{});

EXPECT_EQ(static_cast<TestMetricStorage *>(storage.get())->num_calls_long, 3);
EXPECT_EQ(static_cast<TestMetricStorage *>(storage.get())->num_calls_double, 1);
Expand Down
Loading