Skip to content

Commit defc07b

Browse files
authored
chore: [receiver/hostmetrics] Fix integration tests (open-telemetry#36847)
1 parent 36945ee commit defc07b

File tree

7 files changed

+102
-124
lines changed

7 files changed

+102
-124
lines changed

receiver/hostmetricsreceiver/integration_test.go

+15-17
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
)
2323

2424
func Test_ProcessScrape(t *testing.T) {
25-
t.Skip("TODO: Skipping for now due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32536")
26-
2725
expectedFile := filepath.Join("testdata", "e2e", "expected_process.yaml")
2826
cmd := exec.Command("/bin/sleep", "300")
2927
require.NoError(t, cmd.Start())
@@ -38,6 +36,7 @@ func Test_ProcessScrape(t *testing.T) {
3836
rCfg := cfg.(*Config)
3937
rCfg.CollectionInterval = time.Second
4038
pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
39+
pCfg.MuteProcessExeError = true
4140
pCfg.Include = processscraper.MatchConfig{
4241
Config: filterset.Config{MatchType: filterset.Regexp},
4342
Names: []string{"sleep"},
@@ -48,6 +47,9 @@ func Test_ProcessScrape(t *testing.T) {
4847
}),
4948
scraperinttest.WithExpectedFile(expectedFile),
5049
scraperinttest.WithCompareOptions(
50+
pmetrictest.IgnoreResourceAttributeValue("process.owner"),
51+
pmetrictest.IgnoreResourceAttributeValue("process.parent_pid"),
52+
pmetrictest.IgnoreResourceAttributeValue("process.pid"),
5153
pmetrictest.IgnoreResourceMetricsOrder(),
5254
pmetrictest.IgnoreMetricValues(),
5355
pmetrictest.IgnoreMetricDataPointsOrder(),
@@ -58,25 +60,22 @@ func Test_ProcessScrape(t *testing.T) {
5860
}
5961

6062
func Test_ProcessScrapeWithCustomRootPath(t *testing.T) {
61-
t.Skip("TODO: Skipping for now due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32536")
62-
6363
expectedFile := filepath.Join("testdata", "e2e", "expected_process_separate_proc.yaml")
6464

6565
scraperinttest.NewIntegrationTest(
6666
NewFactory(),
6767
scraperinttest.WithCustomConfig(
6868
func(_ *testing.T, cfg component.Config, _ *scraperinttest.ContainerInfo) {
69+
rootPath := filepath.Join("testdata", "e2e")
6970
rCfg := cfg.(*Config)
7071
rCfg.CollectionInterval = time.Second
72+
rCfg.RootPath = rootPath
7173
pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
72-
pCfg.Include = processscraper.MatchConfig{
73-
Config: filterset.Config{MatchType: filterset.Regexp},
74-
Names: []string{"sleep"},
75-
}
74+
pCfg.SetRootPath(rootPath)
75+
pCfg.SetEnvMap(setGoPsutilEnvVars(rootPath, &osEnv{}))
7676
rCfg.Scrapers = map[string]internal.Config{
7777
"process": pCfg,
7878
}
79-
rCfg.RootPath = filepath.Join("testdata", "e2e")
8079
}),
8180
scraperinttest.WithExpectedFile(expectedFile),
8281
scraperinttest.WithCompareOptions(
@@ -90,25 +89,24 @@ func Test_ProcessScrapeWithCustomRootPath(t *testing.T) {
9089
}
9190

9291
func Test_ProcessScrapeWithBadRootPathAndEnvVar(t *testing.T) {
93-
t.Skip("TODO: Skipping for now due to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32536")
94-
92+
rootPath := filepath.Join("testdata", "e2e", "proc")
93+
badRootPath := filepath.Join("testdata", "NOT A VALID FOLDER")
9594
expectedFile := filepath.Join("testdata", "e2e", "expected_process_separate_proc.yaml")
96-
t.Setenv("HOST_PROC", filepath.Join("testdata", "e2e", "proc"))
95+
96+
t.Setenv("HOST_PROC", rootPath)
9797
scraperinttest.NewIntegrationTest(
9898
NewFactory(),
9999
scraperinttest.WithCustomConfig(
100100
func(_ *testing.T, cfg component.Config, _ *scraperinttest.ContainerInfo) {
101101
rCfg := cfg.(*Config)
102102
rCfg.CollectionInterval = time.Second
103103
pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
104-
pCfg.Include = processscraper.MatchConfig{
105-
Config: filterset.Config{MatchType: filterset.Regexp},
106-
Names: []string{"sleep"},
107-
}
104+
pCfg.SetRootPath(badRootPath)
105+
pCfg.SetEnvMap(setGoPsutilEnvVars(badRootPath, &osEnv{}))
108106
rCfg.Scrapers = map[string]internal.Config{
109107
"process": pCfg,
110108
}
111-
rCfg.RootPath = filepath.Join("testdata", "NOT A VALID FOLDER")
109+
rCfg.RootPath = badRootPath
112110
}),
113111
scraperinttest.WithExpectedFile(expectedFile),
114112
scraperinttest.WithCompareOptions(

receiver/hostmetricsreceiver/testdata/e2e/expected_process.yaml

+15-78
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resourceMetrics:
33
attributes:
44
- key: process.command
55
value:
6-
stringValue: /bin/sleep 300
6+
stringValue: /bin/sleep
77
- key: process.command_line
88
value:
99
stringValue: /bin/sleep 300
@@ -12,16 +12,7 @@ resourceMetrics:
1212
stringValue: sleep
1313
- key: process.executable.path
1414
value:
15-
stringValue: /bin/sleep
16-
- key: process.owner
17-
value:
18-
stringValue: atoulme
19-
- key: process.parent_pid
20-
value:
21-
intValue: "95040"
22-
- key: process.pid
23-
value:
24-
intValue: "95041"
15+
stringValue: /usr/bin/sleep
2516
schemaUrl: https://opentelemetry.io/schemas/1.9.0
2617
scopeMetrics:
2718
- metrics:
@@ -30,14 +21,14 @@ resourceMetrics:
3021
sum:
3122
aggregationTemporality: 2
3223
dataPoints:
33-
- asDouble: 0.0012836666666666665
24+
- asDouble: 0
3425
attributes:
3526
- key: state
3627
value:
3728
stringValue: system
3829
startTimeUnixNano: "1000000"
3930
timeUnixNano: "2000000"
40-
- asDouble: 0.00037095833333333333
31+
- asDouble: 0
4132
attributes:
4233
- key: state
4334
value:
@@ -53,87 +44,33 @@ resourceMetrics:
5344
timeUnixNano: "2000000"
5445
isMonotonic: true
5546
unit: s
56-
- description: The amount of physical memory in use.
57-
name: process.memory.usage
58-
sum:
59-
aggregationTemporality: 2
60-
dataPoints:
61-
- asInt: "1064960"
62-
startTimeUnixNano: "1000000"
63-
timeUnixNano: "2000000"
64-
unit: By
65-
- description: Virtual memory size.
66-
name: process.memory.virtual
67-
sum:
68-
aggregationTemporality: 2
69-
dataPoints:
70-
- asInt: "418299674624"
71-
startTimeUnixNano: "1000000"
72-
timeUnixNano: "2000000"
73-
unit: By
74-
scope:
75-
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper
76-
version: latest
77-
- resource:
78-
attributes:
79-
- key: process.command
80-
value:
81-
stringValue: sleep 31536000
82-
- key: process.command_line
83-
value:
84-
stringValue: sleep 31536000
85-
- key: process.executable.name
86-
value:
87-
stringValue: sleep
88-
- key: process.executable.path
89-
value:
90-
stringValue: sleep
91-
- key: process.owner
92-
value:
93-
stringValue: atoulme
94-
- key: process.parent_pid
95-
value:
96-
intValue: "4654"
97-
- key: process.pid
98-
value:
99-
intValue: "4668"
100-
schemaUrl: https://opentelemetry.io/schemas/1.9.0
101-
scopeMetrics:
102-
- metrics:
103-
- description: Total CPU seconds broken down by different states.
104-
name: process.cpu.time
47+
- description: Disk bytes transferred.
48+
name: process.disk.io
10549
sum:
10650
aggregationTemporality: 2
10751
dataPoints:
108-
- asDouble: 0.0030173333333333332
52+
- asInt: "7090"
10953
attributes:
110-
- key: state
54+
- key: direction
11155
value:
112-
stringValue: system
56+
stringValue: read
11357
startTimeUnixNano: "1000000"
11458
timeUnixNano: "2000000"
115-
- asDouble: 0.0006898333333333332
59+
- asInt: "0"
11660
attributes:
117-
- key: state
61+
- key: direction
11862
value:
119-
stringValue: user
120-
startTimeUnixNano: "1000000"
121-
timeUnixNano: "2000000"
122-
- asDouble: 0
123-
attributes:
124-
- key: state
125-
value:
126-
stringValue: wait
63+
stringValue: write
12764
startTimeUnixNano: "1000000"
12865
timeUnixNano: "2000000"
12966
isMonotonic: true
130-
unit: s
67+
unit: By
13168
- description: The amount of physical memory in use.
13269
name: process.memory.usage
13370
sum:
13471
aggregationTemporality: 2
13572
dataPoints:
136-
- asInt: "311296"
73+
- asInt: "5873664"
13774
startTimeUnixNano: "1000000"
13875
timeUnixNano: "2000000"
13976
unit: By
@@ -142,7 +79,7 @@ resourceMetrics:
14279
sum:
14380
aggregationTemporality: 2
14481
dataPoints:
145-
- asInt: "418299674624"
82+
- asInt: "8265728"
14683
startTimeUnixNano: "1000000"
14784
timeUnixNano: "2000000"
14885
unit: By

receiver/hostmetricsreceiver/testdata/e2e/expected_process_separate_proc.yaml

+26-29
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
resourceMetrics:
22
- resource:
33
attributes:
4-
- key: process.command
4+
- key: process.pid
55
value:
6-
stringValue: sleep 31536000
7-
- key: process.command_line
6+
intValue: "1"
7+
- key: process.parent_pid
88
value:
9-
stringValue: sleep 31536000
9+
intValue: "0"
1010
- key: process.executable.name
1111
value:
12-
stringValue: sleep
12+
stringValue: ""
1313
- key: process.executable.path
1414
value:
15-
stringValue: sleep
16-
- key: process.owner
17-
value:
18-
stringValue: atoulme
19-
- key: process.parent_pid
15+
stringValue: testdata/e2e/bin/bash
16+
- key: process.command
2017
value:
21-
intValue: "4654"
22-
- key: process.pid
18+
stringValue: /bin/bash
19+
- key: process.command_line
2320
value:
24-
intValue: "4668"
21+
stringValue: /bin/bash
2522
schemaUrl: https://opentelemetry.io/schemas/1.9.0
2623
scopeMetrics:
2724
- metrics:
@@ -30,46 +27,46 @@ resourceMetrics:
3027
sum:
3128
aggregationTemporality: 2
3229
dataPoints:
33-
- asDouble: 0.0030173333333333332
30+
- asDouble: 0
3431
attributes:
3532
- key: state
3633
value:
37-
stringValue: system
38-
startTimeUnixNano: "1000000"
39-
timeUnixNano: "2000000"
40-
- asDouble: 0.0006898333333333332
34+
stringValue: user
35+
startTimeUnixNano: "1693963661860000000"
36+
timeUnixNano: "1734347455586234971"
37+
- asDouble: 0
4138
attributes:
4239
- key: state
4340
value:
44-
stringValue: user
45-
startTimeUnixNano: "1000000"
46-
timeUnixNano: "2000000"
41+
stringValue: system
42+
startTimeUnixNano: "1693963661860000000"
43+
timeUnixNano: "1734347455586234971"
4744
- asDouble: 0
4845
attributes:
4946
- key: state
5047
value:
5148
stringValue: wait
52-
startTimeUnixNano: "1000000"
53-
timeUnixNano: "2000000"
49+
startTimeUnixNano: "1693963661860000000"
50+
timeUnixNano: "1734347455586234971"
5451
isMonotonic: true
5552
unit: s
5653
- description: The amount of physical memory in use.
5754
name: process.memory.usage
5855
sum:
5956
aggregationTemporality: 2
6057
dataPoints:
61-
- asInt: "311296"
62-
startTimeUnixNano: "1000000"
63-
timeUnixNano: "2000000"
58+
- asInt: "2322432"
59+
startTimeUnixNano: "1693963661860000000"
60+
timeUnixNano: "1734347455586234971"
6461
unit: By
6562
- description: Virtual memory size.
6663
name: process.memory.virtual
6764
sum:
6865
aggregationTemporality: 2
6966
dataPoints:
70-
- asInt: "418299674624"
71-
startTimeUnixNano: "1000000"
72-
timeUnixNano: "2000000"
67+
- asInt: "5054464"
68+
startTimeUnixNano: "1693963661860000000"
69+
timeUnixNano: "1734347455586234971"
7370
unit: By
7471
scope:
7572
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0::/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testdata/e2e/bin/bash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1234 567 89 10 11 12 13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Name: bash
2+
State: S (sleeping)
3+
Tgid: 1
4+
Pid: 1
5+
PPid: 0
6+
TracerPid: 0
7+
Uid: 1000 1000 1000 1000
8+
Gid: 1000 1000 1000 1000
9+
FDSize: 128
10+
Groups: 4 20 24
11+
VmPeak: 4153344 kB
12+
VmSize: 4153344 kB
13+
VmLck: 0 kB
14+
VmPin: 0 kB
15+
VmHWM: 808 kB
16+
VmRSS: 808 kB
17+
VmData: 3686404 kB
18+
VmStk: 65536 kB
19+
VmExe: 1129 kB
20+
VmLib: 13 kB
21+
VmPTE: 4 kB
22+
VmSwap: 0 kB
23+
Threads: 1
24+
SigQ: 0/1266761467
25+
SigPnd: 0000000000000000
26+
ShdPnd: 0000000000000000
27+
SigBlk: 0000000000000000
28+
SigIgn: 0000000000000000
29+
SigCgt: 0000000000000000
30+
CapInh: 0000000000000000
31+
CapPrm: 0000000000000000
32+
CapEff: 0000000000000000
33+
CapBnd: 0000000000000000
34+
CapAmb: 0000000000000000
35+
NoNewPrivs: 0
36+
Seccomp: 0
37+
Speculation_Store_Bypass: thread vulnerable
38+
Cpus_allowed: 1
39+
Cpus_allowed_list: 0
40+
Mems_allowed: 0
41+
Mems_allowed_list: 0
42+
voluntary_ctxt_switches: 17
43+
nonvoluntary_ctxt_switches: 4

0 commit comments

Comments
 (0)