@@ -16,6 +16,8 @@ import (
16
16
"go.opentelemetry.io/collector/pdata/pmetric"
17
17
"go.opentelemetry.io/collector/processor/processorhelper"
18
18
"go.opentelemetry.io/collector/processor/processortest"
19
+ "go.opentelemetry.io/otel/attribute"
20
+ "go.opentelemetry.io/otel/sdk/metric/metricdata"
19
21
20
22
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/goldendataset"
21
23
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig"
@@ -366,74 +368,119 @@ func TestFilterMetricProcessor(t *testing.T) {
366
368
}
367
369
368
370
func TestFilterMetricProcessorTelemetry (t * testing.T ) {
369
- telemetryTest (t , "FilterMetricProcessorTelemetry" , func (t * testing.T , tel testTelemetry ) {
370
- next := new (consumertest.MetricsSink )
371
- cfg := & Config {
372
- Metrics : MetricFilters {
373
- MetricConditions : []string {
374
- "name==\" metric1\" " ,
375
- },
371
+ tel := setupTestTelemetry ()
372
+ next := new (consumertest.MetricsSink )
373
+ cfg := & Config {
374
+ Metrics : MetricFilters {
375
+ MetricConditions : []string {
376
+ "name==\" metric1\" " ,
376
377
},
377
- }
378
- factory := NewFactory ()
379
- fmp , err := factory .CreateMetricsProcessor (
380
- context .Background (),
381
- tel .NewProcessorCreateSettings (),
382
- cfg ,
383
- next ,
384
- )
385
- assert .NotNil (t , fmp )
386
- assert .NoError (t , err )
387
-
388
- caps := fmp .Capabilities ()
389
- assert .True (t , caps .MutatesData )
390
- ctx := context .Background ()
391
- assert .NoError (t , fmp .Start (ctx , nil ))
392
-
393
- err = fmp .ConsumeMetrics (context .Background (), testResourceMetrics ([]metricWithResource {
394
- {
395
- metricNames : []string {"foo" , "bar" },
396
- resourceAttributes : map [string ]any {
397
- "attr1" : "attr1/val1" ,
378
+ },
379
+ }
380
+ factory := NewFactory ()
381
+ fmp , err := factory .CreateMetricsProcessor (
382
+ context .Background (),
383
+ tel .NewSettings (),
384
+ cfg ,
385
+ next ,
386
+ )
387
+ assert .NotNil (t , fmp )
388
+ assert .NoError (t , err )
389
+
390
+ caps := fmp .Capabilities ()
391
+ assert .True (t , caps .MutatesData )
392
+ ctx := context .Background ()
393
+ assert .NoError (t , fmp .Start (ctx , nil ))
394
+
395
+ err = fmp .ConsumeMetrics (context .Background (), testResourceMetrics ([]metricWithResource {
396
+ {
397
+ metricNames : []string {"foo" , "bar" },
398
+ resourceAttributes : map [string ]any {
399
+ "attr1" : "attr1/val1" ,
400
+ },
401
+ },
402
+ }))
403
+ assert .NoError (t , err )
404
+
405
+ want := []metricdata.Metrics {
406
+ {
407
+ Name : "otelcol_processor_filter_datapoints.filtered" ,
408
+ Description : "Number of metric data points dropped by the filter processor" ,
409
+ Unit : "1" ,
410
+ Data : metricdata.Sum [int64 ]{
411
+ Temporality : metricdata .CumulativeTemporality ,
412
+ IsMonotonic : true ,
413
+ DataPoints : []metricdata.DataPoint [int64 ]{
414
+ {
415
+ Value : 0 ,
416
+ Attributes : attribute .NewSet (attribute .String ("filter" , "filter" )),
417
+ },
398
418
},
399
419
},
400
- }))
401
- assert . NoError ( t , err )
420
+ },
421
+ }
402
422
403
- tel .assertMetrics (t , expectedMetrics {
404
- metricDataPointsFiltered : 0 ,
405
- })
423
+ tel .assertMetrics (t , want )
424
+
425
+ err = fmp .ConsumeMetrics (context .Background (), testResourceMetrics ([]metricWithResource {
426
+ {
427
+ metricNames : []string {"metric1" , "metric2" },
428
+ resourceAttributes : map [string ]any {
429
+ "attr1" : "attr1/val1" ,
430
+ },
431
+ },
432
+ }))
433
+ assert .NoError (t , err )
406
434
407
- err = fmp .ConsumeMetrics (context .Background (), testResourceMetrics ([]metricWithResource {
408
- {
409
- metricNames : []string {"metric1" , "metric2" },
410
- resourceAttributes : map [string ]any {
411
- "attr1" : "attr1/val1" ,
435
+ want = []metricdata.Metrics {
436
+ {
437
+ Name : "otelcol_processor_filter_datapoints.filtered" ,
438
+ Description : "Number of metric data points dropped by the filter processor" ,
439
+ Unit : "1" ,
440
+ Data : metricdata.Sum [int64 ]{
441
+ Temporality : metricdata .CumulativeTemporality ,
442
+ IsMonotonic : true ,
443
+ DataPoints : []metricdata.DataPoint [int64 ]{
444
+ {
445
+ Value : 1 ,
446
+ Attributes : attribute .NewSet (attribute .String ("filter" , "filter" )),
447
+ },
412
448
},
413
449
},
414
- }))
415
- assert .NoError (t , err )
450
+ },
451
+ }
452
+ tel .assertMetrics (t , want )
416
453
417
- tel .assertMetrics (t , expectedMetrics {
418
- metricDataPointsFiltered : 1 ,
419
- })
454
+ err = fmp .ConsumeMetrics (context .Background (), testResourceMetrics ([]metricWithResource {
455
+ {
456
+ metricNames : []string {"metric1" },
457
+ resourceAttributes : map [string ]any {
458
+ "attr1" : "attr1/val1" ,
459
+ },
460
+ },
461
+ }))
462
+ assert .NoError (t , err )
420
463
421
- err = fmp .ConsumeMetrics (context .Background (), testResourceMetrics ([]metricWithResource {
422
- {
423
- metricNames : []string {"metric1" },
424
- resourceAttributes : map [string ]any {
425
- "attr1" : "attr1/val1" ,
464
+ want = []metricdata.Metrics {
465
+ {
466
+ Name : "otelcol_processor_filter_datapoints.filtered" ,
467
+ Description : "Number of metric data points dropped by the filter processor" ,
468
+ Unit : "1" ,
469
+ Data : metricdata.Sum [int64 ]{
470
+ Temporality : metricdata .CumulativeTemporality ,
471
+ IsMonotonic : true ,
472
+ DataPoints : []metricdata.DataPoint [int64 ]{
473
+ {
474
+ Value : 2 ,
475
+ Attributes : attribute .NewSet (attribute .String ("filter" , "filter" )),
476
+ },
426
477
},
427
478
},
428
- }))
429
- assert .NoError (t , err )
430
-
431
- tel .assertMetrics (t , expectedMetrics {
432
- metricDataPointsFiltered : 2 ,
433
- })
479
+ },
480
+ }
481
+ tel .assertMetrics (t , want )
434
482
435
- assert .NoError (t , fmp .Shutdown (ctx ))
436
- })
483
+ assert .NoError (t , fmp .Shutdown (ctx ))
437
484
}
438
485
439
486
func testResourceMetrics (mwrs []metricWithResource ) pmetric.Metrics {
0 commit comments