From b8438685ebfc438780df30a7c135c516e715d194 Mon Sep 17 00:00:00 2001 From: Nashwan Azhari Date: Mon, 21 Mar 2022 15:19:59 +0200 Subject: [PATCH] Parametrize benchmarking-related timeouts. Signed-off-by: Nashwan Azhari --- pkg/benchmark/container.go | 11 ++++++++++- pkg/benchmark/image.go | 26 ++++++++++++++++++++++---- pkg/benchmark/pod.go | 11 ++++++++++- pkg/benchmark/pod_container.go | 10 +++++++++- pkg/framework/test_context.go | 16 ++++++++++++++++ 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/pkg/benchmark/container.go b/pkg/benchmark/container.go index 885fe1fdd9..283f275f54 100644 --- a/pkg/benchmark/container.go +++ b/pkg/benchmark/container.go @@ -28,6 +28,10 @@ import ( runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" ) +const ( + defaultContainerBenchmarkTimeoutSeconds = 60 +) + var _ = framework.KubeDescribe("Container", func() { f := framework.NewDefaultCRIFramework() @@ -41,6 +45,11 @@ var _ = framework.KubeDescribe("Container", func() { Context("benchmark about operations on Container", func() { It("benchmark about basic operations on Container", func() { + timeout := defaultContainerBenchmarkTimeoutSeconds + if framework.TestContext.BenchmarkingParams.ContainerBenchmarkTimeoutSeconds > 0 { + timeout = framework.TestContext.BenchmarkingParams.ContainerBenchmarkTimeoutSeconds + } + // Setup sampling config from TestContext: samplingConfig := gmeasure.SamplingConfig{ N: framework.TestContext.BenchmarkingParams.ContainersNumber, @@ -61,7 +70,7 @@ var _ = framework.KubeDescribe("Container", func() { } resultsManager := NewLifecycleBenchmarksResultsManager( resultsSet, - 60, + timeout, ) resultsChannel := resultsManager.StartResultsConsumer() diff --git a/pkg/benchmark/image.go b/pkg/benchmark/image.go index 83e03cd642..bcf0bc8d1e 100644 --- a/pkg/benchmark/image.go +++ b/pkg/benchmark/image.go @@ -27,6 +27,13 @@ import ( . "github.com/onsi/gomega" ) +const ( + defaultImagePullTimeoutSeconds = 1 + defaultImageStatusTimeoutSeconds = 2 + defaultImageRemoveTimeoutSeconds = 2 + defaultImageListTimeoutSeconds = 2 +) + var _ = framework.KubeDescribe("Container", func() { f := framework.NewDefaultCRIFramework() @@ -65,6 +72,17 @@ var _ = framework.KubeDescribe("Container", func() { } }) + imagePullTimeoutSeconds := defaultImagePullTimeoutSeconds + imageStatusTimeoutSeconds := defaultImageStatusTimeoutSeconds + imageRemoveTimeoutSeconds := defaultImageRemoveTimeoutSeconds + imageListTimeoutSeconds := defaultImageListTimeoutSeconds + if framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds > 0 { + imagePullTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds + imageStatusTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds + imageRemoveTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds + imageListTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds + } + Measure("benchmark about basic operations on Image", func(b Benchmarker) { imageSpec := &runtimeapi.ImageSpec{ Image: testImageList[0], @@ -73,21 +91,21 @@ var _ = framework.KubeDescribe("Container", func() { operation := b.Time("pull Image", func() { framework.PullPublicImage(ic, testImageList[0], nil) }) - Expect(operation.Minutes()).Should(BeNumerically("<", 1), "pull Image shouldn't take too long.") + Expect(operation.Minutes()).Should(BeNumerically("<", imagePullTimeoutSeconds), "pull Image shouldn't take too long.") operation = b.Time("Image status", func() { _, err = ic.ImageStatus(imageSpec, false) }) framework.ExpectNoError(err, "failed to get image status: %v", err) - Expect(operation.Seconds()).Should(BeNumerically("<", 2), "get image status shouldn't take too long.") + Expect(operation.Seconds()).Should(BeNumerically("<", imageStatusTimeoutSeconds), "get image status shouldn't take too long.") operation = b.Time("remove Image", func() { err = ic.RemoveImage(imageSpec) }) framework.ExpectNoError(err, "failed to remove image: %v", err) - Expect(operation.Seconds()).Should(BeNumerically("<", 2), "remove Image shouldn't take too long.") + Expect(operation.Seconds()).Should(BeNumerically("<", imageRemoveTimeoutSeconds), "remove Image shouldn't take too long.") }, defaultOperationTimes) @@ -101,7 +119,7 @@ var _ = framework.KubeDescribe("Container", func() { }) framework.ExpectNoError(err, "failed to list Image: %v", err) - Expect(operation.Seconds()).Should(BeNumerically("<", 2), "list Image shouldn't take too long.") + Expect(operation.Seconds()).Should(BeNumerically("<", imageListTimeoutSeconds), "list Image shouldn't take too long.") }, defaultOperationTimes) }) }) diff --git a/pkg/benchmark/pod.go b/pkg/benchmark/pod.go index 1660ad26c9..7f67d67111 100644 --- a/pkg/benchmark/pod.go +++ b/pkg/benchmark/pod.go @@ -29,6 +29,10 @@ import ( runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" ) +const ( + defaultPodBenchmarkTimeoutSeconds = 60 +) + var _ = framework.KubeDescribe("PodSandbox", func() { f := framework.NewDefaultCRIFramework() @@ -40,6 +44,11 @@ var _ = framework.KubeDescribe("PodSandbox", func() { Context("benchmark about operations on PodSandbox", func() { It("benchmark about lifecycle of PodSandbox", func() { + timeout := defaultPodBenchmarkTimeoutSeconds + if framework.TestContext.BenchmarkingParams.ContainerBenchmarkTimeoutSeconds > 0 { + timeout = framework.TestContext.BenchmarkingParams.ContainerBenchmarkTimeoutSeconds + } + // Setup sampling config from TestContext: samplingConfig := gmeasure.SamplingConfig{ N: framework.TestContext.BenchmarkingParams.PodsNumber, @@ -60,7 +69,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() { } resultsManager := NewLifecycleBenchmarksResultsManager( resultsSet, - 60, + timeout, ) resultsChannel := resultsManager.StartResultsConsumer() diff --git a/pkg/benchmark/pod_container.go b/pkg/benchmark/pod_container.go index b66a558901..90115959b7 100644 --- a/pkg/benchmark/pod_container.go +++ b/pkg/benchmark/pod_container.go @@ -25,12 +25,20 @@ import ( . "github.com/onsi/gomega" ) +const ( + defaultPodContainerBenchmarkTimeoutSeconds = 5 +) + var _ = framework.KubeDescribe("PodSandbox", func() { f := framework.NewDefaultCRIFramework() var rc internalapi.RuntimeService var ic internalapi.ImageManagerService var podID string + timeout := defaultPodContainerBenchmarkTimeoutSeconds + if framework.TestContext.BenchmarkingParams.PodContainerStartBenchmarkTimeoutSeconds > 0 { + timeout = framework.TestContext.BenchmarkingParams.PodContainerStartBenchmarkTimeoutSeconds + } BeforeEach(func() { rc = f.CRIClient.CRIRuntimeClient @@ -68,7 +76,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() { }) framework.ExpectNoError(err, "failed to start Container: %v", err) - Expect(operation.Seconds()).Should(BeNumerically("<", 5), "create PodSandbox shouldn't take too long.") + Expect(operation.Seconds()).Should(BeNumerically("<", timeout), "create PodSandbox shouldn't take too long.") }, defaultOperationTimes) }) }) diff --git a/pkg/framework/test_context.go b/pkg/framework/test_context.go index ce04e9a304..88a7eb0ea8 100644 --- a/pkg/framework/test_context.go +++ b/pkg/framework/test_context.go @@ -48,12 +48,28 @@ type BenchmarkingParamsType struct { // to run in parallel. ContainersNumberParallel int `yaml:"containersNumberParallel"` + // ContainerBenchmarkTimeoutSeconds is the maximum number of seconds acceptable + // for a Container lifecycle benchmark to take. + ContainerBenchmarkTimeoutSeconds int `yaml:"containerBenchmarkTimeoutSeconds"` + // PodsNumber is the number of Pods to run as part of the pod-related benchmarks. PodsNumber int `yaml:"podsNumber"` // PodsNumberParallel is the maximum number of pod -related benchmarks // to run in parallel. PodsNumberParallel int `yaml:"podsNumberParallel"` + + // PodBenchmarkTimeoutSeconds is the maximum number of seconds acceptable + // for a Pod lifecycle benchmark to take. + PodBenchmarkTimeoutSeconds int `yaml:"podBenchmarkTimeoutSeconds"` + + // ImageBenchmarkTimeoutSeconds is the maximum of seconds acceptable for + // image-related benchmarks. + ImageBenchmarkTimeoutSeconds int `yaml:"imageBenchmarkTimeoutSeconds"` + + // ImageBenchmarkTimeoutSeconds is the maximum of seconds acceptable for + // benchmarks focused on Pod+Container start performance. + PodContainerStartBenchmarkTimeoutSeconds int `yaml:"podContainerStartBenchmarkTimeoutSeconds"` } // TestContextType is the type of test context.