Skip to content

Commit

Permalink
[processor/resourcedetection] Add support for host cpuinfo attributes
Browse files Browse the repository at this point in the history
**Description:** : Added support for host's cpuinfo attributes
                   as part of the system resourcedetection. This information
		   is retrieved from /proc/cpuinfo.

**Link to tracking Issue:** open-telemetry#26532

Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark committed Sep 8, 2023
1 parent 175bb59 commit fc7a0e0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .chloggen/add_host_cpuinfo.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: Added support for host's cpuinfo attributes. This information is retrieved from /proc/cpuinfo.

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

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

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 @@ -8,6 +8,7 @@ import (
"errors"
"fmt"

"github.com/shirou/gopsutil/v3/cpu"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/processor"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
Expand Down Expand Up @@ -74,6 +75,11 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
return pcommon.NewResource(), "", fmt.Errorf("failed getting OS description: %w", err)
}

cpuInfo, err := cpu.Info()
if err != nil {
return pcommon.NewResource(), "", fmt.Errorf("failed getting host cpuinfo: %w", err)
}

for _, source := range d.cfg.HostnameSources {
getHostFromSource := hostnameSourcesMap[source]
hostname, err = getHostFromSource(d)
Expand All @@ -89,6 +95,9 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
}
d.rb.SetHostArch(hostArch)
d.rb.SetOsDescription(osDescription)
if len(cpuInfo) > 0 {
d.rb.SetHostCPUInfo(cpuInfo[0])
}
return d.rb.Emit(), conventions.SchemaURL, nil
}
d.logger.Debug(err.Error())
Expand Down

0 comments on commit fc7a0e0

Please sign in to comment.