Skip to content

Introduce inferred-context for filterprocessor#39688

Closed
jaronoff97 wants to merge 12 commits intoopen-telemetry:mainfrom
jaronoff97:jaronoff97-37904-filter-processor-changes
Closed

Introduce inferred-context for filterprocessor#39688
jaronoff97 wants to merge 12 commits intoopen-telemetry:mainfrom
jaronoff97:jaronoff97-37904-filter-processor-changes

Conversation

@jaronoff97
Copy link
Contributor

Description

This PR adds the ability to do context inference for conditions for the filter processor. New config fields are introduced for the supported telemetry types and an isolated code path is introduced for ease of review and separation of concerns

Link to tracking issue

Fixes #37904

Testing

Unit, ran locally

Documentation

TODO

@github-actions github-actions bot added the processor/filter Filter processor label Apr 28, 2025
@jaronoff97 jaronoff97 marked this pull request as ready for review May 6, 2025 16:27
@jaronoff97 jaronoff97 requested a review from a team as a code owner May 6, 2025 16:27
@atoulme
Copy link
Contributor

atoulme commented May 9, 2025

Looks OK to my untrained eye, asking for codeowner review.

Copy link
Contributor

@edmocosta edmocosta left a comment

Choose a reason for hiding this comment

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

Thanks for working on it, @jaronoff97, it's great to have standardized settings across processors :)

These are early comments; I'm still going through the PR.

// Validate checks if the processor configuration is valid
func (cfg *Config) Validate() error {
// TODO: The old format should be deprecated and removed.
if cfg.TraceConditions != nil && (cfg.Traces.SpanConditions != nil || cfg.Traces.SpanEventConditions != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add some tests for those mixed-style conditions?

flp.telemetry = fpt

if len(cfg.LogConditions) > 0 {
pc, collectionErr := common.NewLogParserCollection(set.TelemetrySettings, common.WithLogParser(filterottl.StandardLogFuncs()))
Copy link
Contributor

Choose a reason for hiding this comment

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

We're missing passing the default error_mode options (common.With*ErrorMode) for the parser collections (other signals too). In addition to that, can we please also port the existing error mode unit tests from the transform processor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want me to port these tests for the config or these tests for the processors, or both?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant the second set of tests that are specific for error mode.

return Scope
}

func (s scopeConditions) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we've no coverage for the scope context (all signals). Can we please add some tests for that?

if cfg.TraceConditions != nil && (cfg.Traces.SpanConditions != nil || cfg.Traces.SpanEventConditions != nil) {
return errors.New("cannot use inferred context trace conditions and old format at the same time")
}
if cfg.MetricConditions != nil && (cfg.Metrics.MetricConditions != nil || cfg.Metrics.DataPointConditions != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to wrap my head around on how this processor config should work, but based on the existing settings and validations (docs is missing), it should use either the include and exclude settings, OR the OTTL conditions, but not both.

That said, I think we're missing a validation here, so it does not allow the include and exclude keys when <sinal>_conditions are configured.

if errors != nil {
return nil, errors
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should early return here as skipExpr won't be evaluated when the signal condition is set.

)

type filterLogProcessor struct {
consumers []common.LogsConsumer
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if we could add some tests for all signals processors using their context inferrer settings (like we do for the transformprocessor (example), so we can ensure that filtering all possible inferred contexts works.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still think we need to add tests for the high level processor code (all signals). I might be wrong, but I don't think the current implementation is working as expected with the new context inferred style.

At the moment, we're skipping processing the data for all signals when the skipExpr is nil, leading configurations with only context inferred conditions to be no-op.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 3, 2025
@edmocosta edmocosta removed the Stale label Jun 3, 2025
@edmocosta edmocosta self-assigned this Jun 3, 2025
@jaronoff97
Copy link
Contributor Author

@edmocosta i still want to work at this, ive been very busy the past week 😢

@jaronoff97
Copy link
Contributor Author

still going through rn to add tests!

@jaronoff97
Copy link
Contributor Author

@edmocosta i think this should be ready for another review. One thing i'd like your take on – I think we could probably condense the individual <signal>_conditions into a single ottl_conditions and just parse them dynamically with a single parser collection rather than having one per telemetry type, this would simplify the configuration a lot as well as a lot of the code. What do you think?

switch {
case tt.filterEverything && !tt.wantErr:
assert.Equal(t, processorhelper.ErrSkipProcessingData, consumeErr)
case tt.wantErr:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this condition and the above && !tt.wantErr? It seems we're early returning it when tt.wantErr == true at line 96. If we want to assert both operations ParseContextConditions and ConsumeLogs errors, we probably should be more specific on the expected error string.

errorMode ottl.ErrorMode
conditions []common.ContextConditions
want func(td plog.Logs)
wantErr bool
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we're not using this wantErr field on the tests scenarios. if so, we could just drop it and keep only the wantErrorWith.

// Apply each consumer sequentially
for _, consumer := range consumers {
if err := consumer.ConsumeLogs(context.Background(), finalLogs); err != nil {
if errors.Is(err, processorhelper.ErrSkipProcessingData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't fully understand this block, shouldn't it be something like the following if the idea is to ignore ErrSkipProcessingData errors? am I missing something?

if err := consumer.ConsumeLogs(context.Background(), finalLogs); err != nil {
  if !errors.Is(err, processorhelper.ErrSkipProcessingData) {
     consumeErr = err
     break
   }
}

If that's the case, we can also drop the if condition at line 236 and assert.NoError(t, consumeErr) it directly.

)

type filterLogProcessor struct {
consumers []common.LogsConsumer
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still think we need to add tests for the high level processor code (all signals). I might be wrong, but I don't think the current implementation is working as expected with the new context inferred style.

At the moment, we're skipping processing the data for all signals when the skipExpr is nil, leading configurations with only context inferred conditions to be no-op.

@edmocosta
Copy link
Contributor

@edmocosta i think this should be ready for another review. One thing i'd like your take on – I think we could probably condense the individual <signal>_conditions into a single ottl_conditions and just parse them dynamically with a single parser collection rather than having one per telemetry type, this would simplify the configuration a lot as well as a lot of the code. What do you think?

That's interesting, but I'm not completely sure if that would work, we need to run some tests to double check that.
My concern are the shared contexts, such as resource and scope, which are common for all other signals. In that case, if one condition only use those shared contexts, e.g. `resource.attributes["bar"] == "foo"', It would apply & filter data for all signals, which maybe is not desired I guess 🤔

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jul 24, 2025
@edmocosta edmocosta removed the Stale label Jul 24, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Aug 8, 2025
@edmocosta edmocosta removed the Stale label Aug 12, 2025
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Sep 24, 2025
@edmocosta edmocosta removed the Stale label Sep 25, 2025
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Oct 10, 2025
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Oct 25, 2025
kaisecheng added a commit to kaisecheng/opentelemetry-collector-contrib that referenced this pull request Nov 26, 2025
This commit continues the work from PR open-telemetry#39688 by @jaronoff97
- Carried over the original implementation
- Fixed error_mode ignore test cases
- Fixed issues with resource filtering

Co-authored-by: jaronoff97 <jacobaronoff45@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter Processor should support inferred context statements

6 participants