Skip to content

Commit

Permalink
Upgraded Locusat and small fixes to some tests (#14)
Browse files Browse the repository at this point in the history
* Upgraded Locust to version 2.31.8 for local development. Upgraded Python to 3.12. Added instructions for using pyenv.

* Fixed some load tests that were missing trailing slashes or using the incorrect http verb. Namely create project and logout tasks.

* Upgraded linting and other tools in the pre-commit action. Also fixed some formatting errors in a test file.

* Upgraded the checkout task in the CI action.

* Upgraded Locust and locust-plugins also in the custom docker image.
  • Loading branch information
alfredeen authored Oct 4, 2024
1 parent cb85bf1 commit e0e3e6c
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
HADOLINT_RECURSIVE: "true"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: "Dockerfile*"
Expand All @@ -33,6 +33,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build source --file source/Dockerfile --tag ci:$(date +%s)
10 changes: 5 additions & 5 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ on:

jobs:
pre_commit:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pre-commit==3.3.3
python -m pip install --upgrade pre-commit==3.7.1
- name: Run pre-commit
run: pre-commit run --all-files
2 changes: 2 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "main" ]
paths-ignore:
- '**.md'
- 'argocd/**'
- 'manifests/**'
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ docs/_build/
.pybuilder/
target/

# pyenv
.python-version

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
Expand Down
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,38 @@ Make changes in the develop branch, commit and submit pull requests to merge to

## Setup for local development

### Using virtual environments with venv

cd ./source
python3 -m venv .venv
source ./.venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt

### Using pyenv

cd ./source
pyenv virtualenv 3.12.2 locust-3.12.2
pyenv local locust-3.12.2
pyenv version
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt

### Check the Locust version

locust -V

## Configuration options

