Skip to content
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/splunkhec] fix event size check #22834

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/hec-event-size-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: splunkhecexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix the event size check associated with the `max_event_size` setting.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [18066]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (b *bufferState) Close() error {

// accept returns true if data is accepted by the buffer
func (b *bufferState) accept(data []byte) (bool, error) {
if len(data)+b.rawLength > int(b.maxEventLength) {
if len(data) > int(b.maxEventLength) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause an unnecessary batch flush every time this is encountered. This check should not be inside the accept. Let's hold off on this for now. I'd like to simplify the compression logic first, which is dependent on this in some way.

return false, nil
}
_, err := b.writer.Write(data)
Expand Down
37 changes: 6 additions & 31 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,17 +728,18 @@ func TestReceiveLogs(t *testing.T) {
},
},
{
name: "two events with 2000 bytes, one with 2000 bytes, then one with 20000 bytes",
name: "dropping one event longer than max event size",
logs: func() plog.Logs {
firstLog := createLogData(1, 1, 3)
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().SetStr(repeatableString(2000))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(1).Body().SetStr(repeatableString(2000))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(2).Body().SetStr(repeatableString(20000))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().SetStr(repeatableString(100))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(1).Body().SetStr(repeatableString(100))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(2).Body().SetStr(repeatableString(500))
return firstLog
}(),
conf: func() *Config {
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.MaxEventSize = 20000 // small so we can reproduce without allocating big logs.
cfg.MaxEventSize = 300
cfg.MaxContentLengthLogs = 50000
cfg.DisableCompression = true
return cfg
}(),
Expand All @@ -750,32 +751,6 @@ func TestReceiveLogs(t *testing.T) {
wantDrops: 1,
},
},
{
name: "two events with 2000 bytes, one with 1000 bytes, then one with 4200 bytes",
logs: func() plog.Logs {
firstLog := createLogData(1, 1, 5)
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().SetStr(repeatableString(2000))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(1).Body().SetStr(repeatableString(2000))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(2).Body().SetStr(repeatableString(1000))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(3).Body().SetStr(repeatableString(4200))
return firstLog
}(),
conf: func() *Config {
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.MaxEventSize = 10000 // small so we can reproduce without allocating big logs.
cfg.MaxContentLengthLogs = 5000
cfg.DisableCompression = true
return cfg
}(),
want: wantType{
batches: [][]string{
{`"otel.log.name":"0_0_0"`, `"otel.log.name":"0_0_1"`},
{`"otel.log.name":"0_0_2"`},
{`"otel.log.name":"0_0_3"`, `"otel.log.name":"0_0_4"`},
},
numBatches: 3,
},
},
{
name: "10 resource logs, 1 scope logs, 10 log records, no compression",
logs: createLogData(10, 1, 10),
Expand Down