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/ottl] Improve Statement execution error message #18733

Merged
Merged
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
6 changes: 4 additions & 2 deletions pkg/ottl/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Parser[K any] struct {
type Statement[K any] struct {
function Expr[K]
condition BoolExpr[K]
origText string
}

// Execute is a function that will execute the statement's function if the statement's condition is met.
Expand Down Expand Up @@ -134,6 +135,7 @@ func (p *Parser[K]) ParseStatement(statement string) (*Statement[K], error) {
return &Statement[K]{
function: function,
condition: expression,
origText: statement,
}, nil
}

Expand Down Expand Up @@ -201,10 +203,10 @@ func (s *Statements[K]) Execute(ctx context.Context, tCtx K) error {
_, _, err := statement.Execute(ctx, tCtx)
if err != nil {
if s.errorMode == PropagateError {
err = fmt.Errorf("failed to execute statement: %w", err)
err = fmt.Errorf("failed to execute statement: %v, %w", statement.origText, err)
return err
}
s.telemetrySettings.Logger.Error("failed to execute statement", zap.Error(err))
s.telemetrySettings.Logger.Warn("failed to execute statement", zap.Error(err), zap.String("statement", statement.origText))
Copy link
Member

Choose a reason for hiding this comment

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

Is it intentional that you're changing the log level here from Error to Warn?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. My reasoning is that if using error_mode: ignore you are acknowledging that issues in individual statements should be ignored. If we log them as Error, then any user who is monitoring their collector logs for errors would find these messages as errors. I think Warn is a more appropriate level as it will let the users see that something happened, but not trigger any monitoring that is watching for errors.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree with this reasoning.

}
}
return nil
Expand Down