Skip to content

Commit 35c0bb0

Browse files
committed
feat: add locust
Signed-off-by: DongYoung Kim <[email protected]>
1 parent 34787f6 commit 35c0bb0

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

chaoslib/litmus/locust-loadgen/lib/locust-loadgen.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,6 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
102102
const volumeName = "script-volume"
103103
const mountPath = "/mnt"
104104

105-
args := []string{
106-
"--users", strconv.Itoa(experimentsDetails.Users),
107-
"--spawn-rate", strconv.Itoa(experimentsDetails.SpawnRate),
108-
"-H", experimentsDetails.Host,
109-
"-t", strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
110-
}
111-
112-
if experimentsDetails.ConfigMapName != "" {
113-
args = append(args, "-f", mountPath+"/config.py")
114-
}
115-
116105
helperPod := &corev1.Pod{
117106
ObjectMeta: v1.ObjectMeta{
118107
GenerateName: experimentsDetails.ExperimentName + "-helper-",
@@ -132,7 +121,13 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
132121
"locust",
133122
"--headless",
134123
},
135-
Args: args,
124+
Args: []string{
125+
"--users", strconv.Itoa(experimentsDetails.Users),
126+
"--spawn-rate", strconv.Itoa(experimentsDetails.SpawnRate),
127+
"-H", experimentsDetails.Host,
128+
"-t", strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
129+
"-f", mountPath + "/" + experimentsDetails.ConfigMapKey,
130+
},
136131
Resources: chaosDetails.Resources,
137132
VolumeMounts: []corev1.VolumeMount{
138133
{

contribute/developer-guide/templates/chaoslib_helper.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
)
2121

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

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

6063
func runChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
64+
// @TODO: setup tracing
65+
// ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "experimentExecution[name-your-chaos]Fault")
66+
// defer span.End()
67+
6168
if experimentsDetails.EngineName != "" {
6269
msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on target pod"
6370
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)

pkg/load/locust-loadgen/environment/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
1313
experimentDetails.ChaosNamespace = types.Getenv("CHAOS_NAMESPACE", "litmus")
1414
experimentDetails.EngineName = types.Getenv("CHAOSENGINE", "")
1515
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
16-
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "10"))
1716
experimentDetails.RampTime, _ = strconv.Atoi(types.Getenv("RAMP_TIME", "0"))
1817
experimentDetails.Delay, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_DELAY", "2"))
1918
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
2019
experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "locustio/locust")
2120
experimentDetails.LIBImagePullPolicy = types.Getenv("LIB_IMAGE_PULL_POLICY", "Always")
2221
experimentDetails.Host = types.Getenv("HOST", "")
2322
experimentDetails.ConfigMapName = types.Getenv("CONFIG_MAP_NAME", "locust-script")
23+
experimentDetails.ConfigMapKey = types.Getenv("CONFIG_MAP_KEY", "locust.py")
2424
experimentDetails.Users, _ = strconv.Atoi(types.Getenv("USERS", "40"))
2525
experimentDetails.SpawnRate, _ = strconv.Atoi(types.Getenv("SPAWN_RATE", "30"))
2626
}

pkg/load/locust-loadgen/types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ type ExperimentDetails struct {
66
ChaosNamespace string
77
EngineName string
88
ChaosDuration int
9-
ChaosInterval int
109
RampTime int
1110
Delay int
1211
Timeout int
1312
LIBImage string
1413
LIBImagePullPolicy string
1514
Host string
1615
ConfigMapName string
16+
ConfigMapKey string
1717
Users int
1818
SpawnRate int
1919
}

0 commit comments

Comments
 (0)