Skip to content

Commit a07a4cc

Browse files
sumo-drosiekCaleb-Hurshman
authored andcommitted
resourcedetectionprocessor: use opentelemetry-go for host id detection (open-telemetry#18740)
* resourcedetectionprocessor: use gopsutil for host id detection Signed-off-by: Dominik Rosiek <[email protected]> * feat: use opentelemetry sdk Signed-off-by: Dominik Rosiek <[email protected]> --------- Signed-off-by: Dominik Rosiek <[email protected]>
1 parent 5ae8302 commit a07a4cc

File tree

16 files changed

+71
-30
lines changed

16 files changed

+71
-30
lines changed

.chloggen/drosiek-host-id-2.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: resourcedetectionprocessor
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "use opentelemetry-go library for `host.id` detection in the `system` detector"
9+
10+
# One or more tracking issues related to the change
11+
issues: [18533]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

cmd/configschema/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ require (
199199
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowsperfcountersreceiver v0.79.0 // indirect
200200
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.79.0 // indirect
201201
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zookeeperreceiver v0.79.0 // indirect
202-
github.com/panta/machineid v1.0.2 // indirect
203202
github.com/samber/lo v1.37.0 // indirect
204203
github.com/shoenig/go-m1cpu v0.1.6 // indirect
205204
github.com/signalfx/signalfx-agent/pkg/apm v0.0.0-20230214151822-6a6813cf5bf1 // indirect

cmd/configschema/go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/otelcontribcol/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ require (
539539
github.com/openzipkin/zipkin-go v0.4.1 // indirect
540540
github.com/outcaste-io/ristretto v0.2.1 // indirect
541541
github.com/ovh/go-ovh v1.3.0 // indirect
542-
github.com/panta/machineid v1.0.2 // indirect
543542
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
544543
github.com/paulmach/orb v0.9.0 // indirect
545544
github.com/pelletier/go-toml v1.9.5 // indirect

cmd/otelcontribcol/go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/datadogexporter/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ require (
139139
github.com/openshift/api v3.9.0+incompatible // indirect
140140
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // indirect
141141
github.com/outcaste-io/ristretto v0.2.1 // indirect
142-
github.com/panta/machineid v1.0.2 // indirect
143142
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
144143
github.com/philhofer/fwd v1.1.2 // indirect
145144
github.com/pkg/errors v0.9.1 // indirect

exporter/datadogexporter/go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ require (
523523
github.com/openzipkin/zipkin-go v0.4.1 // indirect
524524
github.com/outcaste-io/ristretto v0.2.1 // indirect
525525
github.com/ovh/go-ovh v1.3.0 // indirect
526-
github.com/panta/machineid v1.0.2 // indirect
527526
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
528527
github.com/paulmach/orb v0.9.0 // indirect
529528
github.com/philhofer/fwd v1.1.2 // indirect

go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/metadataproviders/go.mod

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ require (
77
github.com/aws/aws-sdk-go v1.44.277
88
github.com/docker/docker v24.0.2+incompatible
99
github.com/hashicorp/consul/api v1.21.0
10-
github.com/panta/machineid v1.0.2
1110
github.com/stretchr/testify v1.8.4
11+
go.opentelemetry.io/collector/semconv v0.79.0
12+
go.opentelemetry.io/otel/sdk v1.16.0
1213
)
1314

1415
require (
@@ -19,6 +20,8 @@ require (
1920
github.com/docker/go-connections v0.4.0 // indirect
2021
github.com/docker/go-units v0.4.0 // indirect
2122
github.com/fatih/color v1.13.0 // indirect
23+
github.com/go-logr/logr v1.2.4 // indirect
24+
github.com/go-logr/stdr v1.2.2 // indirect
2225
github.com/gogo/protobuf v1.3.2 // indirect
2326
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
2427
github.com/hashicorp/go-hclog v1.5.0 // indirect
@@ -38,6 +41,9 @@ require (
3841
github.com/pkg/errors v0.9.1 // indirect
3942
github.com/pmezard/go-difflib v1.0.0 // indirect
4043
github.com/stretchr/objx v0.5.0 // indirect
44+
go.opentelemetry.io/otel v1.16.0 // indirect
45+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
46+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
4147
golang.org/x/net v0.10.0 // indirect
4248
golang.org/x/sys v0.8.0 // indirect
4349
golang.org/x/time v0.3.0 // indirect

internal/metadataproviders/go.sum

+20-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/metadataproviders/system/metadata.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
package system // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/system"
55

66
import (
7+
"context"
78
"fmt"
89
"net"
910
"os"
1011
"runtime"
1112
"strings"
1213

1314
"github.com/Showmax/go-fqdn"
14-
"github.com/panta/machineid"
15+
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
16+
"go.opentelemetry.io/otel/sdk/resource"
1517

1618
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/internal"
1719
)
@@ -53,7 +55,7 @@ type Provider interface {
5355
ReverseLookupHost() (string, error)
5456

5557
// HostID returns Host Unique Identifier
56-
HostID() (string, error)
58+
HostID(ctx context.Context) (string, error)
5759
}
5860

5961
type systemMetadataProvider struct {
@@ -117,6 +119,22 @@ func (p systemMetadataProvider) reverseLookup(ipAddresses []string) (string, err
117119
return "", fmt.Errorf("reverseLookup failed to convert IP addresses to name: %w", err)
118120
}
119121

120-
func (p systemMetadataProvider) HostID() (string, error) {
121-
return machineid.ID()
122+
func (p systemMetadataProvider) HostID(ctx context.Context) (string, error) {
123+
res, err := resource.New(ctx,
124+
resource.WithHostID(),
125+
)
126+
127+
if err != nil {
128+
return "", fmt.Errorf("failed to obtain host id: %w", err)
129+
}
130+
131+
iter := res.Iter()
132+
133+
for iter.Next() {
134+
if iter.Attribute().Key == conventions.AttributeHostID {
135+
return iter.Attribute().Value.Emit(), nil
136+
}
137+
}
138+
139+
return "", fmt.Errorf("failed to obtain host id")
122140
}

processor/resourcedetectionprocessor/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ require (
7474
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.79.0 // indirect
7575
github.com/opencontainers/go-digest v1.0.0 // indirect
7676
github.com/opencontainers/image-spec v1.0.2 // indirect
77-
github.com/panta/machineid v1.0.2 // indirect
7877
github.com/pkg/errors v0.9.1 // indirect
7978
github.com/pmezard/go-difflib v1.0.0 // indirect
8079
github.com/rs/cors v1.9.0 // indirect
@@ -84,6 +83,7 @@ require (
8483
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect
8584
go.opentelemetry.io/otel v1.16.0 // indirect
8685
go.opentelemetry.io/otel/metric v1.16.0 // indirect
86+
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
8787
go.opentelemetry.io/otel/trace v1.16.0 // indirect
8888
go.uber.org/atomic v1.10.0 // indirect
8989
golang.org/x/net v0.10.0 // indirect

processor/resourcedetectionprocessor/go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/system/system.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewDetector(p processor.CreateSettings, dcfg internal.DetectorConfig) (inte
4949
}
5050

5151
// Detect detects system metadata and returns a resource with the available ones
52-
func (d *Detector) Detect(_ context.Context) (resource pcommon.Resource, schemaURL string, err error) {
52+
func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schemaURL string, err error) {
5353
var hostname string
5454

5555
res := pcommon.NewResource()
@@ -60,7 +60,7 @@ func (d *Detector) Detect(_ context.Context) (resource pcommon.Resource, schemaU
6060
return res, "", fmt.Errorf("failed getting OS type: %w", err)
6161
}
6262

63-
hostID, err := d.provider.HostID()
63+
hostID, err := d.provider.HostID(ctx)
6464
if err != nil {
6565
return res, "", fmt.Errorf("failed getting host ID: %w", err)
6666
}

processor/resourcedetectionprocessor/internal/system/system_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m *mockMetadata) OSType() (string, error) {
4040
return args.String(0), args.Error(1)
4141
}
4242

43-
func (m *mockMetadata) HostID() (string, error) {
43+
func (m *mockMetadata) HostID(_ context.Context) (string, error) {
4444
args := m.MethodCalled("HostID")
4545
return args.String(0), args.Error(1)
4646
}

0 commit comments

Comments
 (0)