Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added load generator #11

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion dapr-distributed-calendar/kubernetes-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,21 @@ helm install redis bitnami/redis --namespace 12-factor-app --wait
# deploy the 12-factor-app
kubectl apply -f kubernetes/.

# setup locust for loadgeneration OPTIONAL
kubectl create configmap my-loadtest-locustfile --from-file locust/main.py -n 12-factor-app
helm repo add deliveryhero https://charts.deliveryhero.io/
helm repo update
helm install locust deliveryhero/locust \
--set loadtest.name=my-loadtest \
--set loadtest.locust_locustfile_configmap=my-loadtest-locustfile \
--set loadtest.locust_host=http://controller.12-factor-app:3000 \
--set master.environment.LOCUST_RUN_TIME=1m \
--set loadtest.environment.LOCUST_AUTOSTART="true" \
--namespace 12-factor-app \
--wait
kubectl apply -f locust/ingress.yaml

# get redis password (for manual interactions with the redis cli) OPTIONAL
kubectl get secret redis -n 12-factor-app -o jsonpath='{.data.redis-password}' | base64 --decode
redis_pwd=$(kubectl get secret redis -n 12-factor-app -o jsonpath='{.data.redis-password}' | base64 --decode)
echo The redis password is $redis_pwd
echo To authenticate use: redis-cli -a $redis_pwd
2 changes: 1 addition & 1 deletion dapr-distributed-calendar/kubernetes/node-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind: Service
apiVersion: v1
metadata:
name: controller
# namespace: 12-factor-app
namespace: 12-factor-app
labels:
app: controller
spec:
Expand Down
14 changes: 14 additions & 0 deletions dapr-distributed-calendar/locust/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: locust-ingress
namespace: 12-factor-app
spec:
entryPoints:
- web
routes:
- match: Host(`locust.<ENV-NAME>-<ENV-USER-ID>-01.<ENV-ANIMAL>.<ENV-DOMAIN>`) && PathPrefix(`/`)
kind: Rule
services:
- name: locust
port: 8089
49 changes: 49 additions & 0 deletions dapr-distributed-calendar/locust/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from locust import HttpUser, task, between

default_headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}

class EventsUser(HttpUser):
wait_time = between(5, 10) # Adjust the wait time between tasks as needed

@task
def event_lifecycle(self):
for event_id in range(100, 105):
# Create an event
headers = {
'Content-Type': 'application/json',
}

data = {
"data": {
"name": f"Event {event_id}",
"date": "TBD",
"id": str(event_id)
}
}

# Send the POST request to create an event
response = self.client.post('/newevent', json=data, headers=headers)

# Check if the request was successful
if response.status_code == 200:
print(f"Event {event_id} created successfully")
else:
print(f"Failed to create event {event_id}. Status code: {response.status_code}")

# Get the event
response = self.client.get('/event/{event_id}')

# Check if the request was successful
if response.status_code == 200:
print(f"Event {event_id} retrieved successfully")
else:
print(f"Failed to retrieve event {event_id}. Status code: {response.status_code}")

# Delete the event
response = self.client.delete('/event/{event_id}')

# Check if the request was successful
if response.status_code == 200:
print(f"Event {event_id} deleted successfully")
else:
print(f"Failed to delete event {event_id}. Status code: {response.status_code}")
Loading