@@ -36,34 +36,9 @@ import (
36
36
"go.uber.org/atomic"
37
37
)
38
38
39
- // ResourceSpec is a resource consumption specification.
40
- type ResourceSpec struct {
41
- // Percentage of one core the process is expected to consume at most.
42
- // Test is aborted and failed if consumption during
43
- // ResourceCheckPeriod exceeds this number. If 0 the CPU
44
- // consumption is not monitored and does not affect the test result.
45
- ExpectedMaxCPU uint32
46
-
47
- // Maximum RAM in MiB the process is expected to consume.
48
- // Test is aborted and failed if consumption exceeds this number.
49
- // If 0 memory consumption is not monitored and does not affect
50
- // the test result.
51
- ExpectedMaxRAM uint32
52
-
53
- // Period during which CPU and RAM of the process are measured.
54
- // Bigger numbers will result in more averaging of short spikes.
55
- ResourceCheckPeriod time.Duration
56
- }
57
-
58
- // isSpecified returns true if any part of ResourceSpec is specified,
59
- // i.e. has non-zero value.
60
- func (rs * ResourceSpec ) isSpecified () bool {
61
- return rs != nil && (rs .ExpectedMaxCPU != 0 || rs .ExpectedMaxRAM != 0 )
62
- }
63
-
64
- // ChildProcess implements the OtelcolRunner interface as a child process on the same machine executing
39
+ // childProcessCollector implements the OtelcolRunner interface as a child process on the same machine executing
65
40
// the test. The process can be monitored and the output of which will be written to a log file.
66
- type ChildProcess struct {
41
+ type childProcessCollector struct {
67
42
// Path to agent executable. If unset the default executable in
68
43
// bin/otelcol_{{.GOOS}}_{{.GOARCH}} will be used.
69
44
// Can be set for example to use the unstable executable for a specific test.
@@ -121,21 +96,12 @@ type ChildProcess struct {
121
96
ramMiBMax uint32
122
97
}
123
98
124
- type StartParams struct {
125
- Name string
126
- LogFilePath string
127
- CmdArgs []string
128
- resourceSpec * ResourceSpec
129
- }
130
-
131
- type ResourceConsumption struct {
132
- CPUPercentAvg float64
133
- CPUPercentMax float64
134
- RAMMiBAvg uint32
135
- RAMMiBMax uint32
99
+ // NewChildProcessCollector crewtes a new OtelcolRunner as a child process on the same machine executing the test.
100
+ func NewChildProcessCollector () OtelcolRunner {
101
+ return & childProcessCollector {}
136
102
}
137
103
138
- func (cp * ChildProcess ) PrepareConfig (configStr string ) (configCleanup func (), err error ) {
104
+ func (cp * childProcessCollector ) PrepareConfig (configStr string ) (configCleanup func (), err error ) {
139
105
configCleanup = func () {
140
106
// NoOp
141
107
}
@@ -198,7 +164,7 @@ func expandExeFileName(exeName string) string {
198
164
// logFilePath is the file path to write the standard output and standard error of
199
165
// the process to.
200
166
// cmdArgs is the command line arguments to pass to the process.
201
- func (cp * ChildProcess ) Start (params StartParams ) error {
167
+ func (cp * childProcessCollector ) Start (params StartParams ) error {
202
168
203
169
cp .name = params .Name
204
170
cp .doneSignal = make (chan struct {})
@@ -275,7 +241,7 @@ func (cp *ChildProcess) Start(params StartParams) error {
275
241
return err
276
242
}
277
243
278
- func (cp * ChildProcess ) Stop () (stopped bool , err error ) {
244
+ func (cp * childProcessCollector ) Stop () (stopped bool , err error ) {
279
245
if ! cp .isStarted || cp .isStopped {
280
246
return false , nil
281
247
}
@@ -341,7 +307,7 @@ func (cp *ChildProcess) Stop() (stopped bool, err error) {
341
307
return stopped , err
342
308
}
343
309
344
- func (cp * ChildProcess ) WatchResourceConsumption () error {
310
+ func (cp * childProcessCollector ) WatchResourceConsumption () error {
345
311
if ! cp .resourceSpec .isSpecified () {
346
312
// Resource monitoring is not enabled.
347
313
return nil
@@ -388,11 +354,11 @@ func (cp *ChildProcess) WatchResourceConsumption() error {
388
354
}
389
355
}
390
356
391
- func (cp * ChildProcess ) GetProcessMon () * process.Process {
357
+ func (cp * childProcessCollector ) GetProcessMon () * process.Process {
392
358
return cp .processMon
393
359
}
394
360
395
- func (cp * ChildProcess ) fetchRAMUsage () {
361
+ func (cp * childProcessCollector ) fetchRAMUsage () {
396
362
// Get process memory and CPU times
397
363
mi , err := cp .processMon .MemoryInfo ()
398
364
if err != nil {
@@ -415,7 +381,7 @@ func (cp *ChildProcess) fetchRAMUsage() {
415
381
cp .ramMiBCur .Store (ramMiBCur )
416
382
}
417
383
418
- func (cp * ChildProcess ) fetchCPUUsage () {
384
+ func (cp * childProcessCollector ) fetchCPUUsage () {
419
385
times , err := cp .processMon .Times ()
420
386
if err != nil {
421
387
log .Printf ("cannot get process times for %d: %s" ,
@@ -448,7 +414,7 @@ func (cp *ChildProcess) fetchCPUUsage() {
448
414
cp .cpuPercentX1000Cur .Store (curCPUPercentageX1000 )
449
415
}
450
416
451
- func (cp * ChildProcess ) checkAllowedResourceUsage () error {
417
+ func (cp * childProcessCollector ) checkAllowedResourceUsage () error {
452
418
// Check if current CPU usage exceeds expected.
453
419
var errMsg string
454
420
if cp .resourceSpec .ExpectedMaxCPU != 0 && cp .cpuPercentX1000Cur .Load ()/ 1000 > cp .resourceSpec .ExpectedMaxCPU {
@@ -472,7 +438,7 @@ func (cp *ChildProcess) checkAllowedResourceUsage() error {
472
438
}
473
439
474
440
// GetResourceConsumption returns resource consumption as a string
475
- func (cp * ChildProcess ) GetResourceConsumption () string {
441
+ func (cp * childProcessCollector ) GetResourceConsumption () string {
476
442
if ! cp .resourceSpec .isSpecified () {
477
443
// Monitoring is not enabled.
478
444
return ""
@@ -486,7 +452,7 @@ func (cp *ChildProcess) GetResourceConsumption() string {
486
452
}
487
453
488
454
// GetTotalConsumption returns total resource consumption since start of process
489
- func (cp * ChildProcess ) GetTotalConsumption () * ResourceConsumption {
455
+ func (cp * childProcessCollector ) GetTotalConsumption () * ResourceConsumption {
490
456
rc := & ResourceConsumption {}
491
457
492
458
if cp .processMon != nil {
0 commit comments