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

Upgraded Locusat and small fixes to some tests #14

Merged
merged 92 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
5b3d919
Updated docs and config.
alfredeen Jan 10, 2024
8af2e1a
Small change to instructions.
alfredeen Jan 12, 2024
7dc91f1
Refactored into using abstract base user types. These are implemented…
alfredeen Jan 12, 2024
0b74393
Added an app viewer user
alfredeen Jan 12, 2024
8f96c6f
Work on login to Serve as test user.
alfredeen Jan 16, 2024
a180aeb
Completed authentication methods. Work on user type power user..
alfredeen Jan 16, 2024
991cbe1
Created non-locust module for opening user apps which created k8s pod…
alfredeen Jan 18, 2024
16c6066
More settings and configuration to customize the user app behaviour
alfredeen Jan 18, 2024
82e8720
Better handling of switching between test environments.
alfredeen Jan 19, 2024
8286b6a
Added task to register new user account.
alfredeen Jan 19, 2024
0855d6a
Began test plan classroom. Implemented power user create and delete u…
alfredeen Jan 22, 2024
0075962
Finished test plan classroom.
alfredeen Jan 22, 2024
3aad2da
Small change to readme to make configuration URL into a link.
alfredeen Feb 1, 2024
b4b3c42
Added config files for pre-commit and flake8.
alfredeen Feb 1, 2024
db19a75
Added github workflow pre-commit
alfredeen Feb 1, 2024
0ec1f15
Update source/tests-dev/appviewer_requestshtml.py
alfredeen Feb 1, 2024
01cc795
Update source/tests-dev/appviewer_requestshtml.py
alfredeen Feb 1, 2024
0d82d4c
Update source/tests-dev/appviewer_requestshtml.py
alfredeen Feb 1, 2024
b955402
Update source/tests-dev/authenticated.py
alfredeen Feb 1, 2024
12b8fc9
Moved code check config files up to root level.
alfredeen Feb 1, 2024
359a383
Reformatted with code linters and checkers
alfredeen Feb 1, 2024
36c5c7f
Reformatted imports with isort
alfredeen Feb 1, 2024
b67f157
Reformatted and code changes for the mypy type checker.
alfredeen Feb 1, 2024
626027c
Fixed end of line rules
alfredeen Feb 1, 2024
046cdad
Introduced the standard logging library. Converted most prints to log…
alfredeen Feb 1, 2024
c176ef8
Update source/tests/base_user_types.py
alfredeen Feb 2, 2024
b29ce3f
Update source/tests/base_user_types.py
alfredeen Feb 2, 2024
14e0035
Clearer setup instructions
alfredeen Feb 2, 2024
e1c10eb
Formatting
alfredeen Feb 2, 2024
ab83dc1
Formatting
alfredeen Feb 2, 2024
cc88b22
Updated test logic so sync with changes to Serve.
alfredeen Apr 17, 2024
2a1694a
Added Dockerfile and a start script.
alfredeen Apr 18, 2024
1961106
Added a CI github action
alfredeen Apr 18, 2024
af783a2
Pinned version of the Locust base image.
alfredeen Apr 18, 2024
e2ddd2c
Building source directory
alfredeen Apr 18, 2024
336342d
Adding a publish action
alfredeen Apr 19, 2024
c23bf74
Fixed formatting
alfredeen Apr 19, 2024
be975ee
Fixed formatting
alfredeen Apr 19, 2024
10e620d
Fixed formatting
alfredeen Apr 19, 2024
e75b8e1
Merge branch 'main' into develop
alfredeen Apr 19, 2024
bba9531
Fixed package name
alfredeen Apr 19, 2024
0a503bd
Merge branch 'develop' of https://github.com/ScilifelabDataCentre/ser…
alfredeen Apr 19, 2024
1d940bb
Merge branch 'main' into develop
alfredeen Apr 19, 2024
d778864
Fixed publish context
alfredeen Apr 19, 2024
c47dd19
Adjusted permissions in image
alfredeen Apr 19, 2024
b277ebc
Set start-script to locust
alfredeen Apr 19, 2024
6209559
Added k8s manifests
alfredeen Apr 19, 2024
f62ce3e
Added more k8s manifests
alfredeen Apr 22, 2024
85fd979
Creating resources in namespace locust. Added a cert manager for TLS.
alfredeen Apr 24, 2024
0d7ef4b
Added an ArgoCD application manifest file to create the ArgoCD app.
alfredeen Apr 24, 2024
f3f927f
Removed the ingress class name from the ingress.
alfredeen Apr 24, 2024
0b16b97
Fixed formatting
alfredeen Apr 25, 2024
4f4af04
Added basic auth to Locust web UI
alfredeen Apr 29, 2024
c2e56b5
Corrected secret incstructions.
alfredeen Apr 29, 2024
22b87fa
Added secret locust-secrets with settings from .env
alfredeen Apr 29, 2024
a2242c7
Merge branch 'main' into develop
alfredeen Apr 29, 2024
9f1382f
Base64 of values
alfredeen Apr 29, 2024
29ca18d
Updated the image version used
alfredeen Apr 29, 2024
d9928f2
Added a container to the k8s deployment with locust-timescale. Added …
alfredeen Apr 30, 2024
37477a5
Fixed a secret setting value
alfredeen May 2, 2024
aa49af8
Using kustomize to customize k8s manifests for local development and …
alfredeen May 2, 2024
2b5d84d
Created a version of the k8s manifest deployment without using kustom…
alfredeen May 2, 2024
0238325
Changed the ArgoCD deployemtn directory to manifests/built
alfredeen May 2, 2024
72e208d
Simplified prod deployemnt for now without db.
alfredeen May 2, 2024
e6008fd
Added a second pod for postgresql db.
alfredeen May 2, 2024
a7f3cc3
Replaced postgres image with locust-timescale
alfredeen May 2, 2024
ab1f501
Added locust-plugins to docker image
alfredeen May 3, 2024
ec249d9
Pinned version of locust-plugins
alfredeen May 3, 2024
b6d1ea2
Added a hadolint conf file. Set failure threshold to warning.
alfredeen May 3, 2024
b7909dc
Fixed merge issues
alfredeen May 3, 2024
2e50fb2
Updated the version of the load testing image
alfredeen May 3, 2024
c4fab97
Changed resource limits for the postgres deployment
alfredeen May 3, 2024
820e437
Ignoring argocd and manifests directories when publishing image
alfredeen May 6, 2024
ae3328b
Updated the production env overlay manifests
alfredeen May 6, 2024
ecfc2ae
Set the production web UI URL to the new cluster. Added the web UI se…
alfredeen May 6, 2024
20c0e65
Set security context in deployment manifests.
alfredeen May 6, 2024
6b0c90f
Added more security context
alfredeen May 6, 2024
e9cb6fd
Added capabilities restriction to postgres container
alfredeen May 6, 2024
fd00b2b
Small fix
alfredeen May 6, 2024
54404df
Updated the ingress cert issuer for the new cluster
alfredeen May 15, 2024
82b341a
Updated the ingress cert issuer for the new cluster
alfredeen May 15, 2024
9330dab
Removed some of the security context for the locust timescale postgre…
alfredeen May 15, 2024
e5979f3
Removed some of the security context for the locust timescale postgre…
alfredeen May 15, 2024
b9e3291
Removed some of the security context for the locust timescale postgre…
alfredeen May 15, 2024
244c1f6
Added env var LOCUST_WEB_HOST.
alfredeen May 15, 2024
dac4fbc
Set env var LOCUST_WEB_HOST to 0.0.0.0
alfredeen May 15, 2024
a800aed
Upgraded Locust to version 2.31.8 for local development. Upgraded Pyt…
alfredeen Oct 3, 2024
c48ec0c
Fixed some load tests that were missing trailing slashes or using the…
alfredeen Oct 3, 2024
fc3694e
Upgraded linting and other tools in the pre-commit action. Also fixed…
alfredeen Oct 3, 2024
6fff651
Upgraded the checkout task in the CI action.
alfredeen Oct 3, 2024
21d8961
Upgraded Locust and locust-plugins also in the custom docker image.
alfredeen Oct 3, 2024
3c8b23c
Merge branch 'main' into develop
alfredeen Oct 4, 2024
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
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

Check failure on line 7 in source/Dockerfile

View workflow job for this annotation

GitHub Actions / lint

SC2102 info: Ranges can only match single chars (mentioned due to duplicates).

# 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

Check failure on line 17 in source/Dockerfile

View workflow job for this annotation

GitHub Actions / lint

DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.

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