Skip to content

Commit

Permalink
sdk/log: Refine BenchmarkProcessor (open-telemetry#5607)
Browse files Browse the repository at this point in the history
Add a benchmark that shows that a processor that adds an attribute may
not introduce a heap allocation (as long as the log record still has <=
5 attributes).
  • Loading branch information
pellared authored Jul 11, 2024
1 parent 55f9b5c commit d6aa213
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions sdk/log/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,39 @@ func BenchmarkProcessor(b *testing.B) {
},
},
{
name: "ModifyTimestampSimple",
name: "SetTimestampSimple",
f: func() Processor {
return timestampDecorator{NewSimpleProcessor(noopExporter{})}
},
},
{
name: "ModifyTimestampBatch",
name: "SetTimestampBatch",
f: func() Processor {
return timestampDecorator{NewBatchProcessor(noopExporter{})}
},
},
{
name: "ModifyAttributesSimple",
name: "AddAttributesSimple",
f: func() Processor {
return attrDecorator{NewSimpleProcessor(noopExporter{})}
return attrAddDecorator{NewSimpleProcessor(noopExporter{})}
},
},
{
name: "ModifyAttributesBatch",
name: "AddAttributesBatch",
f: func() Processor {
return attrDecorator{NewBatchProcessor(noopExporter{})}
return attrAddDecorator{NewBatchProcessor(noopExporter{})}
},
},
{
name: "SetAttributesSimple",
f: func() Processor {
return attrSetDecorator{NewSimpleProcessor(noopExporter{})}
},
},
{
name: "SetAttributesBatch",
f: func() Processor {
return attrSetDecorator{NewBatchProcessor(noopExporter{})}
},
},
} {
Expand Down Expand Up @@ -89,11 +101,21 @@ func (e timestampDecorator) OnEmit(ctx context.Context, r Record) error {
return e.Processor.OnEmit(ctx, r)
}

type attrDecorator struct {
type attrAddDecorator struct {
Processor
}

func (e attrAddDecorator) OnEmit(ctx context.Context, r Record) error {
r = r.Clone()
r.AddAttributes(log.String("add", "me"))
return e.Processor.OnEmit(ctx, r)
}

type attrSetDecorator struct {
Processor
}

func (e attrDecorator) OnEmit(ctx context.Context, r Record) error {
func (e attrSetDecorator) OnEmit(ctx context.Context, r Record) error {
r = r.Clone()
r.SetAttributes(log.String("replace", "me"))
return e.Processor.OnEmit(ctx, r)
Expand Down

0 comments on commit d6aa213

Please sign in to comment.