Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Commit e77b1ea

Browse files
christian-kreuzberger-dtxMeg McRoberts
andauthored
feat: Added Keptn 0.17 jmeter integration based on job-executor (#172)
* feat:: Added Keptn 0.17 jmeter integration based on job-executor Signed-off-by: Christian Kreuzberger <[email protected]> * Apply suggestions from code review Co-authored-by: Meg McRoberts <[email protected]> Signed-off-by: Christian Kreuzberger <[email protected]> Co-authored-by: Meg McRoberts <[email protected]>
1 parent f7ed30f commit e77b1ea

File tree

3 files changed

+221
-0
lines changed

3 files changed

+221
-0
lines changed

jmeter/0.3.0/README.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# JMeter Job-Executor Integration
2+
3+
This integration shows you how to leverage [Job-executor-service](https://github.com/keptn-contrib/job-executor-service) for running load tests using `JMeter` on your Kubernetes cluster.
4+
5+
**Please note, that the instructions provided here enable you to run and configure your Kubernetes deployments using the job-executor-service. They are in no way intended to be a complete reference of Kubernetes, nor JMeter, nor Keptn.**
6+
7+
## Installation and Configuration
8+
9+
### Step 1: Install the Job-Executor in your cluster
10+
11+
Install [Job-Executor](https://github.com/keptn-contrib/job-executor-service) in a version compatible with your Keptn installation (see [GitHub Releases page](https://github.com/keptn-contrib/job-executor-service/releases), e.g., version 0.2.5 is compatible with Keptn 0.17.x), and make sure it is subscribed to the following Keptn Cloud Events:
12+
13+
* `sh.keptn.event.test.triggered`
14+
15+
This can verified in Keptn Bridge -> Project -> Settings -> Integrations -> job-executor-service.
16+
17+
**Example Installation Instructions**
18+
Please update `JES_VERSION` and `JES_NAMESPACE` in the example below according to your needs.
19+
20+
```bash
21+
TASK_SUBSCRIPTION='sh.keptn.event.test.triggered'
22+
JES_VERSION=0.2.5
23+
JES_NAMESPACE=keptn-jes
24+
25+
helm upgrade --install --create-namespace -n ${JES_NAMESPACE} \
26+
job-executor-service https://github.com/keptn-contrib/job-executor-service/releases/download/${JES_VERSION}/job-executor-service-${JES_VERSION}.tgz \
27+
--set remoteControlPlane.autoDetect.enabled="true",remoteControlPlane.topicSubscription="${TASK_SUBSCRIPTION}",remoteControlPlane.api.token="",remoteControlPlane.api.hostname="",remoteControlPlane.api.protocol=""
28+
```
29+
30+
**If you have installed jmeter-service, uninstall it**
31+
32+
```bash
33+
helm uninstall jmeter-service -n keptn
34+
```
35+
36+
### Step 2: Build your own JMeter Docker image
37+
38+
Since there are no official JMeter Docker images, we recommend that you build and customize your own. Here is a Dockerfile with a basic JMeter installation, feel free to adapt it!
39+
40+
```docker
41+
FROM alpine:3.15
42+
ENV env=production
43+
ARG JMETER_VERSION="5.4.3"
44+
ENV JMETER_HOME /opt/apache-jmeter-${JMETER_VERSION}
45+
ENV JMETER_BIN ${JMETER_HOME}/bin
46+
ENV JMETER_DOWNLOAD_URL https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-${JMETER_VERSION}.tgz
47+
48+
# Install extra packages
49+
# See https://github.com/gliderlabs/docker-alpine/issues/136#issuecomment-272703023
50+
# Change TimeZone TODO: TZ still is not set!
51+
ARG TZ="Europe/Amsterdam"
52+
RUN apk update \
53+
&& apk upgrade \
54+
&& apk add ca-certificates libc6-compat \
55+
&& update-ca-certificates \
56+
&& apk add --update openjdk8-jre tzdata curl unzip bash \
57+
&& apk add --no-cache nss \
58+
&& rm -rf /var/cache/apk/*
59+
60+
# install jmeter
61+
RUN mkdir -p /tmp/dependencies \
62+
&& curl -L --silent ${JMETER_DOWNLOAD_URL} > /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz \
63+
&& mkdir -p /opt \
64+
&& tar -xzf /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz -C /opt \
65+
&& rm -rf /tmp/dependencies
66+
67+
# Set global PATH such that "jmeter" command is found
68+
ENV PATH $PATH:$JMETER_BIN
69+
70+
# Entrypoint has same signature as "jmeter" command
71+
COPY entrypoint.sh /
72+
73+
WORKDIR /keptn/jmeter
74+
75+
RUN chmod +x /entrypoint.sh
76+
77+
ENTRYPOINT ["/entrypoint.sh"]
78+
```
79+
80+
The `entrypoint.sh` file executes JMeter using the passed arguments. You can also uncomment the commands below to enable some debugging steps.
81+
82+
```bash
83+
#!/bin/bash
84+
echo "jmeter args=$@"
85+
86+
echo "START Running Jmeter on `date`"
87+
88+
jmeter $@
89+
90+
echo "END Running Jmeter on `date`"
91+
92+
# Uncomment lines below for debug output
93+
# echo "Test.log"
94+
# cat /keptn/jmeter/test.log
95+
96+
# echo "log.tlf"
97+
# cat /keptn/jmeter/log.tlf
98+
```
99+
100+
Now you will need to build the Docker image and push it to your image registry, e.g., `docker.io/yourorg/jmeter:latest`.
101+
102+
```bash
103+
docker build -t docker.io/yourorg/jmeter:latest .
104+
docker push docker.io/yourorg/jmeter:latest
105+
```
106+
107+
### Step 3: Make sure your project is set up properly with the right tasks.
108+
109+
While technically not part of the installation instructions, it is worthwhile to mention the coupling between the Keptn shipyard file, and the respective Cloud Event Types configured for Job Executor.
110+
111+
For example, you should already have a monitoring provider (e.g,. Prometheus) configured for `evaluation` tasks. In addition, your shipyard should contain one or more stages with a `delivery` sequence. Last but not least, the example below also contains a `deployment` step. You can skip this, and just adapt the `JSERVER_URL` in the job-executor config below.
112+
113+
Example:
114+
```yaml
115+
apiVersion: "spec.keptn.sh/0.2.2"
116+
kind: "Shipyard"
117+
metadata:
118+
name: "shipyard-delivery"
119+
spec:
120+
stages:
121+
- name: "qa"
122+
sequences:
123+
- name: "delivery"
124+
tasks:
125+
- name: "deployment"
126+
- name: "test"
127+
properties:
128+
teststrategy: performance
129+
```
130+
131+
### Step 4: Add the Job-Executor configuration file
132+
133+
The following Job Executor configuration (referred to as job config or `job/config.yaml`) allows you to run jmeter with the `load.jmx` file (e.g., from the [Keptn Carts example](https://github.com/keptn/examples/tree/master/onboarding-carts/jmeter)) used whenever a `test.triggered` with `teststrategy=performance` event is sent by Keptn.
134+
135+
Add the following content to a file called *jmeter-job-config.yaml* in your current working directory:
136+
```yaml
137+
apiVersion: v2
138+
actions:
139+
- name: "Run JMeter"
140+
events:
141+
- name: "sh.keptn.event.test.triggered"
142+
jsonpath:
143+
property: "$.data.test.teststrategy"
144+
match: "performance"
145+
tasks:
146+
- name: "Run jmeter smoke tests"
147+
files:
148+
- jmeter/load.jmx
149+
image: "docker.io/yourorg/jmeter:latest"
150+
args:
151+
- '-n'
152+
- '-t'
153+
- '/keptn/jmeter/load.jmx'
154+
- '-JPROTOCOL=http'
155+
- '-JSERVER_PROTOCOL=http'
156+
- '-JVUCount=10'
157+
- '-JLoopCount=10'
158+
- '-JSERVER_URL=$(KEPTN_SERVICE).$(KEPTN_PROJECT)-$(KEPTN_STAGE).svc.cluster.local'
159+
- '-j'
160+
- '/keptn/jmeter/test.log'
161+
- '-l'
162+
- '/keptn/jmeter/log.tlf'
163+
```
164+
165+
Add the job-executor configuration file to your Keptn service and stage:
166+
167+
```bash
168+
PROJECT=sockshop
169+
SERVICE=carts
170+
171+
keptn add-resource --project=$PROJECT --service=$SERVICE --stage=staging --resource=jmeter-job-config.yaml --resourceUri=job/config.yaml
172+
```
173+
174+
## Run it
175+
176+
Now the Job-Executor-Service executes the JMeter tests whenever you trigger a delivery, e.g.,
177+
```bash
178+
IMAGE="docker.io/keptnexamples/carts"
179+
VERSION=0.13.1
180+
181+
keptn trigger delivery --project=$PROJECT --service=$SERVICE --stage=staging --image=$IMAGE:$VERSION --labels=version=$VERSION
182+
```
183+
184+
Eventually you should see the `deployment` and `test` events in Keptn Bridge:
185+
186+
![](https://raw.githubusercontent.com/keptn-sandbox/artifacthub/main/jmeter/0.3.0/images/keptn-bridge.png)
187+
188+
189+
## Limitations
190+
191+
Currently, there are a few open problems when using jmeter via Job Executor Service:
192+
193+
- JMeter CLI does not throw an error when the tests fail but instead just returns the results. These results cannot be evaluated directly in JMeter.
194+
- Tests towards a non-existing or non-reachable endpoint take a very long time (15+ min) and currently don't have a timeout.
195+
196+
## Feedback
197+
198+
If you have any feedback or additional examples please let us know. The best way is to either leave a comment on this Git repo, do a PR or join our conversation in the [Keptn Slack Channel](https://slack.keptn.sh)

jmeter/0.3.0/artifacthub-pkg.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Artifact Hub package metadata file
2+
# https://github.com/artifacthub/hub/blob/master/docs/metadata/artifacthub-pkg.yml
3+
version: 0.3.0
4+
name: jmeter
5+
displayName: JMeter Job-Executor Integration
6+
createdAt: 2022-09-15T09:00:00Z
7+
digest: 2022-09-15T09:00:00Z
8+
description: Running JMeter tests using the Job-Executor service
9+
logoURL: https://jmeter.apache.org/images/logo.svg
10+
license: Apache-2.0
11+
homeURL: https://keptn.sh/docs/integrations/
12+
keywords:
13+
- keptn
14+
- job-executor
15+
- jmeter
16+
- sandbox
17+
- testing
18+
recommendations:
19+
- url: https://artifacthub.io/packages/helm/keptn/keptn
20+
annotations:
21+
keptn/kind: "testing"
22+
keptn/org: "keptn"
23+
keptn/version: "0.17.x"
19 KB
Loading

0 commit comments

Comments
 (0)