Skip to content

Commit

Permalink
[processor/resourcedetection] Fix docker detector
Browse files Browse the repository at this point in the history
After migrating the detection processor to the new config interface, the docker detector stopped setting any attributes
  • Loading branch information
dmitryax committed Jul 16, 2023
1 parent 6816bc1 commit cfa10d7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
15 changes: 15 additions & 0 deletions .chloggen/resource-detection-processor-fix-docker-detector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: processor/resourcedetection

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix docker detector not setting any attributes.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24280]
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ type Detector struct {
}

// NewDetector creates a new system metadata detector
func NewDetector(p processor.CreateSettings, _ internal.DetectorConfig) (internal.Detector, error) {
func NewDetector(p processor.CreateSettings, cfg internal.DetectorConfig) (internal.Detector, error) {
dockerProvider, err := docker.NewProvider()
if err != nil {
return nil, fmt.Errorf("failed creating detector: %w", err)
}

return &Detector{provider: dockerProvider, logger: p.Logger}, nil
return &Detector{
provider: dockerProvider,
logger: p.Logger,
resourceAttributes: cfg.(Config).ResourceAttributes,
}, nil
}

// Detect detects system metadata and returns a resource with the available ones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/processor/processortest"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/docker"
)
Expand All @@ -37,8 +37,9 @@ func TestDetect(t *testing.T) {
md.On("Hostname").Return("hostname", nil)
md.On("OSType").Return("darwin", nil)

dcfg := CreateDefaultConfig()
detector := &Detector{provider: md, logger: zap.NewNop(), resourceAttributes: dcfg.ResourceAttributes}
detector, err := NewDetector(processortest.NewNopCreateSettings(), CreateDefaultConfig())
require.NoError(t, err)
detector.(*Detector).provider = md
res, schemaURL, err := detector.Detect(context.Background())
require.NoError(t, err)
assert.Equal(t, conventions.SchemaURL, schemaURL)
Expand Down

0 comments on commit cfa10d7

Please sign in to comment.