Skip to content

[pkg/ottl] Add OTTL context inferrer utility #35721

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

Merged

Conversation

edmocosta
Copy link
Contributor

Description

This PR is part of #29017, and adds the context inferrer utility into the ottl package. This utility will be used by components to infer the context it should use to parse some statements, based only on its ottl.path's context prefixes.

This PR delivers a priority-based ottl.ContextInferrer implementation, which chooses the context based on a priority list passed on the ottl.NewPriorityContextInferrer function. It also exposes the ottl.DefaultPriorityContextInferrer function, which creates the same context inferrer type, but using a pre-defined context priorities.

For example, given the context priority ["spanevent", "span", "resource"], and inferring the context from the statement
set(span.foo, resource.value) where spanevent.bar == true, would result in the spanevent context, as it has the highest priority.

For more details on how it will be used, please have a look at the complete draft implementation.

To discuss

Do we really need to support the NewPriorityContextInferrer ignoreUnknownContext argument?

I would say yes, considering the inferrer could be used for any purpose, having the capability of ignoring unknown/non-prioritised contexts would be helpful and wouldn't require users to check if the Infer(..) function returned an unexpected value.

Link to tracking issue

#29017

Testing

Unit tests

Documentation

No changes

@edmocosta
Copy link
Contributor Author

Hi @TylerHelmuth! I've addressed your suggestions to under expose the context inferrer impl (c0a8b67). In addition to that, I've also removed the ignoreUnknownContext option, as we won't need that anymore. All internal usages on the draft are setting that flag to false, and considering we won't be exposing the context inferrer anymore, it would be a dead code. Thanks!

@TylerHelmuth TylerHelmuth added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Oct 22, 2024
@evan-bradley evan-bradley merged commit ecf9538 into open-telemetry:main Oct 22, 2024
167 of 168 checks passed
@github-actions github-actions bot added this to the next release milestone Oct 22, 2024
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
TylerHelmuth pushed a commit that referenced this pull request Feb 10, 2025
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Added debug logs for the [context inferrer
utility](#35721),
it will be useful for troubleshooting possibly issues after officially
releasing the new `transformprocessor` configuration syntaxes.


Example successfully inferred:

```
2025-02-10T11:58:42.735+0100	DEBUG	Inferring context from statements	{"candidates": ["resource", "scope", "metric", "datapoint"], "priority": {"datapoint":1,"instrumentation_scope":7,"log":0,"metric":2,"resource":5,"scope":6,"span":4,"spanevent":3}, "statements": ["replace_pattern(metric.name, \"my.(.+)\", \"metrics.$1\")"]}
2025-02-10T11:58:42.736+0100	DEBUG	Validating selected context candidate: "metric"
2025-02-10T11:58:42.736+0100	DEBUG	Inferred context: "metric"
```

Example unable to infer:

```
2025-02-10T12:05:00.863+0100	DEBUG	Inferring context from statements	{"candidates": ["metric", "datapoint", "resource", "scope"], "priority": {"datapoint":1,"instrumentation_scope":7,"log":0,"metric":2,"resource":5,"scope":6,"span":4,"spanevent":3}, "statements": ["convert_sum_to_gauge() where metric.name == \"system.processes.count\"", "limit(datapoint.attributes, 100, [\"host.name\"])"]}
2025-02-10T12:05:00.867+0100	DEBUG	Validating selected context candidate: "datapoint"
2025-02-10T12:05:00.867+0100	DEBUG	Context "datapoint" does not meet the function requirement: "convert_sum_to_gauge"
2025-02-10T12:05:00.867+0100	DEBUG	Trying to infer context using "datapoint" lower contexts
2025-02-10T12:05:00.867+0100	DEBUG	Unable to infer context from statements
```

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue

#29017

<!--Please delete paragraphs that you did not use before submitting.-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/ottl Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants