Skip to content

Commit 04327f5

Browse files
[processor/resourcedetection] add resource_attributes to every detector 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]>
1 parent 1a096ad commit 04327f5

File tree

99 files changed

+3256
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+3256
-275
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: enhancement
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: resourcedetectionprocessor
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Adds a way to configure the list of added resource attributes by the processor
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [21482]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext: |
21+
Users can now configure what resource attributes are gathered by specific detectors.
22+
Example configuration:
23+
24+
```
25+
resourcedetection:
26+
detectors: [system, ec2]
27+
system:
28+
resource_attributes:
29+
host.name:
30+
enabled: true
31+
host.id:
32+
enabled: false
33+
ec2:
34+
resource_attributes:
35+
host.name:
36+
enabled: false
37+
host.id:
38+
enabled: true
39+
```
40+
41+
For example, this config makes `host.name` being set by `system` detector, and `host.id` by `ec2` detector.
42+
Moreover:
43+
- Existing behavior remains unaffected as all attributes are currently enabled by default.
44+
- The default attributes 'enabled' values are defined in `metadata.yaml`.
45+
- Future releases will introduce changes to resource_attributes `enabled` values.
46+
- Users can tailor resource detection process to their needs and environment.
47+
48+

processor/resourcedetectionprocessor/README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,57 @@ See: [TLS Configuration Settings](https://github.com/open-telemetry/opentelemetr
454454
detectors: [ <string> ]
455455
# determines if existing resource attributes should be overridden or preserved, defaults to true
456456
override: <bool>
457-
# When included, only attributes in the list will be appened. Applies to all detectors.
457+
# [DEPRECATED] When included, only attributes in the list will be appended. Applies to all detectors.
458458
attributes: [ <string> ]
459459
```
460460

461+
Moreover, you have the ability to specify which detector should collect each attribute with `resource_attributes` option. An example of such a configuration is:
462+
463+
```yaml
464+
resourcedetection:
465+
detectors: [system, ec2]
466+
system:
467+
resource_attributes:
468+
host.name:
469+
enabled: true
470+
host.id:
471+
enabled: false
472+
ec2:
473+
resource_attributes:
474+
host.name:
475+
enabled: false
476+
host.id:
477+
enabled: true
478+
```
479+
480+
### Migration from attributes to resource_attributes
481+
482+
The `attributes` option is deprecated and will be removed soon, from now on you should enable/disable attributes through `resource_attributes`.
483+
For example, this config:
484+
485+
```yaml
486+
resourcedetection:
487+
detectors: [system]
488+
attributes: ['host.name', 'host.id']
489+
```
490+
491+
can be replaced with:
492+
493+
```yaml
494+
resourcedetection:
495+
detectors: [system]
496+
system:
497+
resource_attributes:
498+
host.name:
499+
enabled: true
500+
host.id:
501+
enabled: true
502+
os.type:
503+
enabled: false
504+
```
505+
506+
NOTE: Currently all attributes are enabled by default for backwards compatibility purposes, but it will change in the future.
507+
461508
## Ordering
462509

463510
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.

processor/resourcedetectionprocessor/config.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ import (
88

99
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal"
1010
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ec2"
11+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ecs"
12+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/eks"
13+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/elasticbeanstalk"
14+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/lambda"
15+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/azure"
16+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/azure/aks"
1117
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/consul"
18+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/docker"
19+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/gcp"
20+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/heroku"
1221
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/openshift"
1322
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/system"
1423
)
@@ -28,7 +37,8 @@ type Config struct {
2837
// Timeout default is 5s
2938
confighttp.HTTPClientSettings `mapstructure:",squash"`
3039
// Attributes is an allowlist of attributes to add.
31-
// If a supplied attribute is not a valid atrtibute of a supplied detector it will be ignored.
40+
// If a supplied attribute is not a valid attribute of a supplied detector it will be ignored.
41+
// Deprecated: Please use detector's resource_attributes config instead
3242
Attributes []string `mapstructure:"attributes"`
3343
}
3444

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

50+
// ECSConfig contains user-specified configurations for the ECS detector
51+
ECSConfig ecs.Config `mapstructure:"ecs"`
52+
53+
// EKSConfig contains user-specified configurations for the EKS detector
54+
EKSConfig eks.Config `mapstructure:"eks"`
55+
56+
// Elasticbeanstalk contains user-specified configurations for the elasticbeanstalk detector
57+
ElasticbeanstalkConfig elasticbeanstalk.Config `mapstructure:"elasticbeanstalk"`
58+
59+
// Lambda contains user-specified configurations for the lambda detector
60+
LambdaConfig lambda.Config `mapstructure:"lambda"`
61+
62+
// Azure contains user-specified configurations for the azure detector
63+
AzureConfig azure.Config `mapstructure:"azure"`
64+
65+
// Aks contains user-specified configurations for the aks detector
66+
AksConfig aks.Config `mapstructure:"aks"`
67+
4068
// ConsulConfig contains user-specified configurations for the Consul detector
4169
ConsulConfig consul.Config `mapstructure:"consul"`
4270

71+
// DockerConfig contains user-specified configurations for the docker detector
72+
DockerConfig docker.Config `mapstructure:"docker"`
73+
74+
// GcpConfig contains user-specified configurations for the gcp detector
75+
GcpConfig gcp.Config `mapstructure:"gcp"`
76+
77+
// HerokuConfig contains user-specified configurations for the heroku detector
78+
HerokuConfig heroku.Config `mapstructure:"heroku"`
79+
4380
// SystemConfig contains user-specified configurations for the System detector
4481
SystemConfig system.Config `mapstructure:"system"`
4582

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

87+
func detectorCreateDefaultConfig() DetectorConfig {
88+
return DetectorConfig{
89+
EC2Config: ec2.CreateDefaultConfig(),
90+
ECSConfig: ecs.CreateDefaultConfig(),
91+
EKSConfig: eks.CreateDefaultConfig(),
92+
ElasticbeanstalkConfig: elasticbeanstalk.CreateDefaultConfig(),
93+
LambdaConfig: lambda.CreateDefaultConfig(),
94+
AzureConfig: azure.CreateDefaultConfig(),
95+
AksConfig: aks.CreateDefaultConfig(),
96+
ConsulConfig: consul.CreateDefaultConfig(),
97+
DockerConfig: docker.CreateDefaultConfig(),
98+
GcpConfig: gcp.CreateDefaultConfig(),
99+
HerokuConfig: heroku.CreateDefaultConfig(),
100+
SystemConfig: system.CreateDefaultConfig(),
101+
OpenShiftConfig: openshift.CreateDefaultConfig(),
102+
}
103+
}
104+
50105
func (d *DetectorConfig) GetConfigFromType(detectorType internal.DetectorType) internal.DetectorConfig {
51106
switch detectorType {
52107
case ec2.TypeStr:
53108
return d.EC2Config
109+
case ecs.TypeStr:
110+
return d.ECSConfig
111+
case eks.TypeStr:
112+
return d.EKSConfig
113+
case elasticbeanstalk.TypeStr:
114+
return d.ElasticbeanstalkConfig
115+
case lambda.TypeStr:
116+
return d.LambdaConfig
117+
case azure.TypeStr:
118+
return d.AzureConfig
54119
case consul.TypeStr:
55120
return d.ConsulConfig
121+
case docker.TypeStr:
122+
return d.DockerConfig
123+
case gcp.TypeStr:
124+
return d.GcpConfig
125+
case heroku.TypeStr:
126+
return d.HerokuConfig
56127
case system.TypeStr:
57128
return d.SystemConfig
58129
case openshift.TypeStr:

0 commit comments

Comments
 (0)