Skip to content

[processor/resourcedetection] add host.interface resource attribute to system detector #39472

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

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
27 changes: 27 additions & 0 deletions .chloggen/njain-interface-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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: processor/resourcedetection

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: add `host.interface` resource attribute to `system` detector

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

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
8 changes: 7 additions & 1 deletion internal/metadataproviders/system/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ type Provider interface {

// CPUInfo returns the host's CPU info
CPUInfo(ctx context.Context) ([]cpu.InfoStat, error)

// OSName returns the OS name according to semantic conventions.
OSName(ctx context.Context) (string, error)

// OSBuildID returns the OS build ID according to semantic conventions.
OSBuildID(ctx context.Context) (string, error)

// HostInterfaces returns the host's Interfaces info
HostInterfaces() ([]net.Interface, error)
}

type systemMetadataProvider struct {
Expand Down Expand Up @@ -322,3 +324,7 @@ func (p systemMetadataProvider) HostMACs() (macs []net.HardwareAddr, err error)
func (p systemMetadataProvider) CPUInfo(ctx context.Context) ([]cpu.InfoStat, error) {
return cpu.InfoWithContext(ctx)
}

func (p systemMetadataProvider) HostInterfaces() ([]net.Interface, error) {
return net.Interfaces()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| host.cpu.stepping | The host.cpu.stepping | Any Str | false |
| host.cpu.vendor.id | The host.cpu.vendor.id | Any Str | false |
| host.id | The host.id | Any Str | false |
| host.interface | Network interfaces for the host | Any Slice | false |
| host.ip | IP addresses for the host | Any Slice | false |
| host.mac | MAC addresses for the host | Any Slice | false |
| host.name | The host.name | Any Str | true |
Expand Down

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

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

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

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 @@ -17,6 +17,8 @@ all_set:
enabled: true
host.id:
enabled: true
host.interface:
enabled: true
host.ip:
enabled: true
host.mac:
Expand Down Expand Up @@ -51,6 +53,8 @@ none_set:
enabled: false
host.id:
enabled: false
host.interface:
enabled: false
host.ip:
enabled: false
host.mac:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ resource_attributes:
description: MAC addresses for the host
type: slice
enabled: false
host.interface:
description: Network interfaces for the host
type: slice
enabled: false
host.cpu.vendor.id:
description: The host.cpu.vendor.id
type: string
Expand Down
12 changes: 12 additions & 0 deletions processor/resourcedetectionprocessor/internal/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
}
}

var hostInterfaceAttribute []any
if d.cfg.ResourceAttributes.HostInterface.Enabled {
interfaces, errInterfaces := d.provider.HostInterfaces()
if errInterfaces != nil {
return pcommon.NewResource(), "", fmt.Errorf("failed to get host network interfaces: %w", errInterfaces)
}
for _, iface := range interfaces {
hostInterfaceAttribute = append(hostInterfaceAttribute, iface.Name)
}
}

osDescription, err := d.provider.OSDescription(ctx)
if err != nil {
return pcommon.NewResource(), "", fmt.Errorf("failed getting OS description: %w", err)
Expand Down Expand Up @@ -152,6 +163,7 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
d.rb.SetHostArch(hostArch)
d.rb.SetHostIP(hostIPAttribute)
d.rb.SetHostMac(hostMACAttribute)
d.rb.SetHostInterface(hostInterfaceAttribute)
d.rb.SetOsDescription(osDescription)
if d.cfg.ResourceAttributes.OsName.Enabled {
if osName, err2 := d.provider.OSName(ctx); err2 == nil {
Expand Down
Loading