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/resourcedetection] Fix docker detector #24281

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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