-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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] Handle nil val in IsMatch #17572
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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: pkg/ottl | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Fix issue where IsMatch returned an error if the target val was nil | ||
|
||
# One or more tracking issues related to the change | ||
issues: [17572] | ||
|
||
# (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: | | ||
- Affected components | ||
- `filterprocessor` | ||
- `routingprocessor` | ||
- `transformprocessor` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ func IsMatch[K any](target ottl.Getter[K], pattern string) (ottl.ExprFunc[K], er | |
if err != nil { | ||
return nil, err | ||
} | ||
if val == nil { | ||
return false, nil | ||
} | ||
|
||
switch v := val.(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but keep in mind that this path is a slippery path, and will for sure hurt us. The fact that you accept multiple types instead of asking users to call this as IsMatch(..., string(value)) and enforce always having string here. The reason is because I feel like this will get duplicate in multiple places and will diverge. You can at least start by adding "String()" func and call it on the value to avoid duplicate code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want to force users to use a String() Converter function every time they use IsMatch so I like that the function handles conversion for you. Conversion is only happening for the target, not the pattern. If your concern is only the potential duplication of the type switch statement for strings, I can pull that out into a helper function for future reuse. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's start with avoiding potential duplication, I bet we already duplicate this. |
||
case string: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the usual approach with changes to libraries like this? Should each impacted component get its own changelog entry? I'm good with doing it like this, but could also see the other side of things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have an established pattern. I did this once before in the 0.65.0 release.