Skip to content

Commit

Permalink
docs updated, applied comms
Browse files Browse the repository at this point in the history
  • Loading branch information
kkulak committed Mar 29, 2024
1 parent 3100262 commit 9681bc1
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ The desired state of a distributed Gatling load testing is described through a K

## Features

- Allows Gatling load testing scenario, resources, Gatling configurations files to be added in 2 ways:
- Allows Gatling load testing scenario, resources, Gatling configurations files to be added in 3 ways:
- Bundle them with Gatling runtime packages in a Gatling container
- Run the simulations through build tool plugin (e.g. `gradle gatlingRun`) in a Docker container
- Add them as multi-line definition in Gatling CR
- Scaling Gatling load testing
- Horizontal scaling: number of pods running in parallel during a load testing can be configured
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/gatling_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type TestScenarioSpec struct {

// (Optional) Gatling simulation format, supports `bundle` and `gradle`. Defaults to `bundle`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=bundle;gradle
SimulationsFormat string `json:"simulationsFormat,omitempty"`

// (Optional) Gatling Resources directory path where simulation files are stored. Defaults to `/opt/gatling/user-files/simulations`
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/gatling-operator.tech.zozo.com_gatlings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4099,6 +4099,9 @@ spec:
simulationsFormat:
description: (Optional) Gatling simulation format, supports `bundle`
and `gradle`. Defaults to `bundle`
enum:
- bundle
- gradle
type: string
startTime:
description: (Optional) Test Start time.
Expand Down
34 changes: 18 additions & 16 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ _Appears in:_

| Field | Description |
| --- | --- |
| `provider` _string_ | (Required) Provider specifies the cloud provider that will be used. Supported providers: `aws`, `gcp`, and `azure` |
| `provider` _string_ | (Required) Provider specifies the cloud provider that will be used.
Supported providers: `aws`, `gcp`, and `azure` |
| `bucket` _string_ | (Required) Storage Bucket Name. |
| `region` _string_ | (Optional) Region Name. |
| `env` _[EnvVar](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#envvar-v1-core) array_ | (Optional) Environment variables used for connecting to the cloud providers. |
Expand Down Expand Up @@ -82,7 +83,8 @@ _Appears in:_

| Field | Description |
| --- | --- |
| `provider` _string_ | (Required) Provider specifies notification service provider. Supported providers: `slack` |
| `provider` _string_ | (Required) Provider specifies notification service provider.
Supported providers: `slack` |
| `secretName` _string_ | (Required) The name of secret in which all key/value sets needed for the notification are stored. |


Expand Down Expand Up @@ -145,19 +147,19 @@ TestScenarioSpec defines the load testing scenario
_Appears in:_
- [GatlingSpec](#gatlingspec)

| Field | Description |
|--------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `startTime` _string_ | (Optional) Test Start time. |
| `parallelism` _integer_ | (Optional) Number of pods running at the same time. Defaults to `1` (Minimum `1`) |
| `simulationFormat` _string_ | (Optional) Simulation format, should be one of `bundle` / `gradle`. Defaults to `bundle`. In case `gradle` one is chosen, all bundle-specific properties (e.g. `simulationsDirectoryPath`) are ignored. |
| `simulationsDirectoryPath` _string_ | (Optional) Gatling Resources directory path where simulation files are stored. Defaults to `/opt/gatling/user-files/simulations` |
| `resourcesDirectoryPath` _string_ | (Optional) Gatling Simulation directory path where resources are stored. Defaults to `/opt/gatling/user-files/resources` |
| `resultsDirectoryPath` _string_ | (Optional) Gatling Results directory path where results are stored. Defaults to `/opt/gatling/results` |
| `simulationClass` _string_ | (Required) Simulation Class Name. |
| `simulationData` _object (keys:string, values:string)_ | (Optional) Simulation Data. |
| `resourceData` _object (keys:string, values:string)_ | (Optional) Resource Data. |
| `gatlingConf` _object (keys:string, values:string)_ | (Optional) Gatling Configurations. |
| `env` _[EnvVar](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#envvar-v1-core) array_ | (Optional) Environment variables used for running load testing scenario. |
| `volumeMounts` _[VolumeMount](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#volumemount-v1-core) array_ | (Optional) Pod volumes to mount into the container's filesystem. |
| Field | Description |
| --- | --- |
| `startTime` _string_ | (Optional) Test Start time. |
| `parallelism` _integer_ | (Optional) Number of pods running at the same time. Defaults to `1` (Minimum `1`) |
| `simulationsFormat` _string_ | (Optional) Gatling simulation format, supports `bundle` and `gradle`. Defaults to `bundle` |
| `simulationsDirectoryPath` _string_ | (Optional) Gatling Resources directory path where simulation files are stored. Defaults to `/opt/gatling/user-files/simulations` |
| `resourcesDirectoryPath` _string_ | (Optional) Gatling Simulation directory path where resources are stored. Defaults to `/opt/gatling/user-files/resources` |
| `resultsDirectoryPath` _string_ | (Optional) Gatling Results directory path where results are stored. Defaults to `/opt/gatling/results` |
| `simulationClass` _string_ | (Required) Simulation Class Name. |
| `simulationData` _object (keys:string, values:string)_ | (Optional) Simulation Data. |
| `resourceData` _object (keys:string, values:string)_ | (Optional) Resource Data. |
| `gatlingConf` _object (keys:string, values:string)_ | (Optional) Gatling Configurations. |
| `env` _[EnvVar](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#envvar-v1-core) array_ | (Optional) Environment variables used for running load testing scenario. |
| `volumeMounts` _[VolumeMount](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#volumemount-v1-core) array_ | (Optional) Pod volumes to mount into the container's filesystem. |


77 changes: 76 additions & 1 deletion docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ As described in Configuration Overview, there are 2 things that you need to cons

For `Gatling docker image`, you can use default image `ghcr.io/st-tech/gatling:latest`, or you can create custom image to use.

For `Gatling load testing related files`, you have 3 options:
For `Gatling load testing related files`, you have 4 options:

- Create custom image to bundle Gatling load testing files with Java runtime and Gatling standalone bundle package
- Create custom image to bundle all Gatling related files with a gradle gatling plugin
- Add Gatling load testing files as multi-line definitions in `.spec.testScenatioSpec` part of `Gatling CR`
- Set up persistent volume in `.persistentVolume` and `.persistentVolumeClaim` in `Gatling CR` and load test files from the persistent volume in Gatling load test files.

Expand Down Expand Up @@ -179,6 +180,80 @@ spec:
...omit...
```

### Create Custom Gatling Image with Gradle Gatling plugin

Example project can be found [here](https://github.com/gatling/gatling-gradle-plugin-demo-kotlin).

Let's start with cloning the repo:
```bash
git clone [email protected]:gatling/gatling-gradle-plugin-demo-kotlin.git
cd gatling-gradle-plugin-demo-kotlin
```

In order to run this example on Gatling Operator, we have to build a custom docker image with both gradle and gatling baked in.

Let's create a `Dockerfile` in the root directory of the `gatling-gradle-plugin-demo-kotlin` project:
```bash
FROM azul/zulu-openjdk:21-latest

# dependency versions
ENV GATLING_VERSION 3.10.5
ENV GRADLE_VERSION 8.7

# install gatling
RUN mkdir /opt/gatling && \
apt-get update && apt-get upgrade -y && apt-get install -y wget unzip && \
mkdir -p /tmp/downloads && \
wget -q -O /tmp/downloads/gatling-$GATLING_VERSION.zip \
https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/$GATLING_VERSION/gatling-charts-highcharts-bundle-$GATLING_VERSION-bundle.zip && \
mkdir -p /tmp/archive && cd /tmp/archive && \
unzip /tmp/downloads/gatling-$GATLING_VERSION.zip && \
mv /tmp/archive/gatling-charts-highcharts-bundle-$GATLING_VERSION/* /opt/gatling/ && \
rm -rf /opt/gatling/user-files/simulations/computerdatabase /tmp/*

# install gradle
RUN mkdir /opt/gradle && \
wget -q -O /tmp/gradle-$GRADLE_VERSION.zip https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip && \
unzip -d /opt/gradle /tmp/gradle-$GRADLE_VERSION.zip && \
rm -rf /tmp/*

# change context to gatling directory
WORKDIR /opt/gatling

# copy gradle files to gatling directory
COPY . .

# set environment variables
ENV PATH /opt/gatling/bin:/opt/gradle/gradle-$GRADLE_VERSION/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV GATLING_HOME /opt/gatling

ENTRYPOINT ["gatling.sh"]
```

Now we have to build the custom image:
```bash
# Build Docker image
docker build -t <your-registry>/gatling:<tag> .
# Push the image to your container registry
docker push <your-registry>/gatling:<tag>
```

Finally, specify the image in `.spec.podSpec.gatlingImage` of Gatling CR and change the value of property `testScenarioSpec.simulationsFormat` to use it in your distributed load testing.

```yaml
apiVersion: gatling-operator.tech.zozo.com/v1alpha1
kind: Gatling
metadata:
name: gatling-gradle
spec:
podSpec:
serviceAccountName: "gatling-operator-worker"
gatlingImage: <your-registry>/gatling:<tag>
testScenarioSpec:
simulationsFormat: gradle
...omit...
```

### Add Gatling Load Testing Files in Gatling CR

As explained previously, instead of bundling Gatling load testing files in the Gatling docker image, you can add them as multi-line definitions in `.spec.testScenatioSpec` of `Gatling CR`, based on which Gatling Controller automatically creates `ConfigMap` resources and injects Gatling runner Pod with the files.
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} %s %s
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
./gradlew -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
fi
GATLING_EXIT_STATUS=$?
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} -rm local
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
./gradlew -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
fi
GATLING_EXIT_STATUS=$?
Expand Down Expand Up @@ -144,7 +144,7 @@ fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} -nr -rm local
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
./gradlew -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} gatlingRun-${SIMULATION_CLASS}
fi
GATLING_EXIT_STATUS=$?
Expand Down

0 comments on commit 9681bc1

Please sign in to comment.