Skip to content

[processor/transform] Allow specifying functions per context#16251

Merged
djaglowski merged 7 commits into
open-telemetry:mainfrom
TylerHelmuth:tp-functions-per-context
Nov 15, 2022
Merged

[processor/transform] Allow specifying functions per context#16251
djaglowski merged 7 commits into
open-telemetry:mainfrom
TylerHelmuth:tp-functions-per-context

Conversation

@TylerHelmuth

Copy link
Copy Markdown
Member

Description:
While working on a drop function I ran into an unrelated bug where the metric ContextStatements were using functions initialized with ottldatapoint.TransformContext. This PR fixes the bug by forcing ParserCollection to use the WithOption pattern to set context parsers with their specific set of functions.

Testing:
Unit tests

@TylerHelmuth TylerHelmuth requested a review from a team November 10, 2022 22:27
}
}

func Functions() map[string]interface{} {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was the root of the issue: the metrics processor was calling this function to initialize the MetricsParserCollection, which was then using the registry to parse metric statements. The issue is that these functions are datapoint context functions, so when used with metric statements things would panic if a metric path was used that isn't in datapoints, such as name.

@github-actions github-actions Bot added the processor/transform Transform processor label Nov 11, 2022

@kentquirk kentquirk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I kept coming up with objections to the implementation details and then realizing that there was a good answer to each already. I'm now out of objections and I definitely like the idea here.

@TylerHelmuth

Copy link
Copy Markdown
Member Author

I kept coming up with objections to the implementation details and then realizing that there was a good answer to each already. I'm now out of objections and I definitely like the idea here.

@kentquirk I think a fair criticism of the Options approach here is that it implies that the ParserCollection could be created in a meaningful way with the LogParser or SpanParser etc when in reality that wouldn't really make sense.

I think it could be argued that it would be better to force passing in functions for the parsers that are getting initialized via parameters instead of option functions.

If this lived outside of the transformprocessor I think that would be the better solution to force proper usage. Otherwise you'd have to know to use options if you want those types of parsers.

@github-actions github-actions Bot requested a review from kentquirk November 14, 2022 16:29
@TylerHelmuth TylerHelmuth added the ready to merge Code review completed; ready to merge by maintainers label Nov 14, 2022
@djaglowski djaglowski merged commit f031b3b into open-telemetry:main Nov 15, 2022
@TylerHelmuth TylerHelmuth deleted the tp-functions-per-context branch November 15, 2022 16:21
JaredTan95 pushed a commit to openinsight-proj/opentelemetry-collector-contrib that referenced this pull request Nov 21, 2022
shalper2 pushed a commit to shalper2/opentelemetry-collector-contrib that referenced this pull request Dec 6, 2022
@plantfansam plantfansam mentioned this pull request Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

processor/transform Transform processor ready to merge Code review completed; ready to merge by maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants