-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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] Add ParseSeverity
function
#37280
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
… made to mapGetter Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@bacherfl is this still draft? |
@TylerHelmuth Right now this is blocked by #37408 so I left it as draft for now. Once that other PR has been merged this should be ready though |
…#37408) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR fixes the limitations described in #37405. The recently introduced `ValueExpression` had to be adapted, and will now only return raw types, instead of their `pcommon.Map`/`pcommon.Slice` eqivalents, as suggested in #37280 (comment) <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #37405 <!--Describe what testing was performed and which tests were added.--> #### Testing Adapted and extended the unit and e2e tests --------- Signed-off-by: Florian Bacher <[email protected]>
# Conflicts: # pkg/ottl/e2e/e2e_test.go # pkg/ottl/expression.go # pkg/ottl/parser.go
Signed-off-by: Florian Bacher <[email protected]>
Ready for review by codeowners: @TylerHelmuth, @kentquirk, @bogdandrutu, @evan-bradley, @edmocosta please review. |
@bacherfl is it ready for review? description says it's still in progress. |
yes - i forgot to update the description, but it is ready |
if err := mapstructure.Decode(raw, &s); err != nil { | ||
return nil, fmt.Errorf("cannot decode severity mapping: %w", err) | ||
} |
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 dont understand how this is validating.
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.
yes the name of the function was not accurate, I renamed it now. But speaking of validation - do you think it would be better to validate the full mapping at the beginning of the function, or rather return an error when we run into an error during the evaluation of the log level?
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.
We can't validate the map statically during startup, so I think returning errors when we encounter something unexpected is the right thing to do since it is more efficient.
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.
Also, why do we need to decode? I think we can check the type of the value when we try to use it and if it isn't a []any
then we error.
Also would we need to check of other slice types? if the underlying value is a []string than it wont be considered a []any.
Signed-off-by: Florian Bacher <[email protected]>
TBH, I found this function's usage a bit confusing, and I'm not sure how it would scale if we decide to add new options. I think it would be clear (and more scalable) if we named the conditions types, for example The current mappings: ParseSeverity(severity_number, {
"error":["err", { "min": 3, "max": 4 }],
"info":[{ "min": 1, "max": 2 }],
}
)) Could be expressed as: PaseSeverity(severity_number, {
"error": [{"equals": "err"}, {"range":[3,4]}],
"info": [{"range":[1,2]}],
}) With condition names, it's clear for me that the loose "err" string is an "equals" condition, and that the map with Another future possibility would be supporting the PaseSeverity(severity_number, {
"error": [{"equals": "err", "range":[3,4]}, {"range":[5,6]}],
}) Just sharing my thoughts and opening it for discussion. If we don't have further plan for this function, it would be fine as it's (although naming the conditions would simplify the code, I guess). |
@edmocosta the goal here was to use the same structure as the severity parser in stanza: #35079 (comment) |
I'm sorry for the noise, I probably misunderstood it and I thought the goal was having the same stanza functionality, and not exactly replicate the same configuration structure. I'm still don't understand why that should be a requirement, but if you folks agreed on that, I'm fine. Thanks for clarifying. |
Description
This PR adds the
ParseSeverity
function, as discussed in the linked ticket. I also had to make a minor change to theinternal
mapGetter
, handling the map literals to return a rawmap[string]any
, instead of apcommon.Map
. This is because if there is a map literal within a slice, thepcommon.Slice.FromRaw
cannot handle thepcommon.Map
, as it only works with raw data types.This change is however transparent, and the behavior to the outside of this package does not change.
EDIT: After merging main with the support for value expressions, introduced in #36883, this would affect the type of values returned by
ParseValueExpression
- previously this could potentially returnmap[string]any
/[]any
, but with the changes introduced in this PR, this would return apcommon.Map
/pcommon.Slice
.Please let me know if I should do this change in a separate PR though.
Link to tracking issue
Fixes #35079
Testing
Added unit and e2e tests
Documentation
Describe new function in the readme