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

feat(sourceprocessor): ensure that '_collector' is set before other source headers #824

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This release introduces the following breaking changes:
- chore(deps): bump golang from 1.18.4 to 1.19.2 [#745]
- chore(deps): bump go-boringcrypto to 1.18.7b7 [#746]
- chore: upgrade OpenTelemetry Contrib Core to v0.62.0 [#769]
- feat(sourceprocessor): ensure that '_collector' is set before other source headers [#824]

### Removed

Expand All @@ -50,6 +51,7 @@ This release introduces the following breaking changes:
[#769]: https://github.com/SumoLogic/sumologic-otel-collector/pull/769
[#693]: https://github.com/SumoLogic/sumologic-otel-collector/pull/693
[#767]: https://github.com/SumoLogic/sumologic-otel-collector/pull/767
[#824]: https://github.com/SumoLogic/sumologic-otel-collector/pull/824
[upgrade_guide_unreleased]: ./docs/upgrading.md#unreleased

## [v0.57.2-sumo-1]
Expand Down
4 changes: 2 additions & 2 deletions pkg/processor/sourceprocessor/source_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ func (sp *sourceProcessor) ProcessLogs(ctx context.Context, md plog.Logs) (plog.
return md, nil
}

// processResource performs multiple actions on resource:
// processResource performs multiple actions on resource in the following order:
// - enrich pod name, so it can be used in templates
// - set metadata (collector name), so it can be used in templates as well
// - fills source attributes based on config or annotations
// - set metadata (collector name)
func (sp *sourceProcessor) processResource(res pcommon.Resource) pcommon.Resource {
atts := res.Attributes()

Expand Down
15 changes: 15 additions & 0 deletions pkg/processor/sourceprocessor/source_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,21 @@ func TestSourceCategoryTemplateWithCustomAttribute(t *testing.T) {
attributes := processedTraces.ResourceSpans().At(0).Resource().Attributes()
assertAttribute(t, attributes, "_sourceCategory", "kubernetes/abc/undefined/123")
})

t.Run("attribute is a collector name", func(t *testing.T) {
inputAttributes := createK8sLabels()
traces := newTraceData(inputAttributes)

config := createDefaultConfig().(*Config)
config.SourceCategory = "abc/%{_collector}/123"
config.Collector = "my-collector"

processedTraces, err := newSourceProcessor(config).ProcessTraces(context.Background(), traces)
assert.NoError(t, err)

attributes := processedTraces.ResourceSpans().At(0).Resource().Attributes()
assertAttribute(t, attributes, "_sourceCategory", "kubernetes/abc/my/collector/123")
})
}

func assertAttribute(t *testing.T, attributes pcommon.Map, attributeName string, expectedValue string) {
Expand Down