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] add ValueExpression to support extraction of values from the signal context #36883

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bacherfl
Copy link
Contributor

@bacherfl bacherfl commented Dec 18, 2024

Description

This PR adds a new ParseValueExpression method to the OTTL parser which allows users of this package to extract data from the context using OTTL

Link to tracking issue

Fixes #35621

Testing

Added unit and e2e tests

Documentation

Added godoc comments for the added methods and types

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]>
@bacherfl bacherfl changed the title Feat/35621/ottl expression evaluation [pkg/ottl] add ValueExpression to support extraction of values from the signal context Dec 18, 2024
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me.

# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
change_logs: []
change_logs: [api]

Since the target of this feature is component authors, we should mark it as an API change.

func parseValueExpression(raw string) (*value, error) {
parsed, err := valueExpressionParser.ParseString("", raw)
if err != nil {
return nil, fmt.Errorf("condition has invalid syntax: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("condition has invalid syntax: %w", err)
return nil, fmt.Errorf("expression has invalid syntax: %w", err)

component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add value expression parser that enables components using ottl to retrieve values from the context, as well as the result of converter functions
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
note: Add value expression parser that enables components using ottl to retrieve values from the context, as well as the result of converter functions
note: Add value expression parser that enables components using ottl to retrieve values from the output of an expression

# (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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
subtext:
subtext: the expression can be either a literal value, a path value within the context, or the result of a converter and/or a mathematical expression.

I think the doc you wrote for this is perfect for describing what can be used inside the subtext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pkg/ottl] Support for data retrieval OTTL expressions
2 participants