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

[pkg/stanza] Use HandleEntryError for error handling #35758

Closed
wants to merge 24 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
19 changes: 10 additions & 9 deletions pkg/stanza/operator/parser/container/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/timeutils"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
stanzaerr "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/errors"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
)
Expand Down Expand Up @@ -73,20 +74,20 @@ func (p *Parser) Process(ctx context.Context, entry *entry.Entry) (err error) {
if format == "" {
format, err = p.detectFormat(entry)
if err != nil {
return fmt.Errorf("failed to detect a valid container log format: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "invalid container log format"))
}
}

switch format {
case dockerFormat:
err = p.ParserOperator.ProcessWithCallback(ctx, entry, p.parseDocker, p.handleAttributeMappings)
khushijain21 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("failed to process the docker log: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "docker log"))
}
timeLayout = goTimeLayout
err = parseTime(entry, timeLayout)
if err != nil {
return fmt.Errorf("failed to parse time: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "parse time"))
}
case containerdFormat, crioFormat:
p.criConsumerStartOnce.Do(func() {
Expand Down Expand Up @@ -117,35 +118,35 @@ func (p *Parser) Process(ctx context.Context, entry *entry.Entry) (err error) {
// parse the message
err = p.ParserOperator.ParseWith(ctx, entry, p.parseContainerd)
khushijain21 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("failed to parse containerd log: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "containerd log"))
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the error already handled inside the ParseWithCallback? I would assume we should return nil here as the entry has already been either moved forward or dropped.

}
timeLayout = goTimeLayout
} else {
// parse the message
err = p.ParserOperator.ParseWith(ctx, entry, p.parseCRIO)
if err != nil {
return fmt.Errorf("failed to parse crio log: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "parse crio log"))
}
timeLayout = crioTimeLayout
}

err = parseTime(entry, timeLayout)
if err != nil {
return fmt.Errorf("failed to parse time: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "parse time"))
}

err = p.handleAttributeMappings(entry)
if err != nil {
return fmt.Errorf("failed to handle attribute mappings: %w", err)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "attribute mappings"))
}

// 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)
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "recombine the crio log"))
khushijain21 marked this conversation as resolved.
Show resolved Hide resolved
}
default:
return fmt.Errorf("failed to detect a valid container log format")
return p.HandleEntryError(ctx, entry, stanzaerr.Wrap(err, "invalid container log format"))
}

return nil
Expand Down
Loading