Skip to content

Commit

Permalink
Parametrize benchmarking-related timeouts.
Browse files Browse the repository at this point in the history
Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
  • Loading branch information
aznashwan committed Mar 24, 2022
1 parent 04aeced commit ccf193d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
11 changes: 10 additions & 1 deletion pkg/benchmark/container.go
Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -61,7 +70,7 @@ var _ = framework.KubeDescribe("Container", func() {
}
resultsManager := NewLifecycleBenchmarksResultsManager(
resultsSet,
60,
timeout,
)
resultsChannel := resultsManager.StartResultsConsumer()

Expand Down
26 changes: 22 additions & 4 deletions pkg/benchmark/image.go
Expand Up @@ -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()

Expand Down Expand Up @@ -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],
Expand All @@ -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)

Expand All @@ -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)
})
})
11 changes: 10 additions & 1 deletion pkg/benchmark/pod.go
Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -60,7 +69,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
}
resultsManager := NewLifecycleBenchmarksResultsManager(
resultsSet,
60,
timeout,
)
resultsChannel := resultsManager.StartResultsConsumer()

Expand Down
14 changes: 13 additions & 1 deletion pkg/benchmark/pod_container.go
Expand Up @@ -25,6 +25,18 @@ import (
. "github.com/onsi/gomega"
)

const (
defaultPodContainerBenchmarkTimeoutSeconds = 5
)

func getPodContainerBenchmarkTimeoutSeconds() int {
timeout := defaultPodContainerBenchmarkTimeoutSeconds
if framework.TestContext.BenchmarkingParams.PodContainerStartBenchmarkTimeoutSeconds > 0 {
timeout = framework.TestContext.BenchmarkingParams.PodContainerStartBenchmarkTimeoutSeconds
}
return timeout
}

var _ = framework.KubeDescribe("PodSandbox", func() {
f := framework.NewDefaultCRIFramework()

Expand Down Expand Up @@ -68,7 +80,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("<", getPodContainerBenchmarkTimeoutSeconds()), "create PodSandbox shouldn't take too long.")
}, defaultOperationTimes)
})
})
16 changes: 16 additions & 0 deletions pkg/framework/test_context.go
Expand Up @@ -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.
Expand Down

0 comments on commit ccf193d

Please sign in to comment.