@@ -3,6 +3,7 @@ package log
3
3
import (
4
4
"sort"
5
5
"testing"
6
+ "time"
6
7
7
8
"github.com/prometheus/prometheus/model/labels"
8
9
"github.com/stretchr/testify/assert"
@@ -463,3 +464,41 @@ func assertLabelResult(t *testing.T, lbs labels.Labels, res LabelsResult) {
463
464
res .String (),
464
465
)
465
466
}
467
+
468
+ // benchmark streamLineSampleExtractor.Process method
469
+ func BenchmarkStreamLineSampleExtractor_Process (b * testing.B ) {
470
+ // Setup some test data
471
+ baseLabels := labels .FromStrings (
472
+ "namespace" , "prod" ,
473
+ "cluster" , "us-east-1" ,
474
+ "pod" , "my-pod-123" ,
475
+ "container" , "main" ,
476
+ "stream" , "stdout" ,
477
+ )
478
+
479
+ structuredMeta := []labels.Label {
480
+ {Name : "level" , Value : "info" },
481
+ {Name : "caller" , Value : "http.go:42" },
482
+ {Name : "user" , Value : "john" },
483
+ {Name : "trace_id" , Value : "abc123" },
484
+ }
485
+
486
+ testLine := []byte (`{"timestamp":"2024-01-01T00:00:00Z","level":"info","message":"test message","duration_ms":150}` )
487
+
488
+ // JSON parsing + filtering + label extraction
489
+ matcher := labels .MustNewMatcher (labels .MatchEqual , "level" , "info" )
490
+ filter := NewStringLabelFilter (matcher )
491
+ stages := []Stage {
492
+ NewJSONParser (),
493
+ filter ,
494
+ }
495
+ ex , err := NewLineSampleExtractor (CountExtractor , stages , []string {}, false , false )
496
+ require .NoError (b , err )
497
+ streamEx := ex .ForStream (baseLabels )
498
+ b .ReportAllocs ()
499
+ b .ResetTimer ()
500
+
501
+ for i := 0 ; i < b .N ; i ++ {
502
+ _ , _ , _ = streamEx .Process (time .Now ().UnixNano (), testLine , structuredMeta ... )
503
+ }
504
+ }
0 commit comments