-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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] Change grammar to support expressing statements context via path names #34875
[pkg/ottl] Change grammar to support expressing statements context via path names #34875
Conversation
…lector-contrib into ottl_statements_context_change_grammar
e2d7f05
to
ee02ebd
Compare
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.
@edmocosta I like the way this is looking.
For big refactors like this is gonna end up being we typically create a draft PR with all the changes implemented as if we were going to merge in a breaking change. Can you create a draft PR like that for this work? I'm interested to see the final picture for what we're trying to achieve before we start merging things. Don't worry about unit tests, I just want to see who the API and implementation shakes out.
pkg/ottl/functions.go
Outdated
// path's segment. | ||
if !hasPathContextNames { | ||
return "", append([]field{{Name: path.Context}}, path.Fields...), nil | ||
} else if _, ok := p.pathContextNames[path.Context]; !ok { |
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 remove this else.
pkg/ottl/functions.go
Outdated
return "", path.Fields, fmt.Errorf(`context "%s" from path "%s" is not valid, it must be replaced by one of: %s`, path.Context, buildOriginalText(path), p.buildPathContextNamesText("")) | ||
} | ||
return path.Context, path.Fields, nil | ||
} else if hasPathContextNames { |
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 remove this else.
Sure thing! I'll create a draft PR with all the pieces together soon! Thanks @TylerHelmuth! |
Hi @TylerHelmuth! here's the draft PR: #35050 |
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.
@edmocosta thanks for quickly writing up that draft. There is definitely a lot of complexity we're adding with this change, but I believe the portability and readability of:
trace_statements:
- set(span.status.code, 1) where span.attributes["http.path"] == "/health"
is really nice. Take a look at the remaining comments and then we can get this merged and move on to the next step.
…"possibly" on the error message
@TylerHelmuth, I've addressed the suggestions, plus two nitpicks that I changed on the draft PR:
|
…a path names (open-telemetry#34875) **Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> This PR is part of the open-telemetry#29017, and introduces the necessary OTTL Grammar/Parser changes to make it possible for statements express their context via path names. This first iteration changes the grammar to parse the first `path` segment as the `Context` name, for example, the path `foo.bar.field` would be parsed as the following AST example: `{Context: "foo", Fields: [{Name: "bar"}, {Name: "field"}]}`, instead of `{Fields: [{Name: "foo"},{Name: "bar"}, {Name: "field"}]}`. To make it non-breaking to all components during the transition time and development, this PR also changes the `ottl.Parser[k].newPath` function to, by default, fall this new behavior back to the previous one, using the grammar's parsed `Context` value as the first path segment (`Fields[0]`). Two new `Parser[K]` options were added, `WithPathContextNames` and `WithPathContextNameValidation`, The first option will be used to enable the statements context support, parsing the first path segment as Context when the value maches any configured context names, or falling it back otherwise. The second option will be used to enable the validation and turning off the backward compatible mode, raising an error when paths have no context prefix, or when it's invalid. For more details, please check the open-telemetry#29017 discussion out. **Link to tracking Issue:** open-telemetry#29017 **Testing:** - Unit tests **Documentation:** - No documentation changes were made at this point.
…a path names (open-telemetry#34875) **Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> This PR is part of the open-telemetry#29017, and introduces the necessary OTTL Grammar/Parser changes to make it possible for statements express their context via path names. This first iteration changes the grammar to parse the first `path` segment as the `Context` name, for example, the path `foo.bar.field` would be parsed as the following AST example: `{Context: "foo", Fields: [{Name: "bar"}, {Name: "field"}]}`, instead of `{Fields: [{Name: "foo"},{Name: "bar"}, {Name: "field"}]}`. To make it non-breaking to all components during the transition time and development, this PR also changes the `ottl.Parser[k].newPath` function to, by default, fall this new behavior back to the previous one, using the grammar's parsed `Context` value as the first path segment (`Fields[0]`). Two new `Parser[K]` options were added, `WithPathContextNames` and `WithPathContextNameValidation`, The first option will be used to enable the statements context support, parsing the first path segment as Context when the value maches any configured context names, or falling it back otherwise. The second option will be used to enable the validation and turning off the backward compatible mode, raising an error when paths have no context prefix, or when it's invalid. For more details, please check the open-telemetry#29017 discussion out. **Link to tracking Issue:** open-telemetry#29017 **Testing:** - Unit tests **Documentation:** - No documentation changes were made at this point.
Description:
This PR is part of the #29017, and introduces the necessary OTTL Grammar/Parser changes to make it possible for statements express their context via path names.
This first iteration changes the grammar to parse the first
path
segment as theContext
name, for example, the pathfoo.bar.field
would be parsed as the following AST example:{Context: "foo", Fields: [{Name: "bar"}, {Name: "field"}]}
, instead of{Fields: [{Name: "foo"},{Name: "bar"}, {Name: "field"}]}
.To make it non-breaking to all components during the transition time and development, this PR also changes the
ottl.Parser[k].newPath
function to, by default, fall this new behavior back to the previous one, using the grammar's parsedContext
value as the first path segment (Fields[0]
).Two new
Parser[K]
options were added,WithPathContextNames
andWithPathContextNameValidation
, The first option will be used to enable the statements context support, parsing the first path segment as Context when the value maches any configured context names, or falling it back otherwise. The second option will be used to enable the validation and turning off the backward compatible mode, raising an error when paths have no context prefix, or when it's invalid.For more details, please check the #29017 discussion out.
Link to tracking Issue: #29017
Testing:
Documentation: