@@ -17,6 +17,7 @@ package batchprocessor
1717import (
1818 "context"
1919 "fmt"
20+ "sync"
2021 "testing"
2122 "time"
2223
@@ -504,6 +505,41 @@ func BenchmarkTraceSizeSpanCount(b *testing.B) {
504505 }
505506}
506507
508+ func BenchmarkBatchMetricProcessor (b * testing.B ) {
509+ cfg := Config {
510+ ProcessorSettings : config .NewProcessorSettings (config .NewID (typeStr )),
511+ Timeout : 100 * time .Millisecond ,
512+ SendBatchSize : 2000 ,
513+ }
514+ ctx := context .Background ()
515+ sink := new (metricsSink )
516+ createParams := component.ProcessorCreateParams {Logger : zap .NewNop ()}
517+ metricsPerRequest := 1000
518+
519+ batcher , err := newBatchMetricsProcessor (createParams , sink , & cfg , configtelemetry .LevelDetailed )
520+ require .NoError (b , err )
521+ require .NoError (b , batcher .Start (ctx , componenttest .NewNopHost ()))
522+
523+ md := testdata .GenerateMetricsManyMetricsSameResource (metricsPerRequest )
524+ for n := 0 ; n < b .N ; n ++ {
525+ batcher .ConsumeMetrics (ctx , md .Clone ())
526+ }
527+ require .NoError (b , batcher .Shutdown (ctx ))
528+ require .Equal (b , b .N * metricsPerRequest , sink .metricsCount )
529+ }
530+
531+ type metricsSink struct {
532+ mu sync.Mutex
533+ metricsCount int
534+ }
535+
536+ func (sme * metricsSink ) ConsumeMetrics (_ context.Context , md pdata.Metrics ) error {
537+ sme .mu .Lock ()
538+ defer sme .mu .Unlock ()
539+ sme .metricsCount += md .MetricCount ()
540+ return nil
541+ }
542+
507543func TestBatchLogProcessor_ReceivingData (t * testing.T ) {
508544 // Instantiate the batch processor with low config values to test data
509545 // gets sent through the processor.
0 commit comments