-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[exporter][batching] Serialized bytes based batching for logs #12299
base: main
Are you sure you want to change the base?
Changes from all commits
57d9eed
506ae35
3faa114
a5516f8
d2f21a6
4752210
906aa16
9ebf82f
c804356
6c1f0ad
5bea43a
697ed11
60f71c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
// Copyright The OpenTelemetry Authors | ||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||
|
||||||
package sizer // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal/sizer" | ||||||
|
||||||
import ( | ||||||
math_bits "math/bits" | ||||||
|
||||||
"go.opentelemetry.io/collector/pdata/plog" | ||||||
) | ||||||
|
||||||
type LogsSizer interface { | ||||||
LogsSize(ld plog.Logs) int | ||||||
ResourceLogsSize(rl plog.ResourceLogs) int | ||||||
ScopeLogsSize(sl plog.ScopeLogs) int | ||||||
LogRecordSize(lr plog.LogRecord) int | ||||||
|
||||||
// DeltaCapacity() returns the delta size when a ResourceLog, ScopeLog or LogRecord is added. | ||||||
DeltaSize(newItemSize int) int | ||||||
} | ||||||
|
||||||
// LogsByteSizer returns the byte size of serialized protos. | ||||||
type LogsBytesSizer struct { | ||||||
plog.ProtoMarshaler | ||||||
} | ||||||
|
||||||
// DeltaCapacity() returns the delta size of a proto slice when a new item is added. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Example: | ||||||
// | ||||||
// prevSize := proto1.Size() | ||||||
// proto1.RepeatedField().AppendEmpty() = proto2 | ||||||
// | ||||||
// Then currSize of proto1 can be calculated as | ||||||
// | ||||||
// currSize := (prevSize + deltaCapacity(proto2.Size())) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// | ||||||
// This is derived from gogo/protobuf 's Size() function | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a link to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and you might add that the constant |
||||||
func (s *LogsBytesSizer) DeltaSize(newItemSize int) int { | ||||||
return 1 + newItemSize + math_bits.Len64(uint64(newItemSize|1)+6)/7 //nolint:gosec // disable G115 | ||||||
} | ||||||
|
||||||
// LogsCountSizer returns the nunmber of logs entries. | ||||||
type LogsCountSizer struct{} | ||||||
|
||||||
func (s *LogsCountSizer) LogsSize(ld plog.Logs) int { | ||||||
return ld.LogRecordCount() | ||||||
} | ||||||
|
||||||
func (s *LogsCountSizer) ResourceLogsSize(rl plog.ResourceLogs) int { | ||||||
count := 0 | ||||||
for k := 0; k < rl.ScopeLogs().Len(); k++ { | ||||||
count += rl.ScopeLogs().At(k).LogRecords().Len() | ||||||
} | ||||||
return count | ||||||
} | ||||||
|
||||||
func (s *LogsCountSizer) ScopeLogsSize(sl plog.ScopeLogs) int { | ||||||
return sl.LogRecords().Len() | ||||||
} | ||||||
|
||||||
func (s *LogsCountSizer) LogRecordSize(_ plog.LogRecord) int { | ||||||
return 1 | ||||||
} | ||||||
|
||||||
func (s *LogsCountSizer) DeltaSize(newItemSize int) int { | ||||||
return newItemSize | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package sizer // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal/sizer" | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"go.opentelemetry.io/collector/pdata/testdata" | ||
) | ||
|
||
func TestLogsCountSizer(t *testing.T) { | ||
ld := testdata.GenerateLogs(5) | ||
sizer := LogsCountSizer{} | ||
require.Equal(t, 5, sizer.LogsSize(ld)) | ||
|
||
rl := ld.ResourceLogs().At(0) | ||
require.Equal(t, 5, sizer.ResourceLogsSize(rl)) | ||
|
||
sl := rl.ScopeLogs().At(0) | ||
require.Equal(t, 5, sizer.ScopeLogsSize(sl)) | ||
|
||
require.Equal(t, 1, sizer.LogRecordSize(sl.LogRecords().At(0))) | ||
require.Equal(t, 1, sizer.LogRecordSize(sl.LogRecords().At(1))) | ||
require.Equal(t, 1, sizer.LogRecordSize(sl.LogRecords().At(2))) | ||
require.Equal(t, 1, sizer.LogRecordSize(sl.LogRecords().At(3))) | ||
require.Equal(t, 1, sizer.LogRecordSize(sl.LogRecords().At(4))) | ||
|
||
prevSize := sizer.ScopeLogsSize(sl) | ||
lr := sl.LogRecords().At(2) | ||
lr.CopyTo(sl.LogRecords().AppendEmpty()) | ||
require.Equal(t, sizer.ScopeLogsSize(sl), prevSize+sizer.DeltaSize(sizer.LogRecordSize(lr))) | ||
} | ||
|
||
func TestLogsBytesSizer(t *testing.T) { | ||
ld := testdata.GenerateLogs(5) | ||
sizer := LogsBytesSizer{} | ||
require.Equal(t, 545, sizer.LogsSize(ld)) | ||
|
||
rl := ld.ResourceLogs().At(0) | ||
require.Equal(t, 542, sizer.ResourceLogsSize(rl)) | ||
|
||
sl := rl.ScopeLogs().At(0) | ||
require.Equal(t, 497, sizer.ScopeLogsSize(sl)) | ||
|
||
require.Equal(t, 109, sizer.LogRecordSize(sl.LogRecords().At(0))) | ||
require.Equal(t, 79, sizer.LogRecordSize(sl.LogRecords().At(1))) | ||
require.Equal(t, 109, sizer.LogRecordSize(sl.LogRecords().At(2))) | ||
require.Equal(t, 79, sizer.LogRecordSize(sl.LogRecords().At(3))) | ||
require.Equal(t, 109, sizer.LogRecordSize(sl.LogRecords().At(4))) | ||
|
||
prevSize := sizer.ScopeLogsSize(sl) | ||
lr := sl.LogRecords().At(2) | ||
lr.CopyTo(sl.LogRecords().AppendEmpty()) | ||
require.Equal(t, sizer.ScopeLogsSize(sl), prevSize+sizer.DeltaSize(sizer.LogRecordSize(lr))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.