Skip to content

Commit 64a5161

Browse files
author
Kyle
committed
Add an example load test, using the runCronWorkload command type.
1 parent 68d1614 commit 64a5161

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

examples/load-test/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Load Test
2+
This test comes in two parts:
3+
1. Server - A simple "Hello World" HTTP server provided by Control Plane
4+
2. Client - A Cron workload used to run load tests against the server on demand.
5+
6+
# How to Run the Load Test
7+
## Step 1: Create the client and server workloads
8+
To apply the server, run `cpln apply -f server.yaml --org {YOUR_ORG_NAME_HERE} --gvc load-test-server`
9+
To apply the client, run `cpln apply -f client.yaml --org {YOUR_ORG_NAME_HERE} --gvc load-test-client`
10+
11+
## Step 2: Create one or more load test commands
12+
The workload in `client.yaml` (`load-test-cron`) is created in a suspended state, which means it will only run when commanded to.
13+
This can be done by creating a `command` object in the Control Plane API. To create your first command, run:
14+
`cpln rest post /org/{YOUR_ORG_HERE}/gvc/load-test-client/workload/load-test-cron/-command --file simple-command.yaml`
15+
16+
This will begin a five-minute-long load test against the server workload. You can see the job execution in progress in the
17+
Control Plane Console. Navigate to the load-test-client gvc, click "Workloads" in the main navigation menu, click load-test-cron, and finally on "Job Executions".
18+
Note: the load test is only executing in the location specified in simple-command.yaml. To run a load test against all locations, you will need to create
19+
one command for each location.
20+
21+
### Customize the load test command
22+
This test uses a powerful load testing tool called [k6](https://k6.io). So, optionally, you can override the load test command to change (among other things)
23+
- The number of virtual users
24+
- The duration of the test
25+
- The test script itself
26+
27+
For an example, see `advanced-command.yaml`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "runCronWorkload",
3+
"spec":{
4+
"location":"aws-us-west-2",
5+
"containerOverrides":[
6+
{
7+
"name":"agent",
8+
"command": "/bin/sh",
9+
"args": ["-c", "k6 run --vus 100 --duration 15m /load-test/payload"]
10+
}
11+
]
12+
}
13+
}

examples/load-test/client.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
kind: gvc
2+
name: load-test-client
3+
description: load-test-client
4+
spec:
5+
staticPlacement:
6+
locationLinks:
7+
- //location/aws-eu-central-1
8+
- //location/aws-us-west-2
9+
- //location/azure-eastus2
10+
- //location/gcp-us-east1
11+
---
12+
13+
kind: secret
14+
name: load-test-script
15+
description: load-test-script
16+
tags: {}
17+
type: opaque
18+
data:
19+
encoding: plain
20+
payload: |-
21+
import http from 'k6/http';
22+
import { sleep } from 'k6';
23+
24+
export default function () {
25+
http.get('http://server.load-test-server.cpln.local:8080');
26+
}
27+
---
28+
29+
kind: identity
30+
name: load-test-client
31+
description: load-test-client
32+
tags: {}
33+
---
34+
35+
kind: policy
36+
name: load-test-client
37+
description: load-test-client
38+
tags: {}
39+
origin: default
40+
bindings:
41+
- permissions:
42+
- use
43+
- reveal
44+
principalLinks:
45+
- //gvc/load-test-client/identity/load-test-client
46+
targetKind: secret
47+
targetLinks:
48+
- //secret/load-test-script
49+
---
50+
51+
kind: workload
52+
name: load-test-cron
53+
description: load-test-cron
54+
spec:
55+
type: cron
56+
containers:
57+
- name: agent
58+
args:
59+
- '-c'
60+
- k6 run --vus 100 --duration 5m /load-test/payload
61+
command: /bin/sh
62+
volumes:
63+
- path: /load-test
64+
recoveryPolicy: retain
65+
uri: 'cpln://secret/load-test-script'
66+
cpu: 500m
67+
image: 'grafana/k6:0.47.0'
68+
inheritEnv: false
69+
memory: 512Mi
70+
defaultOptions:
71+
autoscaling:
72+
maxConcurrency: 0
73+
maxScale: 1
74+
minScale: 1
75+
scaleToZeroDelay: 300
76+
target: 95
77+
capacityAI: false
78+
debug: false
79+
suspend: true
80+
timeoutSeconds: 5
81+
firewallConfig:
82+
external:
83+
inboundAllowCIDR: []
84+
outboundAllowCIDR: []
85+
outboundAllowHostname: []
86+
outboundAllowPort: []
87+
internal:
88+
inboundAllowType: none
89+
inboundAllowWorkload: []
90+
identityLink: //identity/load-test-client
91+
job:
92+
concurrencyPolicy: Forbid
93+
historyLimit: 10
94+
restartPolicy: Never
95+
schedule: '0 0 1 1 *'
96+
localOptions: []
97+
supportDynamicTags: false

examples/load-test/server.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
kind: gvc
2+
name: load-test-server
3+
description: load-test-server
4+
spec:
5+
staticPlacement:
6+
locationLinks:
7+
- //location/aws-eu-central-1
8+
- //location/aws-us-west-2
9+
- //location/azure-eastus2
10+
- //location/gcp-us-east1
11+
---
12+
13+
kind: workload
14+
name: server
15+
description: server
16+
spec:
17+
type: standard
18+
containers:
19+
- name: agent
20+
cpu: 250m
21+
image: 'kylecupp/agent:0.7.0'
22+
inheritEnv: false
23+
memory: 256Mi
24+
ports:
25+
- number: 8080
26+
protocol: http
27+
defaultOptions:
28+
autoscaling:
29+
maxConcurrency: 0
30+
maxScale: 5
31+
metric: cpu
32+
minScale: 2
33+
scaleToZeroDelay: 300
34+
target: 50
35+
capacityAI: false
36+
debug: false
37+
suspend: false
38+
timeoutSeconds: 5
39+
firewallConfig:
40+
external:
41+
inboundAllowCIDR:
42+
- 0.0.0.0/0
43+
outboundAllowCIDR: []
44+
outboundAllowHostname: []
45+
outboundAllowPort: []
46+
internal:
47+
inboundAllowType: same-org
48+
inboundAllowWorkload: []
49+
localOptions: []
50+
supportDynamicTags: false
51+
52+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "runCronWorkload",
3+
"spec":{
4+
"location":"aws-us-west-2"
5+
}
6+
}

0 commit comments

Comments
 (0)