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

[processor/logdedup] feat: add ottl condition to logdedup processor #35443

Conversation

colelaven
Copy link
Contributor

Description:

Adds OTTL Condition field to Deduplicate Logs Processor

Link to tracking Issue: Closes #35440

Testing:

  • Tested functionality with BindPlane
  • Added unit tests for the condition logic

Documentation: Added documentation to the logdedup processor README about the condition field and an example configuration with a condition.

@colelaven colelaven requested review from djaglowski and a team as code owners September 26, 2024 17:22
Copy link

linux-foundation-easycla bot commented Sep 26, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

processor/logdedupprocessor/processor.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/processor.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/processor.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/factory.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/processor.go Outdated Show resolved Hide resolved
Copy link
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Overall looks good, thanks @colelaven. I've left a couple of suggestions. The main one being breaking out condition into a set of conditions.

processor/logdedupprocessor/README.md Outdated Show resolved Hide resolved
processor/logdedupprocessor/factory.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/README.md Outdated Show resolved Hide resolved
Copy link
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks good to me, just need to fix up the docs for how the processor handles no configured conditions.

processor/logdedupprocessor/README.md Outdated Show resolved Hide resolved
@colelaven colelaven force-pushed the feat/add-condition-to-logdedup-processor branch from 36b0a50 to a2135f1 Compare October 4, 2024 14:56
Comment on lines 298 to 326
consumedLogs := allSinkLogs[0]
require.Equal(t, 2, consumedLogs.LogRecordCount())

require.Equal(t, 1, consumedLogs.ResourceLogs().Len())
consumedRl := consumedLogs.ResourceLogs().At(0)
require.Equal(t, 1, consumedRl.ScopeLogs().Len())
consumedSl := consumedRl.ScopeLogs().At(0)
require.Equal(t, 2, consumedSl.LogRecords().Len())

for i := 0; i < consumedSl.LogRecords().Len(); i++ {
consumedLogRecord := consumedSl.LogRecords().At(i)
ID, ok := consumedLogRecord.Attributes().Get("ID")
require.True(t, ok)
require.Equal(t, int64(2), ID.Int())
}

dedupedLogs := allSinkLogs[1]
require.Equal(t, 1, dedupedLogs.LogRecordCount())

require.Equal(t, 1, dedupedLogs.ResourceLogs().Len())
dedupedRl := dedupedLogs.ResourceLogs().At(0)
require.Equal(t, 1, dedupedRl.ScopeLogs().Len())
dedupedSl := dedupedRl.ScopeLogs().At(0)
require.Equal(t, 1, dedupedSl.LogRecords().Len())
dedupedLogRecord := dedupedSl.LogRecords().At(0)

countVal, ok := dedupedLogRecord.Attributes().Get(cfg.LogCountAttribute)
require.True(t, ok)
require.Equal(t, int64(2), countVal.Int())
Copy link
Member

Choose a reason for hiding this comment

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

When comparing actual vs expected telemetry, the code can be very complex and still the comparison can be very incomplete. We added some packages to facilitate more precise validation of expected results.

Specifically, use the golden package capture and reload expected results. Use golden.WriteLogs to write these objects once. Then delete the WriteLogs call and use ReadLogs in the actual test.

Then use pdatatest/plogtest.CompareLogs (and make sure to assert no error). You may need to pass in some options to ignore volatile parts of the logs.

Here's an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, just pushed a commit to use golden for the tests and it looks much cleaner now.

processor/logdedupprocessor/processor_test.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/processor_test.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/processor_test.go Outdated Show resolved Hide resolved
processor/logdedupprocessor/processor_test.go Outdated Show resolved Hide resolved
require.NoError(t, err)
}

func removeTimestamps(plogs ...plog.Logs) {
Copy link
Member

Choose a reason for hiding this comment

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

There should be an option in plogtest to ignore these attributes values. This still allows validation that the attributes are present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There wasn't an existing option to ignore log record attribute values, only one for ignoring resource attributes. I added one for ignoring log record attribute values and it is working great.
Let me know if adding that option is not something I should be doing in this PR.

@djaglowski djaglowski merged commit a4b60c7 into open-telemetry:main Oct 8, 2024
155 checks passed
@djaglowski
Copy link
Member

Thanks @colelaven

@github-actions github-actions bot added this to the next release milestone Oct 8, 2024
@colelaven colelaven deleted the feat/add-condition-to-logdedup-processor branch October 8, 2024 13:42
Eromosele-SM pushed a commit to sematext/opentelemetry-collector-contrib that referenced this pull request Oct 9, 2024
…pen-telemetry#35443)

**Description:**

Adds OTTL Condition field to Deduplicate Logs Processor

**Link to tracking Issue:** Closes open-telemetry#35440 

**Testing:** 
- Tested functionality with BindPlane
- Added unit tests for the condition logic

**Documentation:** Added documentation to the logdedup processor README
about the condition field and an example configuration with a condition.

---------

Co-authored-by: Mike Goldsmith <[email protected]>
@colelaven colelaven restored the feat/add-condition-to-logdedup-processor branch October 23, 2024 13:24
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.

[processor/logdedup] Add OTTL Condition Field to logdedup processor
5 participants