Skip to content

Commit d9ad76f

Browse files
authored
[SDK] Creating DoubleUpDownCounter with no matching view (#2379)
1 parent 0e6eae0 commit d9ad76f

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class DefaultAggregation
3535
case AggregationType::kSum:
3636
return (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
3737
? std::move(std::unique_ptr<Aggregation>(new LongSumAggregation(is_monotonic)))
38-
: std::move(std::unique_ptr<Aggregation>(new DoubleSumAggregation(true)));
38+
: std::move(
39+
std::unique_ptr<Aggregation>(new DoubleSumAggregation(is_monotonic)));
3940
break;
4041
case AggregationType::kHistogram: {
4142
if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)

sdk/test/metrics/sum_aggregation_test.cc

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ TEST(CounterToSum, Double)
121121
ASSERT_EQ(1000275.0, opentelemetry::nostd::get<double>(actual.value_));
122122
}
123123

124-
TEST(UpDownCounterToSum, Double)
124+
class UpDownCounterToSumFixture : public ::testing::TestWithParam<bool>
125+
{};
126+
127+
TEST_P(UpDownCounterToSumFixture, Double)
125128
{
129+
bool is_matching_view = GetParam();
126130
MeterProvider mp;
127131
auto m = mp.GetMeter("meter1", "version1", "schema1");
128132
std::string instrument_name = "updowncounter1";
@@ -133,13 +137,16 @@ TEST(UpDownCounterToSum, Double)
133137
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
134138
mp.AddMetricReader(reader);
135139

136-
std::unique_ptr<View> view{
137-
new View("view1", "view1_description", instrument_unit, AggregationType::kSum)};
138-
std::unique_ptr<InstrumentSelector> instrument_selector{
139-
new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)};
140-
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
141-
mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));
142-
140+
if (is_matching_view)
141+
{
142+
std::unique_ptr<View> view{
143+
new View("view1", "view1_description", instrument_unit, AggregationType::kSum)};
144+
std::unique_ptr<InstrumentSelector> instrument_selector{
145+
new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)};
146+
std::unique_ptr<MeterSelector> meter_selector{
147+
new MeterSelector("meter1", "version1", "schema1")};
148+
mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));
149+
}
143150
auto h = m->CreateDoubleUpDownCounter(instrument_name, instrument_desc, instrument_unit);
144151

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

0 commit comments

Comments
 (0)