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

chore: [receiver/hostmetrics] Fix integration tests #36847

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
32 changes: 15 additions & 17 deletions receiver/hostmetricsreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
)

func Test_ProcessScrape(t *testing.T) {
t.Skip("TODO: Skipping for now due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32536")

expectedFile := filepath.Join("testdata", "e2e", "expected_process.yaml")
cmd := exec.Command("/bin/sleep", "300")
require.NoError(t, cmd.Start())
Expand All @@ -38,6 +36,7 @@ func Test_ProcessScrape(t *testing.T) {
rCfg := cfg.(*Config)
rCfg.CollectionInterval = time.Second
pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
pCfg.MuteProcessExeError = true
pCfg.Include = processscraper.MatchConfig{
Config: filterset.Config{MatchType: filterset.Regexp},
Names: []string{"sleep"},
Expand All @@ -48,6 +47,9 @@ func Test_ProcessScrape(t *testing.T) {
}),
scraperinttest.WithExpectedFile(expectedFile),
scraperinttest.WithCompareOptions(
pmetrictest.IgnoreResourceAttributeValue("process.owner"),
pmetrictest.IgnoreResourceAttributeValue("process.parent_pid"),
pmetrictest.IgnoreResourceAttributeValue("process.pid"),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricDataPointsOrder(),
Expand All @@ -58,25 +60,22 @@ func Test_ProcessScrape(t *testing.T) {
}

func Test_ProcessScrapeWithCustomRootPath(t *testing.T) {
t.Skip("TODO: Skipping for now due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32536")

expectedFile := filepath.Join("testdata", "e2e", "expected_process_separate_proc.yaml")

scraperinttest.NewIntegrationTest(
NewFactory(),
scraperinttest.WithCustomConfig(
func(_ *testing.T, cfg component.Config, _ *scraperinttest.ContainerInfo) {
rootPath := filepath.Join("testdata", "e2e")
rCfg := cfg.(*Config)
rCfg.CollectionInterval = time.Second
rCfg.RootPath = rootPath
pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
pCfg.Include = processscraper.MatchConfig{
Config: filterset.Config{MatchType: filterset.Regexp},
Names: []string{"sleep"},
}
pCfg.SetRootPath(rootPath)
pCfg.SetEnvMap(setGoPsutilEnvVars(rootPath, &osEnv{}))
rCfg.Scrapers = map[string]internal.Config{
"process": pCfg,
}
rCfg.RootPath = filepath.Join("testdata", "e2e")
}),
scraperinttest.WithExpectedFile(expectedFile),
scraperinttest.WithCompareOptions(
Expand All @@ -90,25 +89,24 @@ func Test_ProcessScrapeWithCustomRootPath(t *testing.T) {
}

func Test_ProcessScrapeWithBadRootPathAndEnvVar(t *testing.T) {
t.Skip("TODO: Skipping for now due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32536")

rootPath := filepath.Join("testdata", "e2e", "proc")
badRootPath := filepath.Join("testdata", "NOT A VALID FOLDER")
expectedFile := filepath.Join("testdata", "e2e", "expected_process_separate_proc.yaml")
t.Setenv("HOST_PROC", filepath.Join("testdata", "e2e", "proc"))

t.Setenv("HOST_PROC", rootPath)
scraperinttest.NewIntegrationTest(
NewFactory(),
scraperinttest.WithCustomConfig(
func(_ *testing.T, cfg component.Config, _ *scraperinttest.ContainerInfo) {
rCfg := cfg.(*Config)
rCfg.CollectionInterval = time.Second
pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
pCfg.Include = processscraper.MatchConfig{
Config: filterset.Config{MatchType: filterset.Regexp},
Names: []string{"sleep"},
}
pCfg.SetRootPath(badRootPath)
pCfg.SetEnvMap(setGoPsutilEnvVars(badRootPath, &osEnv{}))
rCfg.Scrapers = map[string]internal.Config{
"process": pCfg,
}
rCfg.RootPath = filepath.Join("testdata", "NOT A VALID FOLDER")
rCfg.RootPath = badRootPath
}),
scraperinttest.WithExpectedFile(expectedFile),
scraperinttest.WithCompareOptions(
Expand Down
90 changes: 18 additions & 72 deletions receiver/hostmetricsreceiver/testdata/e2e/expected_process.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resourceMetrics:
attributes:
- key: process.command
value:
stringValue: /bin/sleep 300
stringValue: /bin/sleep
- key: process.command_line
value:
stringValue: /bin/sleep 300
Expand All @@ -12,16 +12,16 @@ resourceMetrics:
stringValue: sleep
- key: process.executable.path
value:
stringValue: /bin/sleep
stringValue: /usr/bin/sleep
- key: process.owner
value:
stringValue: atoulme
stringValue: neck
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're ignoring these attributes now anyway maybe these can be removed? Or does the integration test framework expect them in some way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, the test framework actually removes them, so let's remove them as well 3b5936a

- key: process.parent_pid
value:
intValue: "95040"
intValue: "137141"
- key: process.pid
value:
intValue: "95041"
intValue: "137154"
schemaUrl: https://opentelemetry.io/schemas/1.9.0
scopeMetrics:
- metrics:
Expand All @@ -30,14 +30,14 @@ resourceMetrics:
sum:
aggregationTemporality: 2
dataPoints:
- asDouble: 0.0012836666666666665
- asDouble: 0
attributes:
- key: state
value:
stringValue: system
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 0.00037095833333333333
- asDouble: 0
attributes:
- key: state
value:
Expand All @@ -53,87 +53,33 @@ resourceMetrics:
timeUnixNano: "2000000"
isMonotonic: true
unit: s
- description: The amount of physical memory in use.
name: process.memory.usage
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "1064960"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
unit: By
- description: Virtual memory size.
name: process.memory.virtual
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "418299674624"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
unit: By
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper
version: latest
- resource:
attributes:
- key: process.command
value:
stringValue: sleep 31536000
- key: process.command_line
value:
stringValue: sleep 31536000
- key: process.executable.name
value:
stringValue: sleep
- key: process.executable.path
value:
stringValue: sleep
- key: process.owner
value:
stringValue: atoulme
- key: process.parent_pid
value:
intValue: "4654"
- key: process.pid
value:
intValue: "4668"
schemaUrl: https://opentelemetry.io/schemas/1.9.0
scopeMetrics:
- metrics:
- description: Total CPU seconds broken down by different states.
name: process.cpu.time
- description: Disk bytes transferred.
name: process.disk.io
sum:
aggregationTemporality: 2
dataPoints:
- asDouble: 0.0030173333333333332
- asInt: "7090"
attributes:
- key: state
- key: direction
value:
stringValue: system
stringValue: read
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 0.0006898333333333332
- asInt: "0"
attributes:
- key: state
- key: direction
value:
stringValue: user
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 0
attributes:
- key: state
value:
stringValue: wait
stringValue: write
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
unit: s
unit: By
- description: The amount of physical memory in use.
name: process.memory.usage
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "311296"
- asInt: "5873664"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
unit: By
Expand All @@ -142,7 +88,7 @@ resourceMetrics:
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "418299674624"
- asInt: "8265728"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
unit: By
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
resourceMetrics:
- resource:
attributes:
- key: process.command
- key: process.pid
value:
stringValue: sleep 31536000
- key: process.command_line
intValue: "1"
- key: process.parent_pid
value:
stringValue: sleep 31536000
intValue: "0"
- key: process.executable.name
value:
stringValue: sleep
stringValue: ""
- key: process.executable.path
value:
stringValue: sleep
- key: process.owner
value:
stringValue: atoulme
- key: process.parent_pid
stringValue: testdata/e2e/bin/bash
- key: process.command
value:
intValue: "4654"
- key: process.pid
stringValue: /bin/bash
- key: process.command_line
value:
intValue: "4668"
stringValue: /bin/bash
schemaUrl: https://opentelemetry.io/schemas/1.9.0
scopeMetrics:
- metrics:
Expand All @@ -30,46 +27,46 @@ resourceMetrics:
sum:
aggregationTemporality: 2
dataPoints:
- asDouble: 0.0030173333333333332
- asDouble: 0
attributes:
- key: state
value:
stringValue: system
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 0.0006898333333333332
stringValue: user
startTimeUnixNano: "1693963661860000000"
timeUnixNano: "1734347455586234971"
- asDouble: 0
attributes:
- key: state
value:
stringValue: user
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
stringValue: system
startTimeUnixNano: "1693963661860000000"
timeUnixNano: "1734347455586234971"
- asDouble: 0
attributes:
- key: state
value:
stringValue: wait
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
startTimeUnixNano: "1693963661860000000"
timeUnixNano: "1734347455586234971"
isMonotonic: true
unit: s
- description: The amount of physical memory in use.
name: process.memory.usage
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "311296"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asInt: "2322432"
startTimeUnixNano: "1693963661860000000"
timeUnixNano: "1734347455586234971"
unit: By
- description: Virtual memory size.
name: process.memory.virtual
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "418299674624"
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asInt: "5054464"
startTimeUnixNano: "1693963661860000000"
timeUnixNano: "1734347455586234971"
unit: By
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper
Expand Down
1 change: 1 addition & 0 deletions receiver/hostmetricsreceiver/testdata/e2e/proc/1/cgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0::/
1 change: 1 addition & 0 deletions receiver/hostmetricsreceiver/testdata/e2e/proc/1/exe
1 change: 1 addition & 0 deletions receiver/hostmetricsreceiver/testdata/e2e/proc/1/statm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234 567 89 10 11 12 13
43 changes: 43 additions & 0 deletions receiver/hostmetricsreceiver/testdata/e2e/proc/1/status
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Name: bash
State: S (sleeping)
Tgid: 1
Pid: 1
PPid: 0
TracerPid: 0
Uid: 1000 1000 1000 1000
Gid: 1000 1000 1000 1000
FDSize: 128
Groups: 4 20 24
VmPeak: 4153344 kB
VmSize: 4153344 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 808 kB
VmRSS: 808 kB
VmData: 3686404 kB
VmStk: 65536 kB
VmExe: 1129 kB
VmLib: 13 kB
VmPTE: 4 kB
VmSwap: 0 kB
Threads: 1
SigQ: 0/1266761467
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Speculation_Store_Bypass: thread vulnerable
Cpus_allowed: 1
Cpus_allowed_list: 0
Mems_allowed: 0
Mems_allowed_list: 0
voluntary_ctxt_switches: 17
nonvoluntary_ctxt_switches: 4
Loading