st-tech / gatling-operator

Automating distributed Gatling load testing using Kubernetes operator
MIT License
68 stars 21 forks source link

Gatling container exit status #81

Closed cin closed 10 months ago

cin commented 1 year ago

Given that the last command executed after a Gatling simulation has completed is to touch a file, the container will always succeed (even when gatling failed or its assertions failed). Normally this wouldn't matter, but I'm trying to use the Gatling operator as a part of our end-to-end tests. I need to know if any of the requests fail; so when the Gatling assertion fails, it will mark the container as failed. I can then pick that up in our CI tool (GHA in this case) and act accordingly.

https://github.com/st-tech/gatling-operator/blob/main/pkg/commands/commands.go#L75

Maybe do something like this instead?

gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s %s -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} %s

GATLING_EXIT_STATUS=$?
if [ $GATLING_EXIT_STATUS -ne 0 ]; then
  RUN_STATUS_FILE="${RESULTS_DIR_PATH}/FAILED"
  echo "gatling.sh has failed!" 1>&2
fi
touch ${RUN_STATUS_FILE}
exit $GATLING_EXIT_STATUS

EDIT: you also have to set the JobSpec.BackoffLimit to 0. Otherwise failed pods from jobs will get restarted, and I typically wouldn't want to restart Gatling scenarios.