@@ -107,12 +107,12 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation)
107
107
opentelemetry::sdk::metrics::AsyncMetricStorage storage (
108
108
instr_desc, AggregationType::kSum , default_attributes_processor.get (),
109
109
std::shared_ptr<opentelemetry::sdk::metrics::AggregationConfig>{});
110
- long get_count = 20l ;
111
- long put_count = 10l ;
112
- size_t attribute_count = 2 ;
113
- std::unordered_map<MetricAttributes, long , AttributeHashGenerator> measurements = {
114
- {{{" RequestType" , " GET" }}, get_count }, {{{" RequestType" , " PUT" }}, put_count }};
115
- storage.RecordLong (measurements ,
110
+ long get_count1 = 20l ;
111
+ long put_count1 = 10l ;
112
+ size_t attribute_count = 2 ;
113
+ std::unordered_map<MetricAttributes, long , AttributeHashGenerator> measurements1 = {
114
+ {{{" RequestType" , " GET" }}, get_count1 }, {{{" RequestType" , " PUT" }}, put_count1 }};
115
+ storage.RecordLong (measurements1 ,
116
116
opentelemetry::common::SystemTimestamp (std::chrono::system_clock::now ()));
117
117
118
118
storage.Collect (collector.get (), collectors, sdk_start_ts, collection_ts,
@@ -123,20 +123,57 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation)
123
123
if (opentelemetry::nostd::get<std::string>(
124
124
data_attr.attributes .find (" RequestType" )->second ) == " GET" )
125
125
{
126
- EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), get_count );
126
+ EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), get_count1 );
127
127
}
128
128
else if (opentelemetry::nostd::get<std::string>(
129
129
data_attr.attributes .find (" RequestType" )->second ) == " PUT" )
130
130
{
131
- EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), put_count );
131
+ EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), put_count1 );
132
132
}
133
133
}
134
134
return true ;
135
135
});
136
136
// subsequent recording after collection shouldn't fail
137
- storage.RecordLong (measurements,
137
+ // monotonic increasing values;
138
+ long get_count2 = 50l ;
139
+ long put_count2 = 70l ;
140
+
141
+ std::unordered_map<MetricAttributes, long , AttributeHashGenerator> measurements2 = {
142
+ {{{" RequestType" , " GET" }}, get_count2}, {{{" RequestType" , " PUT" }}, put_count2}};
143
+ storage.RecordLong (measurements2,
138
144
opentelemetry::common::SystemTimestamp (std::chrono::system_clock::now ()));
139
- EXPECT_EQ (MeasurementFetcher::number_of_attributes, attribute_count);
145
+ storage.Collect (
146
+ collector.get (), collectors, sdk_start_ts, collection_ts, [&](const MetricData data) {
147
+ for (auto data_attr : data.point_data_attr_ )
148
+ {
149
+ auto data = opentelemetry::nostd::get<SumPointData>(data_attr.point_data );
150
+ if (opentelemetry::nostd::get<std::string>(
151
+ data_attr.attributes .find (" RequestType" )->second ) == " GET" )
152
+ {
153
+ if (temporality == AggregationTemporality::kCumulative )
154
+ {
155
+ EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), get_count2);
156
+ }
157
+ else
158
+ {
159
+ EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), get_count2 - get_count1);
160
+ }
161
+ }
162
+ else if (opentelemetry::nostd::get<std::string>(
163
+ data_attr.attributes .find (" RequestType" )->second ) == " PUT" )
164
+ {
165
+ if (temporality == AggregationTemporality::kCumulative )
166
+ {
167
+ EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), put_count2);
168
+ }
169
+ else
170
+ {
171
+ EXPECT_EQ (opentelemetry::nostd::get<long >(data.value_ ), put_count2 - put_count1);
172
+ }
173
+ }
174
+ }
175
+ return true ;
176
+ });
140
177
}
141
178
142
179
INSTANTIATE_TEST_SUITE_P (WritableMetricStorageTestLong,
0 commit comments