Skip to content

Commit

Permalink
[processor/resourcedetection] Disable host.id on system detector by d…
Browse files Browse the repository at this point in the history
…efault (#24010)

**Description:** 

Disable setting `host.id` by default on the `system` detector.
Users can restore the previous behavior by setting
`system::resource_attributes::host.id::enabled` to `true`.

**Link to tracking Issue:** Fixes #21233

**Testing:** Amended existing tests
  • Loading branch information
mx-psi committed Jul 17, 2023
1 parent 6816bc1 commit be286ca
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
30 changes: 30 additions & 0 deletions .chloggen/mx-psi_system-detector-host-id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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: breaking

# 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: "Disable `host.id` by default on the `system` detector. This restores the behavior prior to v0.72.0 when using the `system` detector together with other detectors that set `host.id`"

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

# (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: |
To re-enable `host.id` on the `system` detector set `system::resource_attributes::host.id::enabled` to `true`:
```
resourcedetection:
detectors: [system]
system:
resource_attributes:
host.id:
enabled: true
```
2 changes: 0 additions & 2 deletions processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,6 @@ resourcedetection:
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ resource_attributes:
host.id:
description: The host.id
type: string
enabled: true
enabled: false
os.type:
description: The os.type
type: string
enabled: true
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func TestDetectFQDNAvailable(t *testing.T) {
expected := map[string]any{
conventions.AttributeHostName: "fqdn",
conventions.AttributeOSType: "darwin",
conventions.AttributeHostID: "2",
}

assert.Equal(t, expected, res.Attributes().AsRaw())
Expand All @@ -110,10 +109,32 @@ func TestFallbackHostname(t *testing.T) {
mdHostname.On("Hostname").Return("hostname", nil)
mdHostname.On("FQDN").Return("", errors.New("err"))
mdHostname.On("OSType").Return("darwin", nil)
mdHostname.On("HostID").Return("3", nil)

resourceAttributes := CreateDefaultConfig().ResourceAttributes
detector := &Detector{provider: mdHostname, logger: zap.NewNop(), hostnameSources: []string{"dns", "os"}, resourceAttributes: resourceAttributes}
res, schemaURL, err := detector.Detect(context.Background())
require.NoError(t, err)
assert.Equal(t, conventions.SchemaURL, schemaURL)
mdHostname.AssertExpectations(t)

expected := map[string]any{
conventions.AttributeHostName: "hostname",
conventions.AttributeOSType: "darwin",
}

assert.Equal(t, expected, res.Attributes().AsRaw())
}

func TestEnableHostID(t *testing.T) {
mdHostname := &mockMetadata{}
mdHostname.On("Hostname").Return("hostname", nil)
mdHostname.On("FQDN").Return("", errors.New("err"))
mdHostname.On("OSType").Return("darwin", nil)
mdHostname.On("HostID").Return("3", nil)

resourceAttributes := CreateDefaultConfig().ResourceAttributes
resourceAttributes.HostID.Enabled = true
detector := &Detector{provider: mdHostname, logger: zap.NewNop(), hostnameSources: []string{"dns", "os"}, resourceAttributes: resourceAttributes}
res, schemaURL, err := detector.Detect(context.Background())
require.NoError(t, err)
Expand Down Expand Up @@ -145,7 +166,6 @@ func TestUseHostname(t *testing.T) {
expected := map[string]any{
conventions.AttributeHostName: "hostname",
conventions.AttributeOSType: "darwin",
conventions.AttributeHostID: "1",
}

assert.Equal(t, expected, res.Attributes().AsRaw())
Expand Down

0 comments on commit be286ca

Please sign in to comment.