Skip to content

Commit

Permalink
[SDK] Creating DoubleUpDownCounter with no matching view (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 19, 2023
1 parent 0e6eae0 commit d9ad76f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class DefaultAggregation
case AggregationType::kSum:
return (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
? std::move(std::unique_ptr<Aggregation>(new LongSumAggregation(is_monotonic)))
: std::move(std::unique_ptr<Aggregation>(new DoubleSumAggregation(true)));
: std::move(
std::unique_ptr<Aggregation>(new DoubleSumAggregation(is_monotonic)));
break;
case AggregationType::kHistogram: {
if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
Expand Down
26 changes: 18 additions & 8 deletions sdk/test/metrics/sum_aggregation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ TEST(CounterToSum, Double)
ASSERT_EQ(1000275.0, opentelemetry::nostd::get<double>(actual.value_));
}

TEST(UpDownCounterToSum, Double)
class UpDownCounterToSumFixture : public ::testing::TestWithParam<bool>
{};

TEST_P(UpDownCounterToSumFixture, Double)
{
bool is_matching_view = GetParam();
MeterProvider mp;
auto m = mp.GetMeter("meter1", "version1", "schema1");
std::string instrument_name = "updowncounter1";
Expand All @@ -133,13 +137,16 @@ TEST(UpDownCounterToSum, Double)
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
mp.AddMetricReader(reader);

std::unique_ptr<View> view{
new View("view1", "view1_description", instrument_unit, AggregationType::kSum)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));

if (is_matching_view)
{
std::unique_ptr<View> view{
new View("view1", "view1_description", instrument_unit, AggregationType::kSum)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{
new MeterSelector("meter1", "version1", "schema1")};
mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));
}
auto h = m->CreateDoubleUpDownCounter(instrument_name, instrument_desc, instrument_unit);

h->Add(5, {});
Expand Down Expand Up @@ -168,4 +175,7 @@ TEST(UpDownCounterToSum, Double)
const auto &actual = actuals.at(0);
ASSERT_EQ(15.0, opentelemetry::nostd::get<double>(actual.value_));
}
INSTANTIATE_TEST_SUITE_P(UpDownCounterToSum,
UpDownCounterToSumFixture,
::testing::Values(true, false));
#endif

0 comments on commit d9ad76f

Please sign in to comment.