To configure the test runs, use the Locust configuration file ./source/locust.conf
For options, see the [Locust docs](https://docs.locust.io/en/stable/configuration.html)

You can override all of the settings set in the configuration file by setting the same
on the command line. For example, to override the log level settings use --loglevel as in example:

locust --headless -f ./tests/test_verify_setup.py --loglevel debug


## Create tests

Create locust tests in the /source/tests directory.
Expand All @@ -45,13 +64,13 @@ Open the generated html report and verify that there are no errors and that the

Run the command

locust --config locust-ui.conf --modern-ui --class-picker -f ./tests/test_verify_setup.py --html ./reports/locust-report-verify-setup-ui.html
locust --config locust-ui.conf --class-picker -f ./tests/test_verify_setup.py --html ./reports/locust-report-verify-setup-ui.html

Open a browser tab at URL http://localhost:8089/

Paste in as host

https://staging.serve-dev.scilifelab.se
https://serve-dev.scilifelab.se

## Verify the setup and access to a host (URL)

Expand Down Expand Up @@ -80,7 +99,10 @@ Move into the source directory if not already there:
cd ./source

- Copy the template environment file .env.template as .env
- Edit the followinf values in the .env file according to your needs.

cp ./.env.template .env

- Edit the following values in the .env file according to your needs.

- SERVE_LOCUST_TEST_USER_PASS=(The password of the test locust users)
- SERVE_LOCUST_DO_CREATE_OBJECTS=(A boolean indicating whether to create objects in Serve such as projects and apps)
Expand All @@ -97,11 +119,15 @@ Use minimum 10 users for the Normal test plan

locust --headless -f ./tests/test_plan_normal.py --html ./reports/locust-report-normal.html --users 10 --run-time 30s

Or using the Web UI

locust --config locust-ui.conf --class-picker -f ./tests/test_plan_normal.py --html ./reports/locust-report-normal-ui.html --users 10 --run-time 30s


### To run the Classroom test plan/scenario

locust --headless -f ./tests/test_plan_classroom.py --html ./reports/locust-report-classroom.html --users 1 --run-time 30s


## Tests under development

These tests are not yet ready to be used in a load testing session.
Expand Down Expand Up @@ -156,9 +182,9 @@ Copy the environment variables template file to .env and edit as needed. Then ru

cd ./source

docker build -t serve-load-testing .
docker build -t serve-load-testing:dev .

docker run -p 8089:8089 --env-file ./.env serve-load-testing
docker run -p 8089:8089 --env-file ./.env serve-load-testing:dev


## Deploy to a kubernetes cluster in a production environment
Expand Down Expand Up @@ -190,7 +216,7 @@ More specifically, we use the dashboards feature or locust-plugins. See

https://github.com/SvenskaSpel/locust-plugins/tree/master/locust_plugins/dashboards

To setup locust-plugins, there is an option or use locust-compose or manually setup. We use manual setup so that the
To setup locust-plugins, there is an option to use locust-compose or manually setup. We use manual setup so that the
dashboards can always be running.

locust-plugins is integrated in the production version of this project (deployed to kubernetes using k8s manifests and a built docker image) but not used in local development. However the dashboards can be installed locally using:
Expand Down
2 changes: 1 addition & 1 deletion manifests/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: locust
image: ghcr.io/scilifelabdatacentre/serve-load-testing:main-20240429-1418
image: ghcr.io/scilifelabdatacentre/serve-load-testing:main-20240503-1109
ports:
- containerPort: 8089
envFrom:
Expand Down
10 changes: 6 additions & 4 deletions manifests/base/postgres-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ spec:
name: postgres-secret
ports:
- containerPort: 5432
capabilities:
drop: ["ALL"]
resources:
limits:
cpu: "1"
memory: "1Gi"
cpu: "2"
memory: "5Gi"
requests:
cpu: "250m"
memory: "64Mi"
cpu: "500m"
memory: "1Gi"
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
Expand Down
8 changes: 8 additions & 0 deletions manifests/base/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: locust-secrets
type: Opaque
data:
LOCUST_WEB_HOST: MC4wLjAuMA==
SERVE_USERNAME: Y2hhbmdlLW1l
SERVE_PASS: Y2hhbmdlLW1l
SERVE_LOCUST_TEST_USER_PASS: cGFzc3dvcmQxMjM=
Expand All @@ -13,3 +14,10 @@ data:
PGPORT: NTQzMg==
PGUSER: cG9zdGdyZXM=
PGPASSWORD: Q2JpNk42RWVSUGc2RTdC
---
apiVersion: v1
kind: Secret
metadata:
name: locust-ui-secret
data:
auth: Y2hhbmdlLW1l
2 changes: 1 addition & 1 deletion manifests/built/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: locust
image: ghcr.io/scilifelabdatacentre/serve-load-testing:main-20240429-1418
image: ghcr.io/scilifelabdatacentre/serve-load-testing:main-20240503-1109
ports:
- containerPort: 8089
envFrom:
Expand Down
8 changes: 4 additions & 4 deletions manifests/built/postgres-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ spec:
- containerPort: 5432
resources:
limits:
cpu: "1"
memory: "1Gi"
cpu: "2"
memory: "5Gi"
requests:
cpu: "250m"
memory: "64Mi"
cpu: "500m"
memory: "1Gi"
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
Expand Down
13 changes: 9 additions & 4 deletions manifests/overlays/production/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ metadata:
name: locust-secrets
type: Opaque
data:
LOCUST_WEB_HOST: MC4wLjAuMA==
SERVE_USERNAME: Y2hhbmdlLW1l
SERVE_PASS: Y2hhbmdlLW1l
SERVE_LOCUST_TEST_USER_PASS: cGFzc3dvcmQxMjM=
SERVE_LOCUST_DO_CREATE_OBJECTS: ZmFsc2U=
PROTECTED_PAGE_RELATIVE_URL: Y2hhbmdlLW1l
PGHOST: cG9zdGdyZXMtc2VydmljZS5sb2N1c3Quc3ZjLmNsdXN0ZXIubG9jYWw=
PGPORT: NTQzMg==
PGUSER: cG9zdGdyZXM=
PGPASSWORD: Q2JpNk42RWVSUGc2RTdC
---
apiVersion: v1
kind: Service
Expand All @@ -19,8 +24,8 @@ spec:
selector:
app: locust
ports:
- protocol: TCP
- name: web
protocol: TCP
port: 80
targetPort: 8089
type: ClusterIP
Expand All @@ -32,13 +37,13 @@ metadata:
namespace: locust
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-issuer"
cert-manager.io/cluster-issuer: "letsencrypt-prod" #"letsencrypt-issuer"
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: locust-ui-secret
nginx.ingress.kubernetes.io/auth-realm: "Protected area"
spec:
rules:
- host: locust.serve-dev.scilifelab.se
- host: locust.serve-dev.scilifelab-1-dev.sys.kth.se
http:
paths:
- pathType: Prefix
Expand All @@ -51,5 +56,5 @@ spec:
#ingressClassName: nginx
tls:
- hosts:
- locust.serve-dev.scilifelab.se
- locust.serve-dev.scilifelab-1-dev.sys.kth.se
secretName: locust-tls
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

[project]
name = "serve-load-testing"
version = "1.0.0"
version = "1.0.1"
description = "Load testing of the SciLifeLab Serve platform."
requires-python = "=3.8"
requires-python = "=3.12"
keywords = ["load testing", "locust", "python"]

[tool.isort]
profile = 'black'

[tool.black]
line-length = 120
target-version = ['py38']
target-version = ['py312']
include = '\.pyi?$'
extend-exclude = '''
/(
Expand All @@ -29,7 +29,7 @@ extend-exclude = '''

[tool.mypy]
strict = false
python_version = "3.8"
python_version = "3.12"
ignore_missing_imports = true
warn_return_any = true
exclude = ["venv", ".venv", "examples"]
Expand Down
7 changes: 5 additions & 2 deletions source/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Use the Locust image as the base image
FROM locustio/locust:2.25.0
FROM locustio/locust:2.31.8

WORKDIR /home/locust

# Install the locust-plugins dashboards plugin
RUN pip3 install --no-cache-dir locust-plugins[dashboards]==4.4.2
RUN pip3 install --no-cache-dir locust-plugins[dashboards]==4.5.3

# Copy the Locust files into the container
COPY --chown=locust:locust locust-ui.conf locust.conf
COPY --chown=locust:locust tests/ tests
COPY --chown=locust:locust tests-dev/ tests-dev
COPY --chown=locust:locust start-script.sh start-script.sh
COPY --chown=locust:locust run_test_plan.sh run_test_plan.sh

RUN chmod ug+x start-script.sh
RUN chmod ug+x run_test_plan.sh

EXPOSE 8089 5557
3 changes: 2 additions & 1 deletion source/locust-ui.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# locust-ui.conf
locustfile = tests/test_plan_normal.py
headless = false
class-picker = true
#master = true
#expect-workers = 5
only-summary = true
csv = stats/locust
loglevel = INFO
# Can be overridden in UI:
host = https://staging.serve-dev.scilifelab.se
host = https://serve-staging.serve-dev.scilifelab.se
users = 1
spawn-rate = 1
run-time = 10s
2 changes: 1 addition & 1 deletion source/locust.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ locustfile = tests
#headless = true
#master = true
#expect-workers = 5
host = https://serve-dev.scilifelab.se
host = https://serve-staging.serve-dev.scilifelab.se
users = 1
spawn-rate = 1
run-time = 10s
Expand Down
2 changes: 1 addition & 1 deletion source/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
locust>=2.20.0
locust>=2.31.8
requests-html>=0.10.0
8 changes: 5 additions & 3 deletions source/tests-dev/appviewer_requestshtml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Handles opening user apps.
This implementation does not use Locust and does not work with Locust.
This implementation does not use Locust and does not work through Locust.
It can however be run concurrently with Locust load tests to put additional
realistic load on the system.
Note that shiny proxy pods are configured with
- heartbeat-rate=10s
Expand All @@ -22,8 +24,8 @@

# The user app URLs to open in succession
URL_LIST = [
# "https://loadtest-shinyproxy.serve-dev.scilifelab.se/app/loadtest-shinyproxy"
"https://loadtest-shinyproxy2.staging.serve-dev.scilifelab.se/app/loadtest-shinyproxy2"
"https://loadtest-shinyproxy.serve-dev.scilifelab.se/app/loadtest-shinyproxy"
# "https://loadtest-shinyproxy.serve-staging.serve-dev.scilifelab.se/app/loadtest-shinyproxy"
# "https://demo-bayesianlinmod.serve.scilifelab.se/app/demo-bayesianlinmod",
# "https://demo-markovchain.serve.scilifelab.se/app/demo-markovchain"
]
Expand Down
Loading

0 comments on commit e0e3e6c

Please sign in to comment.