Skip to content
Open
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
27 changes: 27 additions & 0 deletions .chloggen/fix_stanza_transformer_container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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. receiver/filelog)
component: "pkg/stanza"

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix container parser operator logging errors at ERROR level when `on_error` is set to quiet mode"

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

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
48 changes: 40 additions & 8 deletions pkg/stanza/operator/parser/container/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func (p *Parser) Process(ctx context.Context, entry *entry.Entry) (err error) {
// Short circuit if the "if" condition does not match
skip, err := p.Skip(ctx, entry)
if err != nil {
return p.HandleEntryError(ctx, entry, err)
handleErr := p.HandleEntryError(ctx, entry, err)
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}
if skip {
return p.Write(ctx, entry)
Expand All @@ -89,7 +93,11 @@ func (p *Parser) Process(ctx context.Context, entry *entry.Entry) (err error) {
if format == "" {
format, err = p.detectFormat(entry)
if err != nil {
return p.HandleEntryError(ctx, entry, fmt.Errorf("failed to detect a valid container log format: %w", err))
handleErr := p.HandleEntryError(ctx, entry, fmt.Errorf("failed to detect a valid container log format: %w", err))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}
}

Expand All @@ -98,7 +106,11 @@ func (p *Parser) Process(ctx context.Context, entry *entry.Entry) (err error) {
p.timeLayout = goTimeLayout
err = p.ProcessWithCallback(ctx, entry, p.parseDocker, p.handleTimeAndAttributeMappings)
if err != nil {
return fmt.Errorf("failed to process the docker log: %w", err)
handleErr := p.HandleEntryError(ctx, entry, fmt.Errorf("failed to process the docker log: %w", err))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}
case containerdFormat, crioFormat:
p.criConsumerStartOnce.Do(func() {
Expand All @@ -119,30 +131,50 @@ func (p *Parser) Process(ctx context.Context, entry *entry.Entry) (err error) {
// parse the message
err = p.ParseWith(ctx, entry, p.parseContainerd, p.Write)
if err != nil {
return fmt.Errorf("failed to parse containerd log: %w", err)
handleErr := p.HandleEntryError(ctx, entry, fmt.Errorf("failed to parse containerd log: %w", err))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}
p.timeLayout = goTimeLayout
} else {
// parse the message
err = p.ParseWith(ctx, entry, p.parseCRIO, p.Write)
if err != nil {
return fmt.Errorf("failed to parse crio log: %w", err)
handleErr := p.HandleEntryError(ctx, entry, fmt.Errorf("failed to parse crio log: %w", err))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}
p.timeLayout = crioTimeLayout
}

err = p.handleTimeAndAttributeMappings(entry)
if err != nil {
return fmt.Errorf("failed to handle attribute mappings: %w", err)
handleErr := p.HandleEntryError(ctx, entry, fmt.Errorf("failed to handle attribute mappings: %w", err))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}

// send it to the recombine operator
err = p.recombineParser.Process(ctx, entry)
if err != nil {
return fmt.Errorf("failed to recombine the crio log: %w", err)
handleErr := p.HandleEntryError(ctx, entry, fmt.Errorf("failed to recombine the crio log: %w", err))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}
default:
return errors.New("failed to detect a valid container log format")
handleErr := p.HandleEntryError(ctx, entry, errors.New("failed to detect a valid container log format"))
if p.OnError == helper.DropOnErrorQuiet || p.OnError == helper.SendOnErrorQuiet {
return nil
}
return handleErr
}

return nil
Expand Down
56 changes: 56 additions & 0 deletions pkg/stanza/operator/parser/container/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,59 @@ func TestCRIRecombineProcessWithFailedDownstreamOperator(t *testing.T) {
})
}
}

func TestContainerQuietModeProcess(t *testing.T) {
testCases := []struct {
name string
onError string
expectError bool
}{
{
name: "DropOnErrorQuiet_ReturnsNoError",
onError: "drop_quiet",
expectError: false,
},
{
name: "SendOnErrorQuiet_ReturnsNoError",
onError: "send_quiet",
expectError: false,
},
{
name: "DropOnError_ReturnsError",
onError: "drop",
expectError: true,
},
{
name: "SendOnError_ReturnsError",
onError: "send",
expectError: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
config := NewConfigWithID("test")
config.OnError = tc.onError
config.OutputIDs = []string{"fake"}

set := componenttest.NewNopTelemetrySettings()
op, err := config.Build(set)
require.NoError(t, err)

fake := testutil.NewFakeOutput(t)
require.NoError(t, op.SetOutputs([]operator.Operator{fake}))

// Create entry with invalid container log format that will cause parse error
e := entry.New()
e.Body = "invalid container log format"
e.ObservedTimestamp = time.Now()

err = op.Process(t.Context(), e)
if tc.expectError {
require.Error(t, err, "expected error in non-quiet mode")
} else {
require.NoError(t, err, "expected no error in quiet mode")
}
})
}
}