@@ -29,6 +29,7 @@ import (
29
29
"go.uber.org/zap"
30
30
"go.uber.org/zap/zapcore"
31
31
"go.uber.org/zap/zaptest/observer"
32
+ "google.golang.org/protobuf/types/known/timestamppb"
32
33
)
33
34
34
35
func TestAddToGroupedMetric (t * testing.T ) {
@@ -211,6 +212,74 @@ func TestAddToGroupedMetric(t *testing.T) {
211
212
}
212
213
})
213
214
215
+ t .Run ("Add multiple metrics w/ different timestamps" , func (t * testing.T ) {
216
+ groupedMetrics := make (map [string ]* GroupedMetric )
217
+ oc := consumerdata.MetricsData {
218
+ Node : & commonpb.Node {},
219
+ Resource : & resourcepb.Resource {
220
+ Labels : map [string ]string {
221
+ conventions .AttributeServiceName : "myServiceName" ,
222
+ conventions .AttributeServiceNamespace : "myServiceNS" ,
223
+ },
224
+ },
225
+ Metrics : []* metricspb.Metric {
226
+ generateTestIntGauge ("int-gauge" ),
227
+ generateTestDoubleGauge ("double-gauge" ),
228
+ generateTestIntSum ("int-sum" ),
229
+ generateTestSummary ("summary" ),
230
+ },
231
+ }
232
+
233
+ timestamp1 := & timestamppb.Timestamp {
234
+ Seconds : int64 (1608068109 ),
235
+ Nanos : 347942000 ,
236
+ }
237
+ timestamp2 := & timestamppb.Timestamp {
238
+ Seconds : int64 (1608068110 ),
239
+ Nanos : 347942000 ,
240
+ }
241
+
242
+ // Give int gauge and int-sum the same timestamp
243
+ oc .Metrics [0 ].Timeseries [0 ].Points [0 ].Timestamp = timestamp1
244
+ oc .Metrics [2 ].Timeseries [0 ].Points [0 ].Timestamp = timestamp1
245
+ // Give summary a different timestamp
246
+ oc .Metrics [3 ].Timeseries [0 ].Points [0 ].Timestamp = timestamp2
247
+
248
+ rm := internaldata .OCToMetrics (oc )
249
+ rms := rm .ResourceMetrics ()
250
+ ilms := rms .At (0 ).InstrumentationLibraryMetrics ()
251
+ metrics := ilms .At (0 ).Metrics ()
252
+ assert .Equal (t , 4 , metrics .Len ())
253
+
254
+ for i := 0 ; i < metrics .Len (); i ++ {
255
+ metric := metrics .At (i )
256
+ addToGroupedMetric (& metric , groupedMetrics , metadata , logger )
257
+ }
258
+
259
+ assert .Equal (t , 3 , len (groupedMetrics ))
260
+ for _ , group := range groupedMetrics {
261
+ for metricName := range group .Metrics {
262
+ if metricName == "int-gauge" || metricName == "int-sum" {
263
+ assert .Equal (t , 2 , len (group .Metrics ))
264
+ assert .Equal (t , int64 (1608068109347 ), group .Metadata .Timestamp )
265
+ } else if metricName == "summary" {
266
+ assert .Equal (t , 1 , len (group .Metrics ))
267
+ assert .Equal (t , int64 (1608068110347 ), group .Metadata .Timestamp )
268
+ } else {
269
+ // double-gauge should use the default timestamp
270
+ assert .Equal (t , 1 , len (group .Metrics ))
271
+ assert .Equal (t , "double-gauge" , metricName )
272
+ assert .Equal (t , timestamp , group .Metadata .Timestamp )
273
+ }
274
+ }
275
+ expectedLabels := map [string ]string {
276
+ (OTellibDimensionKey ): "cloudwatch-otel" ,
277
+ "label1" : "value1" ,
278
+ }
279
+ assert .Equal (t , expectedLabels , group .Labels )
280
+ }
281
+ })
282
+
214
283
t .Run ("Add same metric but different log group" , func (t * testing.T ) {
215
284
groupedMetrics := make (map [string ]* GroupedMetric )
216
285
oc := consumerdata.MetricsData {
0 commit comments