Skip to content

Commit

Permalink
[processor/resourcedetection] Add support for host cpuinfo attributes (
Browse files Browse the repository at this point in the history
…open-telemetry#26533)

**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


**Testing:** 

### How to test this manually

1. Using the following configuration:
```yml
receivers:
  hostmetrics:
    collection_interval: 30s
    scrapers:
      cpu:

processors:
  resourcedetection/system:
    detectors: ["system"]
    system:
      hostname_sources: ["lookup", "cname", "dns", "os"]
      resource_attributes:
        host.name:
          enabled: true
        host.id:
          enabled: true
        host.cpu.cache.l2.size:
          enabled: true
        host.cpu.family:
          enabled: true
        host.cpu.model.id:
          enabled: true
        host.cpu.model.name:
          enabled: true
        host.cpu.stepping:
          enabled: true
        host.cpu.vendor.id:
          enabled: true

service:
  pipelines:
    metrics:
      receivers: [hostmetrics]
      exporters: [file]
      processors: [resourcedetection/system]

exporters:
  file:
    path: ./output.json
```
2. Start the collector with `./bin/otelcontribcol_linux_amd64 --config
examples/host_config.yaml`
3. The output reports the added attributes succesfully:
```json
  {
    "resourceMetrics":[
      {
        "resource":{
          "attributes":[
            {
              "key":"host.name",
              "value":{
                "stringValue":"chrismark-ThinkPad-X1-Carbon-Gen-9"
              }
            },
            {
              "key":"os.type",
              "value":{
                "stringValue":"linux"
              }
            },
            {
              "key":"host.id",
              "value":{
                "stringValue":"d6488716404e4ce4854ff0e230944c6d"
              }
            },
            {
              "key":"host.cpu.vendor.id",
              "value":{
                "stringValue":"GenuineIntel"
              }
            },
            {
              "key":"host.cpu.family",
              "value":{
                "stringValue":"6"
              }
            },
            {
              "key":"host.cpu.model.id",
              "value":{
                "stringValue":"140"
              }
            },
            {
              "key":"host.cpu.model.name",
              "value":{
                "stringValue":"11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz"
              }
            },
            {
              "key":"host.cpu.stepping",
              "value":{
                "intValue":"1"
              }
            },
            {
              "key":"host.cpu.cache.l2.size",
              "value":{
                "intValue":"12288"
              }
            }
          ]
        },
        "scopeMetrics":[...],
        "schemaUrl":"https://opentelemetry.io/schemas/1.9.0"
      }
    ]
  }
```

### Unit tests
-

**Documentation:** Updated [README.md
](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/26533/files#diff-2fd609a720e95f7ad6fe8c31180f20671dbf62301fba3c9914fcb81a8cc930aa)

Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark committed Sep 18, 2023
1 parent dd24134 commit b6f4597
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 16 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.

# 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: In Linux and Darwin all fields are populated. In Windows only family, vendor.id and model.name are populated.

# 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: []
6 changes: 6 additions & 0 deletions processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Queries the host machine to retrieve the following resource attributes:
* host.arch
* host.name
* host.id
* host.cpu.vendor.id
* host.cpu.family
* host.cpu.model.id
* host.cpu.model.name
* host.cpu.stepping
* host.cpu.cache.l2.size
* os.description
* os.type

Expand Down
8 changes: 8 additions & 0 deletions processor/resourcedetectionprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/hashicorp/consul/api v1.24.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.85.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders v0.85.0
github.com/shirou/gopsutil/v3 v3.23.7
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.85.0
go.opentelemetry.io/collector/config/confighttp v0.85.0
Expand Down Expand Up @@ -44,6 +45,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand All @@ -65,6 +67,7 @@ require (
github.com/klauspost/compress v1.16.7 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
Expand All @@ -80,8 +83,13 @@ require (
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rs/cors v1.10.0 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector v0.85.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.85.0 // indirect
Expand Down
22 changes: 22 additions & 0 deletions processor/resourcedetectionprocessor/go.sum

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.

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

Loading

0 comments on commit b6f4597

Please sign in to comment.