Skip to content

Commit c5f3604

Browse files
Merge pull request #753 from dottorblaster/fix-logs-nri-benchmark
fix: prevent eBPF cgroup tracker map exhaustion in NRI benchmarks
2 parents ad675c7 + 9642208 commit c5f3604

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

hack/ci/check-nri-benchmarks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
99
THRESHOLDS_FILE="${THRESHOLDS_FILE:-${SCRIPT_DIR}/nri-benchmark-thresholds.txt}"
1010
BENCH_PKG="${BENCH_PKG:-./internal/nri/}"
1111
BENCH_COUNT="${BENCH_COUNT:-1}"
12-
BENCH_TOLERANCE_PERCENT="${BENCH_TOLERANCE_PERCENT:-20}"
12+
BENCH_TOLERANCE_PERCENT="${BENCH_TOLERANCE_PERCENT:-30}"
1313
UPDATE_BASELINE="${UPDATE_BASELINE:-false}"
1414

1515
if [[ "${GITHUB_ACTIONS:-}" != "true" ]]; then
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# NRI callback benchmark baseline (ns/op).
22
BenchmarkPluginSynchronize 16629755
3-
BenchmarkPluginStartContainer 38394
4-
BenchmarkPluginRemoveContainer 21070
3+
BenchmarkPluginStartContainer 30000
4+
BenchmarkPluginRemoveContainer 15714

internal/nri/plugin_bench_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ func benchContainer(b *testing.B, pod *api.PodSandbox, name string) *api.Contain
132132
}
133133
}
134134

135+
// benchTrackerCleanup returns a function that deletes the container's entry
136+
// from the cgroup tracker map (no BPF programs loaded in benchmarks).
137+
func benchTrackerCleanup(b *testing.B, maps *benchMaps, container *api.Container) func() {
138+
b.Helper()
139+
140+
cgRoot := cgroups.GetCgroupResolutionPrefix()
141+
cgroupPath := filepath.Join(cgRoot, container.GetLinux().GetCgroupsPath())
142+
cgID, err := cgroups.GetCgroupIDFromPath(cgroupPath)
143+
require.NoError(b, err, "resolve cgroup ID")
144+
145+
return func() {
146+
if err = maps.cgTracker.Delete(&cgID); err != nil {
147+
b.Fatalf("delete cgroup tracker entry: %v", err)
148+
}
149+
}
150+
}
151+
135152
func buildSyncFixtures(b *testing.B, numPods, containersPerPod int) ([]*api.PodSandbox, []*api.Container) {
136153
b.Helper()
137154

@@ -183,11 +200,15 @@ func BenchmarkPluginStartContainer(b *testing.B) {
183200
b.StopTimer()
184201
p := newBenchPlugin(b, maps)
185202
container := benchContainer(b, pod, fmt.Sprintf("start-container-%d", i))
203+
cleanup := benchTrackerCleanup(b, maps, container)
186204
b.StartTimer()
187205

188206
if err := p.StartContainer(ctx, pod, container); err != nil {
189207
b.Fatalf("StartContainer: %v", err)
190208
}
209+
210+
b.StopTimer()
211+
cleanup()
191212
}
192213
}
193214

@@ -201,6 +222,8 @@ func BenchmarkPluginRemoveContainer(b *testing.B) {
201222
b.StopTimer()
202223
p := newBenchPlugin(b, maps)
203224
container := benchContainer(b, pod, fmt.Sprintf("remove-container-%d", i))
225+
cleanup := benchTrackerCleanup(b, maps, container)
226+
204227
if err := p.StartContainer(ctx, pod, container); err != nil {
205228
b.Fatalf("seed StartContainer: %v", err)
206229
}
@@ -209,5 +232,8 @@ func BenchmarkPluginRemoveContainer(b *testing.B) {
209232
if err := p.RemoveContainer(ctx, pod, container); err != nil {
210233
b.Fatalf("RemoveContainer: %v", err)
211234
}
235+
236+
b.StopTimer()
237+
cleanup()
212238
}
213239
}

0 commit comments

Comments
 (0)