Skip to content

Commit 21d21bb

Browse files
authored
[testbed] Include CPU and memory limits to benchmark results file (#36753)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR adds the specified limits for the CPU and memory consumption to the benchmark results file. This way, these values can also be included in a timeseries chart, next to the max and average consumption. For now, this is disabled by default in the `PerfTestValidator` to not introduce any unwanted changes to the charts generated from tests using this component <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #36720 --------- Signed-off-by: Florian Bacher <[email protected]>
1 parent f985803 commit 21d21bb

File tree

6 files changed

+89
-25
lines changed

6 files changed

+89
-25
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: testbed
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Include the specified resource limits for CPU and memory in the benchmark results
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36720]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

testbed/testbed/child_process_collector.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ func (cp *childProcessCollector) GetResourceConsumption() string {
466466

467467
// GetTotalConsumption returns total resource consumption since start of process
468468
func (cp *childProcessCollector) GetTotalConsumption() *ResourceConsumption {
469-
rc := &ResourceConsumption{}
469+
rc := &ResourceConsumption{
470+
CPUPercentLimit: float64(cp.resourceSpec.ExpectedMaxCPU),
471+
RAMMiBLimit: cp.resourceSpec.ExpectedMaxRAM,
472+
}
470473

471474
if cp.processMon != nil {
472475
// Get total elapsed time since process start

testbed/testbed/in_process_collector.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ func (ipp *inProcessCollector) GetProcessMon() *process.Process {
116116

117117
func (ipp *inProcessCollector) GetTotalConsumption() *ResourceConsumption {
118118
return &ResourceConsumption{
119-
CPUPercentAvg: 0,
120-
CPUPercentMax: 0,
121-
RAMMiBAvg: 0,
122-
RAMMiBMax: 0,
119+
CPUPercentAvg: 0,
120+
CPUPercentMax: 0,
121+
CPUPercentLimit: 0,
122+
RAMMiBAvg: 0,
123+
RAMMiBMax: 0,
124+
RAMMiBLimit: 0,
123125
}
124126
}
125127

testbed/testbed/otelcol_runner.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ type StartParams struct {
1515
}
1616

1717
type ResourceConsumption struct {
18-
CPUPercentAvg float64
19-
CPUPercentMax float64
20-
RAMMiBAvg uint32
21-
RAMMiBMax uint32
18+
CPUPercentAvg float64
19+
CPUPercentMax float64
20+
CPUPercentLimit float64
21+
RAMMiBAvg uint32
22+
RAMMiBMax uint32
23+
RAMMiBLimit uint32
2224
}
2325

2426
// OtelcolRunner defines the interface for configuring, starting and stopping one or more instances of

testbed/testbed/results.go

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ type PerformanceResults struct {
5252

5353
// PerformanceTestResult reports the results of a single performance test.
5454
type PerformanceTestResult struct {
55-
testName string
56-
result string
57-
duration time.Duration
58-
cpuPercentageAvg float64
59-
cpuPercentageMax float64
60-
ramMibAvg uint32
61-
ramMibMax uint32
62-
sentSpanCount uint64
63-
receivedSpanCount uint64
64-
errorCause string
55+
testName string
56+
result string
57+
duration time.Duration
58+
cpuPercentageAvg float64
59+
cpuPercentageMax float64
60+
cpuPercentageLimit float64
61+
ramMibAvg uint32
62+
ramMibMax uint32
63+
ramMibLimit uint32
64+
sentSpanCount uint64
65+
receivedSpanCount uint64
66+
errorCause string
6567
}
6668

6769
func (r *PerformanceResults) Init(resultsDir string) {
@@ -83,8 +85,8 @@ func (r *PerformanceResults) Init(resultsDir string) {
8385
_, _ = io.WriteString(r.resultsFile,
8486
"# Test PerformanceResults\n"+
8587
fmt.Sprintf("Started: %s\n\n", time.Now().Format(time.RFC1123Z))+
86-
"Test |Result|Duration|CPU Avg%|CPU Max%|RAM Avg MiB|RAM Max MiB|Sent Items|Received Items|\n"+
87-
"----------------------------------------|------|-------:|-------:|-------:|----------:|----------:|---------:|-------------:|\n")
88+
"Test |Result|Duration|CPU Avg%|CPU Max%|CPU Limit|RAM Avg MiB|RAM Max MiB|RAM Limit MiB|Sent Items|Received Items|\n"+
89+
"----------------------------------------|------|-------:|-------:|-------:|--------:|----------:|----------:|------------:|---------:|-------------:|\n")
8890
}
8991

9092
// Save the total results and close the file.
@@ -103,14 +105,16 @@ func (r *PerformanceResults) Add(_ string, result any) {
103105
}
104106

105107
_, _ = io.WriteString(r.resultsFile,
106-
fmt.Sprintf("%-40s|%-6s|%7.0fs|%8.1f|%8.1f|%11d|%11d|%10d|%14d|%s\n",
108+
fmt.Sprintf("%-40s|%-6s|%7.0fs|%8.1f|%8.1f|%8.1f|%11d|%11d|%11d|%10d|%14d|%s\n",
107109
testResult.testName,
108110
testResult.result,
109111
testResult.duration.Seconds(),
110112
testResult.cpuPercentageAvg,
111113
testResult.cpuPercentageMax,
114+
testResult.cpuPercentageLimit,
112115
testResult.ramMibAvg,
113116
testResult.ramMibMax,
117+
testResult.ramMibLimit,
114118
testResult.sentSpanCount,
115119
testResult.receivedSpanCount,
116120
testResult.errorCause,
@@ -135,6 +139,14 @@ func (r *PerformanceResults) Add(_ string, result any) {
135139
Unit: "%",
136140
Extra: cpuChartName,
137141
})
142+
if testResult.cpuPercentageLimit > 0 {
143+
r.benchmarkResults = append(r.benchmarkResults, &benchmarkResult{
144+
Name: "cpu_percentage_limit",
145+
Value: testResult.cpuPercentageLimit,
146+
Unit: "%",
147+
Extra: cpuChartName,
148+
})
149+
}
138150
r.benchmarkResults = append(r.benchmarkResults, &benchmarkResult{
139151
Name: "ram_mib_avg",
140152
Value: float64(testResult.ramMibAvg),
@@ -147,6 +159,14 @@ func (r *PerformanceResults) Add(_ string, result any) {
147159
Unit: "MiB",
148160
Extra: memoryChartName,
149161
})
162+
if testResult.ramMibLimit > 0 {
163+
r.benchmarkResults = append(r.benchmarkResults, &benchmarkResult{
164+
Name: "ram_mib_limit",
165+
Value: float64(testResult.ramMibLimit),
166+
Unit: "MiB",
167+
Extra: memoryChartName,
168+
})
169+
}
150170
r.benchmarkResults = append(r.benchmarkResults, &benchmarkResult{
151171
Name: "dropped_span_count",
152172
Value: float64(testResult.sentSpanCount - testResult.receivedSpanCount),

testbed/testbed/validator.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ func (v *LogPresentValidator) RecordResults(tc *TestCase) {
6666
}
6767

6868
// PerfTestValidator implements TestCaseValidator for test suites using PerformanceResults for summarizing results.
69-
type PerfTestValidator struct{}
69+
type PerfTestValidator struct {
70+
// IncludeLimitsInReport determines whether the summary generated by PerformanceResults should include the specified resource limits
71+
IncludeLimitsInReport bool
72+
}
7073

7174
func (v *PerfTestValidator) Validate(tc *TestCase) {
7275
if assert.EqualValues(tc.t,
@@ -90,7 +93,7 @@ func (v *PerfTestValidator) RecordResults(tc *TestCase) {
9093
// Remove "Test" prefix from test name.
9194
testName := tc.t.Name()[4:]
9295

93-
tc.resultsSummary.Add(tc.t.Name(), &PerformanceTestResult{
96+
performanceResults := &PerformanceTestResult{
9497
testName: testName,
9598
result: result,
9699
receivedSpanCount: tc.MockBackend.DataItemsReceived(),
@@ -101,7 +104,14 @@ func (v *PerfTestValidator) RecordResults(tc *TestCase) {
101104
ramMibAvg: rc.RAMMiBAvg,
102105
ramMibMax: rc.RAMMiBMax,
103106
errorCause: tc.errorCause,
104-
})
107+
}
108+
109+
if v.IncludeLimitsInReport {
110+
performanceResults.cpuPercentageLimit = rc.CPUPercentLimit
111+
performanceResults.ramMibLimit = rc.RAMMiBLimit
112+
}
113+
114+
tc.resultsSummary.Add(tc.t.Name(), performanceResults)
105115
}
106116

107117
// CorrectnessTestValidator implements TestCaseValidator for test suites using CorrectnessResults for summarizing results.

0 commit comments

Comments
 (0)