From 2f3382a2f7e63695a6fa14cdb0e4d13cfb488b06 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 23 Aug 2024 13:53:33 -0700 Subject: [PATCH] Fix minsev --- processors/minsev/minsev.go | 18 ++++++++++++++++-- processors/minsev/minsev_test.go | 7 ++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/processors/minsev/minsev.go b/processors/minsev/minsev.go index aeb135d8946..a1997ecf4b2 100644 --- a/processors/minsev/minsev.go +++ b/processors/minsev/minsev.go @@ -21,7 +21,17 @@ func NewLogProcessor(downstream log.Processor, minimum api.Severity) *LogProcess if downstream == nil { downstream = defaultProcessor } - return &LogProcessor{Processor: downstream, Minimum: minimum} + p := &LogProcessor{Processor: downstream, Minimum: minimum} + if fp, ok := downstream.(filterProcessor); ok { + p.filter = fp + } + return p +} + +// filterProcessor is the experimental optional interface a Processor can +// implement (go.opentelemetry.io/otel/sdk/log/internal/x). +type filterProcessor interface { + Enabled(ctx context.Context, record log.Record) bool } // LogProcessor is an [log.Processor] implementation that wraps another @@ -35,6 +45,7 @@ func NewLogProcessor(downstream log.Processor, minimum api.Severity) *LogProcess type LogProcessor struct { log.Processor + filter filterProcessor Minimum api.Severity } @@ -55,7 +66,10 @@ func (p *LogProcessor) OnEmit(ctx context.Context, record *log.Record) error { // severity of record is greater than or equal to p.Minimum. Otherwise false is // returned. func (p *LogProcessor) Enabled(ctx context.Context, record log.Record) bool { - return record.Severity() >= p.Minimum && p.Processor.Enabled(ctx, record) + if p.filter != nil { + return record.Severity() >= p.Minimum && p.filter.Enabled(ctx, record) + } + return record.Severity() >= p.Minimum } var defaultProcessor = noopProcessor{} diff --git a/processors/minsev/minsev_test.go b/processors/minsev/minsev_test.go index a19ad475fc2..564454260cc 100644 --- a/processors/minsev/minsev_test.go +++ b/processors/minsev/minsev_test.go @@ -171,7 +171,12 @@ func BenchmarkLogProcessor(b *testing.B) { r.SetSeverity(api.SeverityTrace) ctx := context.Background() - run := func(p log.Processor) func(b *testing.B) { + type combo interface { + log.Processor + filterProcessor + } + + run := func(p combo) func(b *testing.B) { return func(b *testing.B) { var err error var enabled bool