Skip to content
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

Part 04 of issue 28679 #17

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c629aa8
Re-enabling 11451 for receivers_test.go
pjanotti Nov 27, 2023
e0f792e
Re-enabling 11451 for exporters_test.go
pjanotti Nov 27, 2023
a837dd9
Increase go test timeout for GROUP cmd
pjanotti Nov 28, 2023
513cad4
Set test timeout to 600s for GROUP cmd on Windows
pjanotti Nov 28, 2023
e3dcf64
Try timeout 1200s for the cmd GROUP
pjanotti Nov 28, 2023
af1f1bc
Changes from `make genotelcontribcol`
pjanotti Nov 28, 2023
b33d275
fix(deps): update all github.com/aws packages (#29546)
renovate[bot] Nov 29, 2023
f67d287
[chore] make genotelcontribcol (#29570)
atoulme Nov 29, 2023
31e6b19
[chore] add Splunk distro to spanmetricsconnector (#29569)
atoulme Nov 29, 2023
fee4517
fix(deps): update module github.com/open-telemetry/opentelemetry-coll…
renovate[bot] Nov 30, 2023
679f121
fix(deps): update all github.com/aws packages (#29575)
renovate[bot] Nov 30, 2023
7aa783a
fix(deps): update module github.com/vmihailenco/msgpack/v4 to v4.3.13…
renovate[bot] Nov 30, 2023
17893fb
fix(deps): update module github.com/sijms/go-ora/v2 to v2.7.23 (#29576)
renovate[bot] Nov 30, 2023
97535ed
chore(deps): update otel/opentelemetry-collector-contrib docker tag t…
renovate[bot] Nov 30, 2023
529fb91
fix(deps): update module github.com/tencentcloud/tencentcloud-sdk-go/…
renovate[bot] Nov 30, 2023
73747ae
[processor/resourcedetection] Graduate `processor.resourcedetection.h…
mx-psi Nov 30, 2023
554dee1
[processor/resourcedetection] Add host.ip addresses detection (#24450)
mx-psi Nov 30, 2023
451e539
[chore][exporter/file] Do not leak temp files during tests (#29554)
pjanotti Nov 30, 2023
a7ef224
[chore][CI/CD] Fix github action for pinging code owners on some comp…
crobert-1 Nov 30, 2023
e1af9da
[chore][receiver/windowseventlog] Expose windowseventlogreceiver conf…
pjanotti Nov 30, 2023
3cf622d
Merge branch 'main' into part-04-of-issue-28679
pjanotti Nov 30, 2023
6a7a201
fix(deps): update module github.com/sap/go-hdb to v1.6.3 (#29590)
renovate[bot] Nov 30, 2023
e7b1307
fix(deps): update module github.com/spf13/cast to v1.6.0 (#29592)
renovate[bot] Nov 30, 2023
16760c7
[extension/opampextension] reports effective config (#29277)
haoqixu Nov 30, 2023
8e5d228
Merge branch 'main' into part-04-of-issue-28679
pjanotti Nov 30, 2023
95a77c1
[pkg/ottl] Add ConditionSequence struct (#29339)
TylerHelmuth Nov 30, 2023
9db03ec
[chore][extension/observer/k8sobserver] try to fix flaky test (DATA R…
sakulali Dec 1, 2023
4d6de7b
Merge branch 'main' into part-04-of-issue-28679
pjanotti Dec 1, 2023
4756047
[chore] [exporter/prometheusremotewrite] Do not repeat marshal proto …
philchia Dec 1, 2023
f369f60
[pkg/ottl] Rename Statements to StatementSequence (#29598)
TylerHelmuth Dec 1, 2023
d41e7dc
Merge branch 'main' into part-04-of-issue-28679
pjanotti Dec 1, 2023
03ad502
[pkg/stanza] Fix flaky TestDeleteAfterRead_SkipPartials (#29597)
djaglowski Dec 1, 2023
d7b940b
[pkg/ottl] Move types to config.go (#29596)
TylerHelmuth Dec 1, 2023
a39fd06
Merge branch 'main' into part-04-of-issue-28679
pjanotti Dec 1, 2023
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
Prev Previous commit
Next Next commit
[processor/resourcedetection] Add host.ip addresses detection (open-t…
…elemetry#24450)

**Description:** 

Adds detection for `host.ip`.

Relates to open-telemetry/semantic-conventions/pull/203

Fixes open-telemetry#24765
  • Loading branch information
mx-psi authored Nov 30, 2023
commit 554dee1c2a59997979088910fb83d01de2d9535e
20 changes: 20 additions & 0 deletions .chloggen/mx-psi_host.ip-ref-impl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# 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 detection of host.ip 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: [24450]

# (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:
37 changes: 37 additions & 0 deletions internal/metadataproviders/system/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type Provider interface {

// HostArch returns the host architecture
HostArch() (string, error)

// HostIPs returns the host's IP interfaces
HostIPs() ([]net.IP, error)
}

type systemMetadataProvider struct {
Expand Down Expand Up @@ -159,3 +162,37 @@ func (p systemMetadataProvider) OSDescription(ctx context.Context) (string, erro
func (systemMetadataProvider) HostArch() (string, error) {
return internal.GOARCHtoHostArch(runtime.GOARCH), nil
}

func (p systemMetadataProvider) HostIPs() (ips []net.IP, err error) {
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
}

for _, iface := range ifaces {
// skip if the interface is down or is a loopback interface
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
continue
}

addrs, errAddr := iface.Addrs()
if errAddr != nil {
return nil, fmt.Errorf("failed to get addresses for interface %v: %w", iface, errAddr)
}
for _, addr := range addrs {
ip, _, parseErr := net.ParseCIDR(addr.String())
if parseErr != nil {
return nil, fmt.Errorf("failed to parse address %q from interface %v: %w", addr, iface, parseErr)
}

if ip.IsLoopback() {
// skip loopback IPs
continue
}

ips = append(ips, ip)
}

}
return ips, err
}
1 change: 1 addition & 0 deletions processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Queries the host machine to retrieve the following resource attributes:
* host.arch
* host.name
* host.id
* host.ip
* host.cpu.vendor.id
* host.cpu.family
* host.cpu.model.id
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.ip:
enabled: true
host.name:
enabled: true
os.description:
Expand All @@ -41,6 +43,8 @@ none_set:
enabled: false
host.id:
enabled: false
host.ip:
enabled: false
host.name:
enabled: false
os.description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ resource_attributes:
description: The host.arch
type: string
enabled: false
host.ip:
description: IP addresses 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 @@ -83,6 +83,17 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
return pcommon.NewResource(), "", fmt.Errorf("failed getting host architecture: %w", err)
}

var hostIPAttribute []any
if d.cfg.ResourceAttributes.HostIP.Enabled {
hostIPs, errIPs := d.provider.HostIPs()
if errIPs != nil {
return pcommon.NewResource(), "", fmt.Errorf("failed getting host IP addresses: %w", errIPs)
}
for _, ip := range hostIPs {
hostIPAttribute = append(hostIPAttribute, ip.String())
}
}

osDescription, err := d.provider.OSDescription(ctx)
if err != nil {
return pcommon.NewResource(), "", fmt.Errorf("failed getting OS description: %w", err)
Expand All @@ -107,6 +118,7 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
}
}
d.rb.SetHostArch(hostArch)
d.rb.SetHostIP(hostIPAttribute)
d.rb.SetOsDescription(osDescription)
if len(cpuInfo) > 0 {
err = setHostCPUInfo(d, cpuInfo[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package system
import (
"context"
"errors"
"net"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -66,6 +67,16 @@ func (m *mockMetadata) ReverseLookupHost() (string, error) {
return args.String(0), args.Error(1)
}

func (m *mockMetadata) HostIPs() ([]net.IP, error) {
args := m.MethodCalled("HostIPs")
return args.Get(0).([]net.IP), args.Error(1)
}

var (
testIPsAttribute = []any{"192.168.1.140", "fe80::abc2:4a28:737a:609e"}
testIPsAddresses = []net.IP{net.ParseIP(testIPsAttribute[0].(string)), net.ParseIP(testIPsAttribute[1].(string))}
)

func TestNewDetector(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -97,6 +108,7 @@ func allEnabledConfig() metadata.ResourceAttributesConfig {
cfg := metadata.DefaultResourceAttributesConfig()
cfg.HostArch.Enabled = true
cfg.HostID.Enabled = true
cfg.HostIP.Enabled = true
cfg.OsDescription.Enabled = true
return cfg
}
Expand All @@ -108,6 +120,7 @@ func TestDetectFQDNAvailable(t *testing.T) {
md.On("OSType").Return("darwin", nil)
md.On("HostID").Return("2", nil)
md.On("HostArch").Return("amd64", nil)
md.On("HostIPs").Return(testIPsAddresses, nil)

detector := newTestDetector(md, []string{"dns"}, allEnabledConfig())
res, schemaURL, err := detector.Detect(context.Background())
Expand All @@ -121,6 +134,7 @@ func TestDetectFQDNAvailable(t *testing.T) {
conventions.AttributeOSType: "darwin",
conventions.AttributeHostID: "2",
conventions.AttributeHostArch: conventions.AttributeHostArchAMD64,
"host.ip": testIPsAttribute,
}

assert.Equal(t, expected, res.Attributes().AsRaw())
Expand All @@ -141,6 +155,7 @@ func TestFallbackHostname(t *testing.T) {
assert.Equal(t, conventions.SchemaURL, schemaURL)
mdHostname.AssertExpectations(t)
mdHostname.AssertNotCalled(t, "HostID")
mdHostname.AssertNotCalled(t, "HostIPs")

expected := map[string]any{
conventions.AttributeHostName: "hostname",
Expand All @@ -158,6 +173,7 @@ func TestEnableHostID(t *testing.T) {
mdHostname.On("OSType").Return("darwin", nil)
mdHostname.On("HostID").Return("3", nil)
mdHostname.On("HostArch").Return("amd64", nil)
mdHostname.On("HostIPs").Return(testIPsAddresses, nil)

detector := newTestDetector(mdHostname, []string{"dns", "os"}, allEnabledConfig())
res, schemaURL, err := detector.Detect(context.Background())
Expand All @@ -171,6 +187,7 @@ func TestEnableHostID(t *testing.T) {
conventions.AttributeOSType: "darwin",
conventions.AttributeHostID: "3",
conventions.AttributeHostArch: conventions.AttributeHostArchAMD64,
"host.ip": testIPsAttribute,
}

assert.Equal(t, expected, res.Attributes().AsRaw())
Expand All @@ -183,6 +200,7 @@ func TestUseHostname(t *testing.T) {
mdHostname.On("OSType").Return("darwin", nil)
mdHostname.On("HostID").Return("1", nil)
mdHostname.On("HostArch").Return("amd64", nil)
mdHostname.On("HostIPs").Return(testIPsAddresses, nil)

detector := newTestDetector(mdHostname, []string{"os"}, allEnabledConfig())
res, schemaURL, err := detector.Detect(context.Background())
Expand All @@ -196,6 +214,7 @@ func TestUseHostname(t *testing.T) {
conventions.AttributeOSType: "darwin",
conventions.AttributeHostID: "1",
conventions.AttributeHostArch: conventions.AttributeHostArchAMD64,
"host.ip": testIPsAttribute,
}

assert.Equal(t, expected, res.Attributes().AsRaw())
Expand All @@ -210,6 +229,7 @@ func TestDetectError(t *testing.T) {
mdFQDN.On("Hostname").Return("", errors.New("err"))
mdFQDN.On("HostID").Return("", errors.New("err"))
mdFQDN.On("HostArch").Return("amd64", nil)
mdFQDN.On("HostIPs").Return(testIPsAddresses, nil)

detector := newTestDetector(mdFQDN, []string{"dns"}, allEnabledConfig())
res, schemaURL, err := detector.Detect(context.Background())
Expand All @@ -224,6 +244,7 @@ func TestDetectError(t *testing.T) {
mdHostname.On("Hostname").Return("", errors.New("err"))
mdHostname.On("HostID").Return("", errors.New("err"))
mdHostname.On("HostArch").Return("amd64", nil)
mdHostname.On("HostIPs").Return(testIPsAddresses, nil)

detector = newTestDetector(mdHostname, []string{"os"}, allEnabledConfig())
res, schemaURL, err = detector.Detect(context.Background())
Expand All @@ -238,6 +259,7 @@ func TestDetectError(t *testing.T) {
mdOSType.On("OSType").Return("", errors.New("err"))
mdOSType.On("HostID").Return("1", nil)
mdOSType.On("HostArch").Return("amd64", nil)
mdOSType.On("HostIPs").Return(testIPsAddresses, nil)

detector = newTestDetector(mdOSType, []string{"os"}, allEnabledConfig())
res, schemaURL, err = detector.Detect(context.Background())
Expand All @@ -252,6 +274,7 @@ func TestDetectError(t *testing.T) {
mdHostID.On("OSType").Return("linux", nil)
mdHostID.On("HostID").Return("", errors.New("err"))
mdHostID.On("HostArch").Return("arm64", nil)
mdHostID.On("HostIPs").Return(testIPsAddresses, nil)

detector = newTestDetector(mdHostID, []string{"os"}, allEnabledConfig())
res, schemaURL, err = detector.Detect(context.Background())
Expand All @@ -262,6 +285,7 @@ func TestDetectError(t *testing.T) {
conventions.AttributeOSDescription: "Ubuntu 22.04.2 LTS (Jammy Jellyfish)",
conventions.AttributeOSType: "linux",
conventions.AttributeHostArch: conventions.AttributeHostArchARM64,
"host.ip": testIPsAttribute,
}, res.Attributes().AsRaw())
}

Expand Down