diff --git a/.chloggen/hec-event-size-fix.yaml b/.chloggen/hec-event-size-fix.yaml new file mode 100644 index 000000000000..507ceecc6427 --- /dev/null +++ b/.chloggen/hec-event-size-fix.yaml @@ -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: diff --git a/exporter/splunkhecexporter/buffer.go b/exporter/splunkhecexporter/buffer.go index 7a1c059f4db1..1744d9e87994 100644 --- a/exporter/splunkhecexporter/buffer.go +++ b/exporter/splunkhecexporter/buffer.go @@ -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) { return false, nil } _, err := b.writer.Write(data) diff --git a/exporter/splunkhecexporter/client_test.go b/exporter/splunkhecexporter/client_test.go index b538b58aaf46..38172901e540 100644 --- a/exporter/splunkhecexporter/client_test.go +++ b/exporter/splunkhecexporter/client_test.go @@ -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 }(), @@ -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),