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

[chore][exporter/splunkhec] add test to reproduce buffer capacity issue on splunk HEC buffer sender #20512

Merged
merged 2 commits into from
Mar 29, 2023
Merged
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
16 changes: 16 additions & 0 deletions .chloggen/over-capacity-issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: Make sure to not return an error if we are over capacity, just return that we cannot accept the event.

# One or more tracking issues related to the change
issues: [20481]

# (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:
4 changes: 4 additions & 0 deletions exporter/splunkhecexporter/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func (b *bufferState) accept(data []byte) (bool, error) {
// if the byte writer was over capacity, try to write the new entry in the zip writer:
if overCapacity {
if _, err2 := zipWriter.Write(data); err2 != nil {
overCapacity2 := errors.Is(err2, errOverCapacity)
if overCapacity2 {
return false, nil
}
return false, err2
}

Expand Down
35 changes: 34 additions & 1 deletion exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ func repeat(what int, times int) []int {
return result
}

// these runes are used to generate long log messages that will compress down to a number of bytes we can rely on for testing.
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789wersgdgr43q3zvbcgv65ew 346xx$gt5/kuopo89.nytqasdfghjklpoiuy")

func repeatableString(length int) string {
b := make([]rune, length)
for i := range b {
l := i % len(letterRunes)
b[i] = letterRunes[l]
}
return string(b)
}

func createLogDataWithCustomLibraries(numResources int, libraries []string, numRecords []int) plog.Logs {
logs := plog.NewLogs()
logs.ResourceLogs().EnsureCapacity(numResources)
Expand Down Expand Up @@ -641,14 +653,35 @@ func TestReceiveLogs(t *testing.T) {
compressed: true,
},
},
{
name: "one event with 1340 bytes, then one triggering compression (going over 1500 bytes) and bypassing the max length, moving to a separate batch",
logs: func() plog.Logs {
firstLog := createLogData(1, 1, 2)
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().SetStr(repeatableString(1340))
firstLog.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(1).Body().SetStr(repeatableString(2800000))
return firstLog
}(),
conf: func() *Config {
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.MaxContentLengthLogs = 10000 // small so we can reproduce without allocating big logs.
return cfg
}(),
want: wantType{
batches: [][]string{
{`"otel.log.name":"0_0_0"`}, {`"otel.log.name":"0_0_1"`},
},
numBatches: 2,
compressed: true,
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := runLogExport(test.conf, test.logs, test.want.numBatches, t)

require.NoError(t, err)
require.Len(t, got, test.want.numBatches)
require.Equal(t, test.want.numBatches, len(got))

for i := 0; i < test.want.numBatches; i++ {
require.NotZero(t, got[i])
Expand Down