Skip to content

Commit

Permalink
Update minsev processor impl
Browse files Browse the repository at this point in the history
Implement the new definition of a LogProcessor.
  • Loading branch information
MrAlias committed Aug 7, 2024
1 parent 52e3d20 commit 4d1a69c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions processors/minsev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.21

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.4.0
go.opentelemetry.io/otel/sdk/log v0.4.0
go.opentelemetry.io/otel/log v0.4.1-0.20240807055449-d0a45b887546
go.opentelemetry.io/otel/sdk/log v0.4.1-0.20240807055449-d0a45b887546
)

require (
Expand All @@ -14,10 +14,10 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/otel v1.28.1-0.20240807055449-d0a45b887546 // indirect
go.opentelemetry.io/otel/metric v1.28.1-0.20240807055449-d0a45b887546 // indirect
go.opentelemetry.io/otel/sdk v1.28.1-0.20240807055449-d0a45b887546 // indirect
go.opentelemetry.io/otel/trace v1.28.1-0.20240807055449-d0a45b887546 // indirect
golang.org/x/sys v0.23.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 12 additions & 12 deletions processors/minsev/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/log v0.4.0 h1:/vZ+3Utqh18e8TPjuc3ecg284078KWrR8BRz+PQAj3o=
go.opentelemetry.io/otel/log v0.4.0/go.mod h1:DhGnQvky7pHy82MIRV43iXh3FlKN8UUKftn0KbLOq6I=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
go.opentelemetry.io/otel/sdk/log v0.4.0 h1:1mMI22L82zLqf6KtkjrRy5BbagOTWdJsqMY/HSqILAA=
go.opentelemetry.io/otel/sdk/log v0.4.0/go.mod h1:AYJ9FVF0hNOgAVzUG/ybg/QttnXhUePWAupmCqtdESo=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.opentelemetry.io/otel v1.28.1-0.20240807055449-d0a45b887546 h1:+2PkfVXGd6+uIqrsad7WJrxH/hyPcSXaJU+NBjeF2i0=
go.opentelemetry.io/otel v1.28.1-0.20240807055449-d0a45b887546/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/log v0.4.1-0.20240807055449-d0a45b887546 h1:PQA8upi2HRtSy3TIZkboP1jDoQghI0iDNZ36fbubxjk=
go.opentelemetry.io/otel/log v0.4.1-0.20240807055449-d0a45b887546/go.mod h1:DhGnQvky7pHy82MIRV43iXh3FlKN8UUKftn0KbLOq6I=
go.opentelemetry.io/otel/metric v1.28.1-0.20240807055449-d0a45b887546 h1:5Z+VcSAvUx6T5RS6VXxQTySbyuRHQ8FophCtFQlDD5U=
go.opentelemetry.io/otel/metric v1.28.1-0.20240807055449-d0a45b887546/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/sdk v1.28.1-0.20240807055449-d0a45b887546 h1:SX1P1762JFSZAEuuVdMg8LcWRz2xZwg1CuL9D0m/0jA=
go.opentelemetry.io/otel/sdk v1.28.1-0.20240807055449-d0a45b887546/go.mod h1:2rWjAcMkswukLVtzgzFcx4Ixw5JEmGaaYmMLGy6mBio=
go.opentelemetry.io/otel/sdk/log v0.4.1-0.20240807055449-d0a45b887546 h1:UpKIPgZFaN19n7PlfWKAuPrPBPVlJfbfBDNYE9RWcQk=
go.opentelemetry.io/otel/sdk/log v0.4.1-0.20240807055449-d0a45b887546/go.mod h1:+Vq8S7zgof3KWrjJaY9gekXdEhhPyHcI2vKpJ42vXXM=
go.opentelemetry.io/otel/trace v1.28.1-0.20240807055449-d0a45b887546 h1:89zRePDon3uT4t9MnJSJxfgL6AL2wQkgnWjhua993go=
go.opentelemetry.io/otel/trace v1.28.1-0.20240807055449-d0a45b887546/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
10 changes: 5 additions & 5 deletions processors/minsev/minsev.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ log.Processor = (*LogProcessor)(nil)
// OnEmit passes ctx and r to the [log.Processor] that p wraps if the severity
// of record is greater than or equal to p.Minimum. Otherwise, record is
// dropped.
func (p *LogProcessor) OnEmit(ctx context.Context, record log.Record) error {
func (p *LogProcessor) OnEmit(ctx context.Context, record *log.Record) error {
if record.Severity() >= p.Minimum {
return p.Processor.OnEmit(ctx, record)
}
Expand All @@ -62,7 +62,7 @@ var defaultProcessor = noopProcessor{}

type noopProcessor struct{}

func (p noopProcessor) OnEmit(context.Context, log.Record) error { return nil }
func (p noopProcessor) Enabled(context.Context, log.Record) bool { return false }
func (p noopProcessor) Shutdown(context.Context) error { return nil }
func (p noopProcessor) ForceFlush(context.Context) error { return nil }
func (p noopProcessor) OnEmit(context.Context, *log.Record) error { return nil }
func (p noopProcessor) Enabled(context.Context, log.Record) bool { return false }
func (p noopProcessor) Shutdown(context.Context) error { return nil }
func (p noopProcessor) ForceFlush(context.Context) error { return nil }
26 changes: 13 additions & 13 deletions processors/minsev/minsev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var severities = []api.Severity{

type args struct {
Ctx context.Context
Record log.Record
Record *log.Record
}

type processor struct {
Expand All @@ -36,13 +36,13 @@ type processor struct {
ShutdownCalls []context.Context
}

func (p *processor) OnEmit(ctx context.Context, r log.Record) error {
func (p *processor) OnEmit(ctx context.Context, r *log.Record) error {
p.OnEmitCalls = append(p.OnEmitCalls, args{ctx, r})
return p.ReturnErr
}

func (p *processor) Enabled(ctx context.Context, r log.Record) bool {
p.EnabledCalls = append(p.EnabledCalls, args{ctx, r})
p.EnabledCalls = append(p.EnabledCalls, args{ctx, &r})
return true
}

Expand Down Expand Up @@ -72,11 +72,11 @@ func TestLogProcessorOnEmit(t *testing.T) {
r := &log.Record{}
for _, sev := range severities {
r.SetSeverity(sev)
assert.ErrorIs(t, p.OnEmit(ctx, *r), assert.AnError, sev.String())
assert.ErrorIs(t, p.OnEmit(ctx, r), assert.AnError, sev.String())

if assert.Lenf(t, wrapped.OnEmitCalls, 1, "Record with severity %s not passed-through", sev) {
assert.Equal(t, ctx, wrapped.OnEmitCalls[0].Ctx, sev.String())
assert.Equal(t, *r, wrapped.OnEmitCalls[0].Record, sev.String())
assert.Equal(t, r, wrapped.OnEmitCalls[0].Record, sev.String())
}
wrapped.Reset()
}
Expand All @@ -90,7 +90,7 @@ func TestLogProcessorOnEmit(t *testing.T) {
r := &log.Record{}
for _, sev := range severities {
r.SetSeverity(sev)
assert.NoError(t, p.OnEmit(ctx, *r), assert.AnError, sev.String())
assert.NoError(t, p.OnEmit(ctx, r), assert.AnError, sev.String())

if !assert.Lenf(t, wrapped.OnEmitCalls, 0, "Record with severity %s passed-through", sev) {
wrapped.Reset()
Expand All @@ -112,7 +112,7 @@ func TestLogProcessorEnabled(t *testing.T) {

if assert.Lenf(t, wrapped.EnabledCalls, 1, "Record with severity %s not passed-through", sev) {
assert.Equal(t, ctx, wrapped.EnabledCalls[0].Ctx, sev.String())
assert.Equal(t, *r, wrapped.EnabledCalls[0].Record, sev.String())
assert.Equal(t, r, wrapped.EnabledCalls[0].Record, sev.String())
}
wrapped.Reset()
}
Expand Down Expand Up @@ -156,28 +156,28 @@ func TestLogProcessorShutdownPassthrough(t *testing.T) {
func TestLogProcessorNilDownstream(t *testing.T) {
p := NewLogProcessor(nil, api.SeverityTrace1)
ctx := context.Background()
r := log.Record{}
r := new(log.Record)
r.SetSeverity(api.SeverityTrace1)
assert.NotPanics(t, func() {
assert.NoError(t, p.OnEmit(ctx, r))
assert.False(t, p.Enabled(ctx, r))
assert.False(t, p.Enabled(ctx, *r))
assert.NoError(t, p.ForceFlush(ctx))
assert.NoError(t, p.Shutdown(ctx))
})
}

func BenchmarkLogProcessor(b *testing.B) {
rPtr := new(log.Record)
rPtr.SetSeverity(api.SeverityTrace)
ctx, r := context.Background(), *rPtr
r := new(log.Record)
r.SetSeverity(api.SeverityTrace)
ctx := context.Background()

run := func(p log.Processor) func(b *testing.B) {
return func(b *testing.B) {
var err error
var enabled bool
b.ReportAllocs()
for n := 0; n < b.N; n++ {
enabled = p.Enabled(ctx, r)
enabled = p.Enabled(ctx, *r)
err = p.OnEmit(ctx, r)
}

Expand Down

0 comments on commit 4d1a69c

Please sign in to comment.