You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[pkg/ottl] Change grammar to support expressing statements context via 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.
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(""))
92
+
}
93
+
94
+
returnpath.Context, path.Fields, nil
95
+
}
96
+
97
+
ifhasPathContextNames {
98
+
originalText:=buildOriginalText(path)
99
+
return"", nil, fmt.Errorf(`missing context name for path "%s", possibly valid options are: %s`, originalText, p.buildPathContextNamesText(originalText))
0 commit comments