Skip to content

Commit

Permalink
[processor/resourcedetection] add resource_attributes to every detect…
Browse files Browse the repository at this point in the history
…or in resource processor (#23253)

**Description:** Adding resource_attributes option to every detector in
resource detection processor
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->

**Link to tracking Issue:**
[21482](#21482)

**Testing:** Unit test for `resource_attribute` config, adjusting
current unit tests to the new implementation

**Documentation:** Updated README.md

---------

Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
omrozowicz-splunk and dmitryax committed Jun 26, 2023
1 parent 1a096ad commit 04327f5
Show file tree
Hide file tree
Showing 99 changed files with 3,256 additions and 275 deletions.
48 changes: 48 additions & 0 deletions .chloggen/resource-detection-processor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds a way to configure the list of added resource attributes by the processor

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [21482]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Users can now configure what resource attributes are gathered by specific detectors.
Example configuration:
```
resourcedetection:
detectors: [system, ec2]
system:
resource_attributes:
host.name:
enabled: true
host.id:
enabled: false
ec2:
resource_attributes:
host.name:
enabled: false
host.id:
enabled: true
```
For example, this config makes `host.name` being set by `system` detector, and `host.id` by `ec2` detector.
Moreover:
- Existing behavior remains unaffected as all attributes are currently enabled by default.
- The default attributes 'enabled' values are defined in `metadata.yaml`.
- Future releases will introduce changes to resource_attributes `enabled` values.
- Users can tailor resource detection process to their needs and environment.
49 changes: 48 additions & 1 deletion processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,57 @@ See: [TLS Configuration Settings](https://github.com/open-telemetry/opentelemetr
detectors: [ <string> ]
# determines if existing resource attributes should be overridden or preserved, defaults to true
override: <bool>
# When included, only attributes in the list will be appened. Applies to all detectors.
# [DEPRECATED] When included, only attributes in the list will be appended. Applies to all detectors.
attributes: [ <string> ]
```

Moreover, you have the ability to specify which detector should collect each attribute with `resource_attributes` option. An example of such a configuration is:

```yaml
resourcedetection:
detectors: [system, ec2]
system:
resource_attributes:
host.name:
enabled: true
host.id:
enabled: false
ec2:
resource_attributes:
host.name:
enabled: false
host.id:
enabled: true
```

### Migration from attributes to resource_attributes

The `attributes` option is deprecated and will be removed soon, from now on you should enable/disable attributes through `resource_attributes`.
For example, this config:

```yaml
resourcedetection:
detectors: [system]
attributes: ['host.name', 'host.id']
```

can be replaced with:

```yaml
resourcedetection:
detectors: [system]
system:
resource_attributes:
host.name:
enabled: true
host.id:
enabled: true
os.type:
enabled: false
```

NOTE: Currently all attributes are enabled by default for backwards compatibility purposes, but it will change in the future.

## Ordering

Note that if multiple detectors are inserting the same attribute name, the first detector to insert wins. For example if you had `detectors: [eks, ec2]` then `cloud.platform` will be `aws_eks` instead of `ec2`. The below ordering is recommended.
Expand Down
73 changes: 72 additions & 1 deletion processor/resourcedetectionprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ec2"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ecs"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/eks"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/elasticbeanstalk"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/lambda"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/azure"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/azure/aks"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/consul"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/docker"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/gcp"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/heroku"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/openshift"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/system"
)
Expand All @@ -28,7 +37,8 @@ type Config struct {
// Timeout default is 5s
confighttp.HTTPClientSettings `mapstructure:",squash"`
// Attributes is an allowlist of attributes to add.
// If a supplied attribute is not a valid atrtibute of a supplied detector it will be ignored.
// 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"`
}

Expand All @@ -37,22 +47,83 @@ type DetectorConfig struct {
// EC2Config contains user-specified configurations for the EC2 detector
EC2Config ec2.Config `mapstructure:"ec2"`

// ECSConfig contains user-specified configurations for the ECS detector
ECSConfig ecs.Config `mapstructure:"ecs"`

// EKSConfig contains user-specified configurations for the EKS detector
EKSConfig eks.Config `mapstructure:"eks"`

// Elasticbeanstalk contains user-specified configurations for the elasticbeanstalk detector
ElasticbeanstalkConfig elasticbeanstalk.Config `mapstructure:"elasticbeanstalk"`

// Lambda contains user-specified configurations for the lambda detector
LambdaConfig lambda.Config `mapstructure:"lambda"`

// Azure contains user-specified configurations for the azure detector
AzureConfig azure.Config `mapstructure:"azure"`

// Aks contains user-specified configurations for the aks detector
AksConfig aks.Config `mapstructure:"aks"`

// ConsulConfig contains user-specified configurations for the Consul detector
ConsulConfig consul.Config `mapstructure:"consul"`

// DockerConfig contains user-specified configurations for the docker detector
DockerConfig docker.Config `mapstructure:"docker"`

// GcpConfig contains user-specified configurations for the gcp detector
GcpConfig gcp.Config `mapstructure:"gcp"`

// HerokuConfig contains user-specified configurations for the heroku detector
HerokuConfig heroku.Config `mapstructure:"heroku"`

// SystemConfig contains user-specified configurations for the System detector
SystemConfig system.Config `mapstructure:"system"`

// OpenShift contains user-specified configurations for the Openshift detector
OpenShiftConfig openshift.Config `mapstructure:"openshift"`
}

func detectorCreateDefaultConfig() DetectorConfig {
return DetectorConfig{
EC2Config: ec2.CreateDefaultConfig(),
ECSConfig: ecs.CreateDefaultConfig(),
EKSConfig: eks.CreateDefaultConfig(),
ElasticbeanstalkConfig: elasticbeanstalk.CreateDefaultConfig(),
LambdaConfig: lambda.CreateDefaultConfig(),
AzureConfig: azure.CreateDefaultConfig(),
AksConfig: aks.CreateDefaultConfig(),
ConsulConfig: consul.CreateDefaultConfig(),
DockerConfig: docker.CreateDefaultConfig(),
GcpConfig: gcp.CreateDefaultConfig(),
HerokuConfig: heroku.CreateDefaultConfig(),
SystemConfig: system.CreateDefaultConfig(),
OpenShiftConfig: openshift.CreateDefaultConfig(),
}
}

func (d *DetectorConfig) GetConfigFromType(detectorType internal.DetectorType) internal.DetectorConfig {
switch detectorType {
case ec2.TypeStr:
return d.EC2Config
case ecs.TypeStr:
return d.ECSConfig
case eks.TypeStr:
return d.EKSConfig
case elasticbeanstalk.TypeStr:
return d.ElasticbeanstalkConfig
case lambda.TypeStr:
return d.LambdaConfig
case azure.TypeStr:
return d.AzureConfig
case consul.TypeStr:
return d.ConsulConfig
case docker.TypeStr:
return d.DockerConfig
case gcp.TypeStr:
return d.GcpConfig
case heroku.TypeStr:
return d.HerokuConfig
case system.TypeStr:
return d.SystemConfig
case openshift.TypeStr:
Expand Down
Loading

0 comments on commit 04327f5

Please sign in to comment.