Skip to content

Commit

Permalink
Chore(stress-chaos): Run CPU chaos with percentage of cpu cores (#482)
Browse files Browse the repository at this point in the history
* Chore(stress-chaos): Run CPU chaos with percentage of cores

Signed-off-by: uditgaurav <[email protected]>
  • Loading branch information
uditgaurav authored Feb 16, 2022
1 parent 4bd3845 commit 027cad6
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chao
Args: []string{
"--cpu",
strconv.Itoa(experimentsDetails.NodeCPUcores),
"--cpu-load",
strconv.Itoa(experimentsDetails.CPULoad),
"--timeout",
strconv.Itoa(experimentsDetails.ChaosDuration),
},
Expand Down
2 changes: 2 additions & 0 deletions chaoslib/litmus/stress-chaos/helper/stress-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func prepareStressor(experimentDetails *experimentTypes.ExperimentDetails) []str
"Timeout": experimentDetails.ChaosDuration,
})
stressArgs = append(stressArgs, "--cpu "+strconv.Itoa(experimentDetails.CPUcores))
stressArgs = append(stressArgs, " --cpu-load "+strconv.Itoa(experimentDetails.CPULoad))

case "pod-memory-stress":

Expand Down Expand Up @@ -510,6 +511,7 @@ func getENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.ContainerRuntime = types.Getenv("CONTAINER_RUNTIME", "")
experimentDetails.SocketPath = types.Getenv("SOCKET_PATH", "")
experimentDetails.CPUcores, _ = strconv.Atoi(types.Getenv("CPU_CORES", ""))
experimentDetails.CPULoad, _ = strconv.Atoi(types.Getenv("CPU_LOAD", ""))
experimentDetails.FilesystemUtilizationPercentage, _ = strconv.Atoi(types.Getenv("FILESYSTEM_UTILIZATION_PERCENTAGE", ""))
experimentDetails.FilesystemUtilizationBytes, _ = strconv.Atoi(types.Getenv("FILESYSTEM_UTILIZATION_BYTES", ""))
experimentDetails.NumberOfWorkers, _ = strconv.Atoi(types.Getenv("NUMBER_OF_WORKERS", ""))
Expand Down
1 change: 1 addition & 0 deletions chaoslib/litmus/stress-chaos/lib/stress-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName st
SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName).
SetEnv("SOCKET_PATH", experimentsDetails.SocketPath).
SetEnv("CPU_CORES", strconv.Itoa(experimentsDetails.CPUcores)).
SetEnv("CPU_LOAD", strconv.Itoa(experimentsDetails.CPULoad)).
SetEnv("FILESYSTEM_UTILIZATION_PERCENTAGE", strconv.Itoa(experimentsDetails.FilesystemUtilizationPercentage)).
SetEnv("FILESYSTEM_UTILIZATION_BYTES", strconv.Itoa(experimentsDetails.FilesystemUtilizationBytes)).
SetEnv("NUMBER_OF_WORKERS", strconv.Itoa(experimentsDetails.NumberOfWorkers)).
Expand Down
1 change: 1 addition & 0 deletions pkg/generic/node-cpu-hog/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
experimentDetails.NodeCPUcores, _ = strconv.Atoi(types.Getenv("NODE_CPU_CORE", "0"))
experimentDetails.CPULoad, _ = strconv.Atoi(types.Getenv("CPU_LOAD", "100"))
experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "litmuschaos/go-runner:latest")
experimentDetails.LIBImagePullPolicy = types.Getenv("LIB_IMAGE_PULL_POLICY", "Always")
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO", "")
Expand Down
1 change: 1 addition & 0 deletions pkg/generic/node-cpu-hog/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ExperimentDetails struct {
ChaosNamespace string
ChaosPodName string
NodeCPUcores int
CPULoad int
RunID string
LIBImage string
LIBImagePullPolicy string
Expand Down
3 changes: 2 additions & 1 deletion pkg/generic/stress-chaos/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails, expName string

switch expName {
case "pod-cpu-hog":
experimentDetails.CPUcores, _ = strconv.Atoi(types.Getenv("CPU_CORES", "1"))
experimentDetails.CPUcores, _ = strconv.Atoi(types.Getenv("CPU_CORES", "0"))
experimentDetails.CPULoad, _ = strconv.Atoi(types.Getenv("CPU_LOAD", "100"))
experimentDetails.StressType = "pod-cpu-stress"

case "pod-memory-hog":
Expand Down
1 change: 1 addition & 0 deletions pkg/generic/stress-chaos/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ExperimentDetails struct {
Sequence string
TerminationGracePeriodSeconds int
CPUcores int
CPULoad int
FilesystemUtilizationPercentage int
FilesystemUtilizationBytes int
NumberOfWorkers int
Expand Down

0 comments on commit 027cad6

Please sign in to comment.