diff --git a/receiver/hostmetricsreceiver/integration_test.go b/receiver/hostmetricsreceiver/integration_test.go index 2238b2fed0b5..775e0cbb4910 100644 --- a/receiver/hostmetricsreceiver/integration_test.go +++ b/receiver/hostmetricsreceiver/integration_test.go @@ -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()) @@ -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"}, @@ -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(), @@ -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( @@ -90,10 +89,11 @@ 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( @@ -101,14 +101,12 @@ func Test_ProcessScrapeWithBadRootPathAndEnvVar(t *testing.T) { 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( diff --git a/receiver/hostmetricsreceiver/testdata/e2e/expected_process.yaml b/receiver/hostmetricsreceiver/testdata/e2e/expected_process.yaml index 0e106177a281..1ca3d63e23a3 100644 --- a/receiver/hostmetricsreceiver/testdata/e2e/expected_process.yaml +++ b/receiver/hostmetricsreceiver/testdata/e2e/expected_process.yaml @@ -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 @@ -12,16 +12,7 @@ resourceMetrics: stringValue: sleep - key: process.executable.path value: - stringValue: /bin/sleep - - key: process.owner - value: - stringValue: atoulme - - key: process.parent_pid - value: - intValue: "95040" - - key: process.pid - value: - intValue: "95041" + stringValue: /usr/bin/sleep schemaUrl: https://opentelemetry.io/schemas/1.9.0 scopeMetrics: - metrics: @@ -30,14 +21,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: @@ -53,87 +44,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 @@ -142,7 +79,7 @@ resourceMetrics: sum: aggregationTemporality: 2 dataPoints: - - asInt: "418299674624" + - asInt: "8265728" startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By diff --git a/receiver/hostmetricsreceiver/testdata/e2e/expected_process_separate_proc.yaml b/receiver/hostmetricsreceiver/testdata/e2e/expected_process_separate_proc.yaml index b7b7ec0d41c1..7b53bc460940 100644 --- a/receiver/hostmetricsreceiver/testdata/e2e/expected_process_separate_proc.yaml +++ b/receiver/hostmetricsreceiver/testdata/e2e/expected_process_separate_proc.yaml @@ -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: @@ -30,27 +27,27 @@ 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. @@ -58,18 +55,18 @@ resourceMetrics: 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 diff --git a/receiver/hostmetricsreceiver/testdata/e2e/proc/1/cgroup b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/cgroup new file mode 100644 index 000000000000..1e027b2a3cba --- /dev/null +++ b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/cgroup @@ -0,0 +1 @@ +0::/ diff --git a/receiver/hostmetricsreceiver/testdata/e2e/proc/1/exe b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/exe new file mode 120000 index 000000000000..bc30512ec713 --- /dev/null +++ b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/exe @@ -0,0 +1 @@ +testdata/e2e/bin/bash \ No newline at end of file diff --git a/receiver/hostmetricsreceiver/testdata/e2e/proc/1/statm b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/statm new file mode 100644 index 000000000000..d56b3b458b13 --- /dev/null +++ b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/statm @@ -0,0 +1 @@ +1234 567 89 10 11 12 13 diff --git a/receiver/hostmetricsreceiver/testdata/e2e/proc/1/status b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/status new file mode 100644 index 000000000000..1f2c31e6027e --- /dev/null +++ b/receiver/hostmetricsreceiver/testdata/e2e/proc/1/status @@ -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