Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Sep 29, 2023
1 parent 4134c00 commit e0bdccc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion api/include/opentelemetry/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class Gauge : public SynchronousInstrument
*
* @param value The increment amount. MUST be non-negative.
*/
virtual void Record(T value) noexcept { this->Record(value, nullptr, nullptr); }
void Record(T value) noexcept { this->Record(value, nullptr, nullptr); }

/**
* Record a value
Expand Down
52 changes: 27 additions & 25 deletions sdk/test/metrics/sync_instruments_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,42 +140,44 @@ TEST(SyncInstruments, DoubleHistogram)
opentelemetry::context::Context{});
}

#if OPEN_TELEMETRY_ABI_VERSION_NO >= 2
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
TEST(SyncInstruments, DoubleGauge)
{
InstrumentDescriptor instrument_descriptor = {
"double_gauge", "description", "1", InstrumentType::kGauge, InstrumentValueType::kDouble};
std::unique_ptr<SyncWritableMetricStorage> metric_storage(new SyncMultiMetricStorage());
DoubleGauge gauge(instrument_descriptor, std::move(metric_storage));
gauge.Record(10.10, opentelemetry::context::Context{});
gauge.Record(-10.10, opentelemetry::context::Context{}); // This is ignored.
gauge.Record(std::numeric_limits<double>::quiet_NaN(),
opentelemetry::context::Context{}); // This is ignored too
gauge.Record(std::numeric_limits<double>::infinity(),
opentelemetry::context::Context{}); // This is ignored too

gauge.Record(10.10,
opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}),
opentelemetry::context::Context{});
gauge.Record(10.10, opentelemetry::common::KeyValueIterableView<M>({}),
opentelemetry::context::Context{});
auto gauge = std::unique_ptr<opentelemetry::metrics::Gauge<double>>(
new DoubleGauge(instrument_descriptor, std::move(metric_storage)));
EXPECT_NO_THROW(gauge->Record(10.10, opentelemetry::context::Context{}));
EXPECT_NO_THROW(gauge->Record(-10.10, opentelemetry::context::Context{})); // This is ignored.
EXPECT_NO_THROW(gauge->Record(std::numeric_limits<double>::quiet_NaN(),
opentelemetry::context::Context{})); // This is ignored too
EXPECT_NO_THROW(gauge->Record(std::numeric_limits<double>::infinity(),
opentelemetry::context::Context{})); // This is ignored too
EXPECT_NO_THROW(gauge->Record(
10.10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}),
opentelemetry::context::Context{}));
EXPECT_NO_THROW(gauge->Record(10.10, opentelemetry::common::KeyValueIterableView<M>({}),
opentelemetry::context::Context{}));
}

TEST(SyncInstruments, LongGauge)
{
InstrumentDescriptor instrument_descriptor = {"double_gauge", "description", "1",
InstrumentType::kGauge, InstrumentValueType::kLong};
std::unique_ptr<SyncWritableMetricStorage> metric_storage(new SyncMultiMetricStorage());
DoubleGauge gauge(instrument_descriptor, std::move(metric_storage));
gauge.Record(10, opentelemetry::context::Context{});
gauge.Record(std::numeric_limits<uint64_t>::quiet_NaN(),
opentelemetry::context::Context{}); // This is ignored too
gauge.Record(std::numeric_limits<uint64_t>::infinity(),
opentelemetry::context::Context{}); // This is ignored too

gauge.Record(10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}),
opentelemetry::context::Context{});
gauge.Record(10, opentelemetry::common::KeyValueIterableView<M>({}),
opentelemetry::context::Context{});
auto gauge = std::unique_ptr<opentelemetry::metrics::Gauge<uint64_t>>(
new LongGauge(instrument_descriptor, std::move(metric_storage)));
EXPECT_NO_THROW(gauge->Record(10, opentelemetry::context::Context{}));
EXPECT_NO_THROW(gauge->Record(std::numeric_limits<uint64_t>::quiet_NaN(),
opentelemetry::context::Context{})); // This is ignored too
EXPECT_NO_THROW(gauge->Record(std::numeric_limits<uint64_t>::infinity(),
opentelemetry::context::Context{})); // This is ignored too

EXPECT_NO_THROW(gauge->Record(
10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}),
opentelemetry::context::Context{}));
EXPECT_NO_THROW(gauge->Record(10, opentelemetry::common::KeyValueIterableView<M>({}),
opentelemetry::context::Context{}));
}
#endif

0 comments on commit e0bdccc

Please sign in to comment.