diff --git a/.chloggen/drosiek-host-id.yaml b/.chloggen/drosiek-host-id.yaml new file mode 100755 index 000000000000..e9b5ae312689 --- /dev/null +++ b/.chloggen/drosiek-host-id.yaml @@ -0,0 +1,16 @@ +# 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: resourcedetectionprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: add host.id to system detector + +# One or more tracking issues related to the change +issues: [18533] + +# (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: diff --git a/cmd/configschema/go.mod b/cmd/configschema/go.mod index 69a34e6651e4..cfcd5c1a60cb 100644 --- a/cmd/configschema/go.mod +++ b/cmd/configschema/go.mod @@ -188,6 +188,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowsperfcountersreceiver v0.0.0-00010101000000-000000000000 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.0.0-00010101000000-000000000000 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zookeeperreceiver v0.0.0-00010101000000-000000000000 // indirect + github.com/panta/machineid v1.0.2 // indirect github.com/signalfx/signalfx-agent/pkg/apm v0.0.0-20230214151822-6a6813cf5bf1 // indirect ) diff --git a/cmd/configschema/go.sum b/cmd/configschema/go.sum index 696e734a680c..e84321d2123d 100644 --- a/cmd/configschema/go.sum +++ b/cmd/configschema/go.sum @@ -1981,6 +1981,8 @@ github.com/outcaste-io/ristretto v0.2.0/go.mod h1:iBZA7RCt6jaOr0z6hiBQ6t662/oZ6G github.com/ovh/go-ovh v1.3.0 h1:mvZaddk4E4kLcXhzb+cxBsMPYp2pHqiQpWYkInsuZPQ= github.com/ovh/go-ovh v1.3.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= +github.com/panta/machineid v1.0.2 h1:LVYeEq1hZ+FwcM+/H6eB8KfXM2R5b2h1SWdnWwZ0OQw= +github.com/panta/machineid v1.0.2/go.mod h1:AROj156fsca3R3rNw3q9h8xFkos25W9P0ZG9gu+3Uf0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/cmd/otelcontribcol/go.mod b/cmd/otelcontribcol/go.mod index 46b34ad47244..9a3125269c3f 100644 --- a/cmd/otelcontribcol/go.mod +++ b/cmd/otelcontribcol/go.mod @@ -495,6 +495,7 @@ require ( github.com/openzipkin/zipkin-go v0.4.1 // indirect github.com/outcaste-io/ristretto v0.2.0 // indirect github.com/ovh/go-ovh v1.3.0 // indirect + github.com/panta/machineid v1.0.2 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/paulmach/orb v0.8.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect diff --git a/cmd/otelcontribcol/go.sum b/cmd/otelcontribcol/go.sum index 1953ad6cdcf2..124cc213f351 100644 --- a/cmd/otelcontribcol/go.sum +++ b/cmd/otelcontribcol/go.sum @@ -1907,6 +1907,8 @@ github.com/outcaste-io/ristretto v0.2.0/go.mod h1:iBZA7RCt6jaOr0z6hiBQ6t662/oZ6G github.com/ovh/go-ovh v1.3.0 h1:mvZaddk4E4kLcXhzb+cxBsMPYp2pHqiQpWYkInsuZPQ= github.com/ovh/go-ovh v1.3.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= +github.com/panta/machineid v1.0.2 h1:LVYeEq1hZ+FwcM+/H6eB8KfXM2R5b2h1SWdnWwZ0OQw= +github.com/panta/machineid v1.0.2/go.mod h1:AROj156fsca3R3rNw3q9h8xFkos25W9P0ZG9gu+3Uf0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/exporter/datadogexporter/go.mod b/exporter/datadogexporter/go.mod index b6068bf4a259..57b65f98d4d3 100644 --- a/exporter/datadogexporter/go.mod +++ b/exporter/datadogexporter/go.mod @@ -136,6 +136,7 @@ require ( github.com/openshift/api v0.0.0-20210521075222-e273a339932a // indirect github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // indirect github.com/outcaste-io/ristretto v0.2.0 // indirect + github.com/panta/machineid v1.0.2 // indirect github.com/philhofer/fwd v1.1.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/exporter/datadogexporter/go.sum b/exporter/datadogexporter/go.sum index 6661c2c5fcc9..dfc8c006ac54 100644 --- a/exporter/datadogexporter/go.sum +++ b/exporter/datadogexporter/go.sum @@ -553,6 +553,8 @@ github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 h1:ZHRIMCFIJN1 github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142/go.mod h1:fjS8r9mqDVsPb5td3NehsNOAWa4uiFkYEfVZioQ2gH0= github.com/outcaste-io/ristretto v0.2.0 h1:47w059XTZWFt01OucwjcBt8mEa3VUUhntUWEfmgVBFc= github.com/outcaste-io/ristretto v0.2.0/go.mod h1:iBZA7RCt6jaOr0z6hiBQ6t662/oZ6Gx/yauuPvIWHAI= +github.com/panta/machineid v1.0.2 h1:LVYeEq1hZ+FwcM+/H6eB8KfXM2R5b2h1SWdnWwZ0OQw= +github.com/panta/machineid v1.0.2/go.mod h1:AROj156fsca3R3rNw3q9h8xFkos25W9P0ZG9gu+3Uf0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/go.mod b/go.mod index a08f06ea16a9..a8477e301c30 100644 --- a/go.mod +++ b/go.mod @@ -511,6 +511,7 @@ require ( github.com/openzipkin/zipkin-go v0.4.1 // indirect github.com/outcaste-io/ristretto v0.2.0 // indirect github.com/ovh/go-ovh v1.3.0 // indirect + github.com/panta/machineid v1.0.2 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/paulmach/orb v0.8.0 // indirect github.com/philhofer/fwd v1.1.2 // indirect diff --git a/go.sum b/go.sum index f3ebb91397bb..d48cb14f4d6d 100644 --- a/go.sum +++ b/go.sum @@ -1980,6 +1980,8 @@ github.com/outcaste-io/ristretto v0.2.0/go.mod h1:iBZA7RCt6jaOr0z6hiBQ6t662/oZ6G github.com/ovh/go-ovh v1.3.0 h1:mvZaddk4E4kLcXhzb+cxBsMPYp2pHqiQpWYkInsuZPQ= github.com/ovh/go-ovh v1.3.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= +github.com/panta/machineid v1.0.2 h1:LVYeEq1hZ+FwcM+/H6eB8KfXM2R5b2h1SWdnWwZ0OQw= +github.com/panta/machineid v1.0.2/go.mod h1:AROj156fsca3R3rNw3q9h8xFkos25W9P0ZG9gu+3Uf0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/internal/metadataproviders/go.mod b/internal/metadataproviders/go.mod index 3221b43d098d..afd25ea50765 100644 --- a/internal/metadataproviders/go.mod +++ b/internal/metadataproviders/go.mod @@ -7,6 +7,7 @@ require ( github.com/aws/aws-sdk-go v1.44.201 github.com/docker/docker v23.0.1+incompatible github.com/hashicorp/consul/api v1.18.0 + github.com/panta/machineid v1.0.2 github.com/stretchr/testify v1.8.1 ) diff --git a/internal/metadataproviders/go.sum b/internal/metadataproviders/go.sum index 815c9bda5c4b..80239cd257d4 100644 --- a/internal/metadataproviders/go.sum +++ b/internal/metadataproviders/go.sum @@ -160,6 +160,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/panta/machineid v1.0.2 h1:LVYeEq1hZ+FwcM+/H6eB8KfXM2R5b2h1SWdnWwZ0OQw= +github.com/panta/machineid v1.0.2/go.mod h1:AROj156fsca3R3rNw3q9h8xFkos25W9P0ZG9gu+3Uf0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/internal/metadataproviders/system/metadata.go b/internal/metadataproviders/system/metadata.go index 08cca854041f..387a05052b6c 100644 --- a/internal/metadataproviders/system/metadata.go +++ b/internal/metadataproviders/system/metadata.go @@ -22,6 +22,7 @@ import ( "strings" "github.com/Showmax/go-fqdn" + "github.com/panta/machineid" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/internal" ) @@ -61,6 +62,9 @@ type Provider interface { // ReverseLookupHost does a reverse DNS query on the current host's IP address ReverseLookupHost() (string, error) + + // HostID returns Host Unique Identifier + HostID() (string, error) } type systemMetadataProvider struct { @@ -123,3 +127,7 @@ func (p systemMetadataProvider) reverseLookup(ipAddresses []string) (string, err } return "", fmt.Errorf("reverseLookup failed to convert IP addresses to name: %w", err) } + +func (p systemMetadataProvider) HostID() (string, error) { + return machineid.ID() +} diff --git a/processor/resourcedetectionprocessor/README.md b/processor/resourcedetectionprocessor/README.md index ae365a3c0112..beec34c31b21 100644 --- a/processor/resourcedetectionprocessor/README.md +++ b/processor/resourcedetectionprocessor/README.md @@ -35,6 +35,7 @@ Note: use the Docker detector (see below) if running the Collector as a Docker c Queries the host machine to retrieve the following resource attributes: * host.name + * host.id * os.type By default `host.name` is being set to FQDN if possible, and a hostname provided by OS used as fallback. diff --git a/processor/resourcedetectionprocessor/go.mod b/processor/resourcedetectionprocessor/go.mod index 0d278e85fe38..a46361514d5f 100644 --- a/processor/resourcedetectionprocessor/go.mod +++ b/processor/resourcedetectionprocessor/go.mod @@ -72,6 +72,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.71.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect + github.com/panta/machineid v1.0.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect diff --git a/processor/resourcedetectionprocessor/go.sum b/processor/resourcedetectionprocessor/go.sum index 539faaa9203c..570a161761d4 100644 --- a/processor/resourcedetectionprocessor/go.sum +++ b/processor/resourcedetectionprocessor/go.sum @@ -312,6 +312,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/panta/machineid v1.0.2 h1:LVYeEq1hZ+FwcM+/H6eB8KfXM2R5b2h1SWdnWwZ0OQw= +github.com/panta/machineid v1.0.2/go.mod h1:AROj156fsca3R3rNw3q9h8xFkos25W9P0ZG9gu+3Uf0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/processor/resourcedetectionprocessor/internal/system/system.go b/processor/resourcedetectionprocessor/internal/system/system.go index 04bd284b0c31..c1f64f072f26 100644 --- a/processor/resourcedetectionprocessor/internal/system/system.go +++ b/processor/resourcedetectionprocessor/internal/system/system.go @@ -70,12 +70,19 @@ func (d *Detector) Detect(_ context.Context) (resource pcommon.Resource, schemaU if err != nil { return res, "", fmt.Errorf("failed getting OS type: %w", err) } + + hostID, err := d.provider.HostID() + if err != nil { + return res, "", fmt.Errorf("failed getting host ID: %w", err) + } + for _, source := range d.hostnameSources { getHostFromSource := hostnameSourcesMap[source] hostname, err = getHostFromSource(d) if err == nil { attrs.PutStr(conventions.AttributeHostName, hostname) attrs.PutStr(conventions.AttributeOSType, osType) + attrs.PutStr(conventions.AttributeHostID, hostID) return res, conventions.SchemaURL, nil } diff --git a/processor/resourcedetectionprocessor/internal/system/system_test.go b/processor/resourcedetectionprocessor/internal/system/system_test.go index 3e4779ada2f8..4c96a508c0a7 100644 --- a/processor/resourcedetectionprocessor/internal/system/system_test.go +++ b/processor/resourcedetectionprocessor/internal/system/system_test.go @@ -51,6 +51,11 @@ func (m *mockMetadata) OSType() (string, error) { return args.String(0), args.Error(1) } +func (m *mockMetadata) HostID() (string, error) { + args := m.MethodCalled("HostID") + return args.String(0), args.Error(1) +} + func (m *mockMetadata) LookupCNAME() (string, error) { args := m.MethodCalled("LookupCNAME") return args.String(0), args.Error(1) @@ -92,6 +97,7 @@ func TestDetectFQDNAvailable(t *testing.T) { md := &mockMetadata{} md.On("FQDN").Return("fqdn", nil) md.On("OSType").Return("darwin", nil) + md.On("HostID").Return("2", nil) detector := &Detector{provider: md, logger: zap.NewNop(), hostnameSources: []string{"dns"}} res, schemaURL, err := detector.Detect(context.Background()) @@ -102,6 +108,7 @@ 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()) @@ -113,6 +120,8 @@ 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("OSType").Return("darwin", nil) + mdHostname.On("HostID").Return("3", nil) detector := &Detector{provider: mdHostname, logger: zap.NewNop(), hostnameSources: []string{"dns", "os"}} res, schemaURL, err := detector.Detect(context.Background()) @@ -123,6 +132,7 @@ func TestFallbackHostname(t *testing.T) { expected := map[string]any{ conventions.AttributeHostName: "hostname", conventions.AttributeOSType: "darwin", + conventions.AttributeHostID: "3", } assert.Equal(t, expected, res.Attributes().AsRaw()) @@ -132,6 +142,7 @@ func TestUseHostname(t *testing.T) { mdHostname := &mockMetadata{} mdHostname.On("Hostname").Return("hostname", nil) mdHostname.On("OSType").Return("darwin", nil) + mdHostname.On("HostID").Return("1", nil) detector := &Detector{provider: mdHostname, logger: zap.NewNop(), hostnameSources: []string{"os"}} res, schemaURL, err := detector.Detect(context.Background()) @@ -142,6 +153,7 @@ 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()) @@ -153,6 +165,7 @@ func TestDetectError(t *testing.T) { mdFQDN.On("OSType").Return("windows", nil) mdFQDN.On("FQDN").Return("", errors.New("err")) mdFQDN.On("Hostname").Return("", errors.New("err")) + mdFQDN.On("HostID").Return("", errors.New("err")) detector := &Detector{provider: mdFQDN, logger: zap.NewNop(), hostnameSources: []string{"dns"}} res, schemaURL, err := detector.Detect(context.Background()) @@ -164,6 +177,7 @@ func TestDetectError(t *testing.T) { mdHostname := &mockMetadata{} mdHostname.On("OSType").Return("windows", nil) mdHostname.On("Hostname").Return("", errors.New("err")) + mdHostname.On("HostID").Return("", errors.New("err")) detector = &Detector{provider: mdHostname, logger: zap.NewNop(), hostnameSources: []string{"os"}} res, schemaURL, err = detector.Detect(context.Background()) @@ -175,6 +189,7 @@ func TestDetectError(t *testing.T) { mdOSType := &mockMetadata{} mdOSType.On("FQDN").Return("fqdn", nil) mdOSType.On("OSType").Return("", errors.New("err")) + mdOSType.On("HostID").Return("", errors.New("err")) detector = &Detector{provider: mdOSType, logger: zap.NewNop(), hostnameSources: []string{"dns"}} res, schemaURL, err = detector.Detect(context.Background())