Skip to content

Commit

Permalink
fix test + polishing
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Jan 28, 2025
1 parent 5094273 commit 33d4edf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,11 @@ with detailed sample configurations in [testdata/config.yaml](./testdata/config.

**Note:**

If you want to disable the ordering of the detectors and instead have a non-blocking resource detection in case of a detection failure, set the `keepOrder` parameter to `false`. For example:
If you want to disable the ordering of the detectors and instead have a non-blocking resource detection in case of a detection failure, set the `order` parameter to `false`. For example:

```yaml
processors:
resourcedetection:
detectors: [docker]
keepOrder: false
order: false
```
4 changes: 2 additions & 2 deletions processor/resourcedetectionprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ type Config struct {
// If a supplied attribute is not a valid attribute of a supplied detector it will be ignored.
// Deprecated: Please use detector's resource_attributes config instead
Attributes []string `mapstructure:"attributes"`
// KeepOrder is a parameter which perserves the order of detectors and the detection of data
// Order is a parameter which perserves the order of detectors and the detection of data
// This also introduces a blocking behavior, if one of the detectors cannot detect the resource
KeepOrder bool `mapstructure:"keepOrder"`
Order bool `mapstructure:"order"`
}

// DetectorConfig contains user-specified configurations unique to all individual detectors
Expand Down
7 changes: 7 additions & 0 deletions processor/resourcedetectionprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestLoadConfig(t *testing.T) {
DetectorConfig: openshiftConfig,
ClientConfig: cfg,
Override: false,
Order: true,
},
},
{
Expand All @@ -82,6 +83,7 @@ func TestLoadConfig(t *testing.T) {
ClientConfig: cfg,
Override: false,
DetectorConfig: detectorCreateDefaultConfig(),
Order: true,
},
},
{
Expand All @@ -91,6 +93,7 @@ func TestLoadConfig(t *testing.T) {
DetectorConfig: ec2Config,
ClientConfig: cfg,
Override: false,
Order: true,
},
},
{
Expand All @@ -101,6 +104,7 @@ func TestLoadConfig(t *testing.T) {
ClientConfig: cfg,
Override: false,
Attributes: []string{"a", "b"},
Order: true,
},
},
{
Expand All @@ -110,6 +114,7 @@ func TestLoadConfig(t *testing.T) {
ClientConfig: cfg,
Override: false,
DetectorConfig: detectorCreateDefaultConfig(),
Order: true,
},
},
{
Expand All @@ -119,6 +124,7 @@ func TestLoadConfig(t *testing.T) {
ClientConfig: cfg,
Override: false,
DetectorConfig: detectorCreateDefaultConfig(),
Order: true,
},
},
{
Expand All @@ -128,6 +134,7 @@ func TestLoadConfig(t *testing.T) {
ClientConfig: cfg,
Override: false,
DetectorConfig: resourceAttributesConfig,
Order: true,
},
},
{
Expand Down
8 changes: 4 additions & 4 deletions processor/resourcedetectionprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func createDefaultConfig() component.Config {
Override: true,
Attributes: nil,
DetectorConfig: detectorCreateDefaultConfig(),
KeepOrder: true,
Order: true,
// TODO: Once issue(https://github.com/open-telemetry/opentelemetry-collector/issues/4001) gets resolved,
// Set the default value of 'hostname_source' here instead of 'system' detector
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func (f *factory) getResourceDetectionProcessor(
if oCfg.Attributes != nil {
params.Logger.Warn("You are using deprecated `attributes` option that will be removed soon; use `resource_attributes` instead, details on configuration: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#migration-from-attributes-to-resource_attributes")
}
provider, err := f.getResourceProvider(params, oCfg.ClientConfig.Timeout, oCfg.Detectors, oCfg.DetectorConfig, oCfg.Attributes, oCfg.KeepOrder)
provider, err := f.getResourceProvider(params, oCfg.ClientConfig.Timeout, oCfg.Detectors, oCfg.DetectorConfig, oCfg.Attributes, oCfg.Order)
if err != nil {
return nil, err
}
Expand All @@ -219,7 +219,7 @@ func (f *factory) getResourceProvider(
configuredDetectors []string,
detectorConfigs DetectorConfig,
attributes []string,
keepOrder bool,
order bool,
) (*internal.ResourceProvider, error) {
f.lock.Lock()
defer f.lock.Unlock()
Expand All @@ -233,7 +233,7 @@ func (f *factory) getResourceProvider(
detectorTypes = append(detectorTypes, internal.DetectorType(strings.TrimSpace(key)))
}

provider, err := f.resourceProviderFactory.CreateResourceProvider(params, timeout, attributes, &detectorConfigs, keepOrder, detectorTypes...)
provider, err := f.resourceProviderFactory.CreateResourceProvider(params, timeout, attributes, &detectorConfigs, order, detectorTypes...)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (f *ResourceProviderFactory) CreateResourceProvider(
timeout time.Duration,
attributes []string,
detectorConfigs ResourceDetectorConfig,
keepOrder bool,
order bool,
detectorTypes ...DetectorType,
) (*ResourceProvider, error) {
detectors, err := f.getDetectors(params, detectorConfigs, detectorTypes)
Expand All @@ -60,7 +60,7 @@ func (f *ResourceProviderFactory) CreateResourceProvider(
}
}

provider := NewResourceProvider(params.Logger, timeout, attributesToKeep, keepOrder, detectors...)
provider := NewResourceProvider(params.Logger, timeout, attributesToKeep, order, detectors...)
return provider, nil
}

Expand Down Expand Up @@ -90,7 +90,7 @@ type ResourceProvider struct {
detectedResource *resourceResult
once sync.Once
attributesToKeep map[string]struct{}
keepOrder bool
order bool
}

type resourceResult struct {
Expand All @@ -99,13 +99,13 @@ type resourceResult struct {
err error
}

func NewResourceProvider(logger *zap.Logger, timeout time.Duration, attributesToKeep map[string]struct{}, keepOrder bool, detectors ...Detector) *ResourceProvider {
func NewResourceProvider(logger *zap.Logger, timeout time.Duration, attributesToKeep map[string]struct{}, order bool, detectors ...Detector) *ResourceProvider {
return &ResourceProvider{
logger: logger,
timeout: timeout,
detectors: detectors,
attributesToKeep: attributesToKeep,
keepOrder: keepOrder,
order: order,
}
}

Expand Down Expand Up @@ -156,11 +156,11 @@ func (p *ResourceProvider) detectResource(ctx context.Context) {
}
}
}(detector)
if p.keepOrder {
if p.order {
mergedSchemaURL = handleResult(&res, resultsChan, mergedSchemaURL)
}
}
if !p.keepOrder {
if !p.order {
for range p.detectors {
mergedSchemaURL = handleResult(&res, resultsChan, mergedSchemaURL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDetect(t *testing.T) {
detectedResources []map[string]any
expectedResource map[string]any
attributes []string
keepOrder bool
order bool
}{
{
name: "Detect three resources",
Expand All @@ -53,7 +53,7 @@ func TestDetect(t *testing.T) {
},
expectedResource: map[string]any{"a": "1", "b": "2", "c": "3"},
attributes: nil,
keepOrder: true,
order: true,
}, {
name: "Detect empty resources",
detectedResources: []map[string]any{
Expand All @@ -63,7 +63,7 @@ func TestDetect(t *testing.T) {
},
expectedResource: map[string]any{"a": "1", "b": "2"},
attributes: nil,
keepOrder: true,
order: true,
}, {
name: "Detect non-string resources",
detectedResources: []map[string]any{
Expand All @@ -73,7 +73,7 @@ func TestDetect(t *testing.T) {
},
expectedResource: map[string]any{"a": "11", "bool": true, "int": int64(2), "double": 0.5},
attributes: nil,
keepOrder: true,
order: true,
}, {
name: "Filter to one attribute",
detectedResources: []map[string]any{
Expand All @@ -83,7 +83,7 @@ func TestDetect(t *testing.T) {
},
expectedResource: map[string]any{"a": "1"},
attributes: []string{"a"},
keepOrder: true,
order: true,
}, {
name: "Detect resources without order",
detectedResources: []map[string]any{
Expand All @@ -93,7 +93,7 @@ func TestDetect(t *testing.T) {
},
expectedResource: map[string]any{"a": "1", "b": "2", "c": "3", "d": "3"},
attributes: nil,
keepOrder: false,
order: false,
},
}

Expand All @@ -116,7 +116,7 @@ func TestDetect(t *testing.T) {
}

f := NewProviderFactory(mockDetectors)
p, err := f.CreateResourceProvider(processortest.NewNopSettings(), time.Second, tt.attributes, &mockDetectorConfig{}, tt.keepOrder, mockDetectorTypes...)
p, err := f.CreateResourceProvider(processortest.NewNopSettings(), time.Second, tt.attributes, &mockDetectorConfig{}, tt.order, mockDetectorTypes...)
require.NoError(t, err)

got, _, err := p.Get(context.Background(), http.DefaultClient)
Expand Down

0 comments on commit 33d4edf

Please sign in to comment.