Skip to content

Commit

Permalink
feat: add locust
Browse files Browse the repository at this point in the history
Signed-off-by: DongYoung Kim <[email protected]>
  • Loading branch information
kwx4957 committed Jan 13, 2025
1 parent 34787f6 commit 35c0bb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
19 changes: 7 additions & 12 deletions chaoslib/litmus/locust-loadgen/lib/locust-loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,6 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
const volumeName = "script-volume"
const mountPath = "/mnt"

args := []string{
"--users", strconv.Itoa(experimentsDetails.Users),
"--spawn-rate", strconv.Itoa(experimentsDetails.SpawnRate),
"-H", experimentsDetails.Host,
"-t", strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
}

if experimentsDetails.ConfigMapName != "" {
args = append(args, "-f", mountPath+"/config.py")
}

helperPod := &corev1.Pod{
ObjectMeta: v1.ObjectMeta{
GenerateName: experimentsDetails.ExperimentName + "-helper-",
Expand All @@ -132,7 +121,13 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
"locust",
"--headless",
},
Args: args,
Args: []string{
"--users", strconv.Itoa(experimentsDetails.Users),
"--spawn-rate", strconv.Itoa(experimentsDetails.SpawnRate),
"-H", experimentsDetails.Host,
"-t", strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
"-f", mountPath + "/" + experimentsDetails.ConfigMapKey,
},
Resources: chaosDetails.Resources,
VolumeMounts: []corev1.VolumeMount{
{
Expand Down
7 changes: 7 additions & 0 deletions contribute/developer-guide/templates/chaoslib_helper.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
)

func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
// @TODO: setup tracing
// ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "experimentExecution[name-your-chaos]Fault")
// defer span.End()

// Get the target pod details for the chaos execution
// if the target pod is not defined it will derive the random target pod list using pod affected percentage
Expand Down Expand Up @@ -58,6 +61,10 @@ func experimentExecution(ctx context.Context, experimentsDetails *experimentType
}

func runChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
// @TODO: setup tracing
// ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "experimentExecution[name-your-chaos]Fault")
// defer span.End()

if experimentsDetails.EngineName != "" {
msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on target pod"
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
Expand Down
2 changes: 1 addition & 1 deletion pkg/load/locust-loadgen/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.ChaosNamespace = types.Getenv("CHAOS_NAMESPACE", "litmus")
experimentDetails.EngineName = types.Getenv("CHAOSENGINE", "")
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "10"))
experimentDetails.RampTime, _ = strconv.Atoi(types.Getenv("RAMP_TIME", "0"))
experimentDetails.Delay, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_DELAY", "2"))
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "locustio/locust")
experimentDetails.LIBImagePullPolicy = types.Getenv("LIB_IMAGE_PULL_POLICY", "Always")
experimentDetails.Host = types.Getenv("HOST", "")
experimentDetails.ConfigMapName = types.Getenv("CONFIG_MAP_NAME", "locust-script")
experimentDetails.ConfigMapKey = types.Getenv("CONFIG_MAP_KEY", "locust.py")
experimentDetails.Users, _ = strconv.Atoi(types.Getenv("USERS", "40"))
experimentDetails.SpawnRate, _ = strconv.Atoi(types.Getenv("SPAWN_RATE", "30"))
}
2 changes: 1 addition & 1 deletion pkg/load/locust-loadgen/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ type ExperimentDetails struct {
ChaosNamespace string
EngineName string
ChaosDuration int
ChaosInterval int
RampTime int
Delay int
Timeout int
LIBImage string
LIBImagePullPolicy string
Host string
ConfigMapName string
ConfigMapKey string
Users int
SpawnRate int
}

0 comments on commit 35c0bb0

Please sign in to comment.