-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sandbox): prototype locust integration to the monorepo (#2896)
- Loading branch information
1 parent
b95bc34
commit 1493b11
Showing
14 changed files
with
1,728 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Locust Load Test | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
product: | ||
type: choice | ||
description: 'Name of the product to test' | ||
required: true | ||
options: | ||
- agora | ||
- openchallenges | ||
# user_count: | ||
# description: 'Number of users to simulate in Locust' | ||
# required: true | ||
# default: '50' | ||
# spawn_rate: | ||
# description: 'Rate at which users are spawned (users per second)' | ||
# required: true | ||
# default: '10' | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-22.04-4core-16GBRAM-150GBSSD | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Derive appropriate SHAs for base and head for `nx affected` commands | ||
uses: nrwl/nx-set-shas@v4 | ||
|
||
- name: Set up the dev container | ||
uses: ./.github/actions/setup-dev-container | ||
|
||
# - name: Build the specified product, serve it, and perform a load test | ||
# run: | | ||
# devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | ||
# && nx run-many --target=build-image --projects=${{ inputs.product }}-*" \ | ||
# && nx serve-detach ${{ inputs.product }}-apex \ | ||
# && nx serve sandbox-locust --configuration=${{ inputs.product }} | ||
|
||
- name: Perform a load test | ||
run: | | ||
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | ||
&& nx run sandbox-locust:serve:${{ inputs.product }} --headless | ||
- name: Upload Locust reports as artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: locust-reports | ||
path: apps/sandbox/locust/locust_*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[flake8] | ||
exclude = | ||
.git, | ||
__pycache__, | ||
build, | ||
dist, | ||
.tox, | ||
venv, | ||
.venv, | ||
.pytest_cache | ||
max-line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Locust reports | ||
locust_*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.10.14 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
PYTHON_VERSION="3.10.14" | ||
|
||
pyenv install --skip-existing $PYTHON_VERSION | ||
|
||
# Initializing pyenv again solves an issue encountered by GitHub action where the version of Python | ||
# installed above is not detected. | ||
eval "$(pyenv init -)" | ||
|
||
pyenv local $PYTHON_VERSION | ||
poetry env use $(pyenv which python) | ||
poetry install --with dev |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[virtualenvs] | ||
in-project = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"name": "sandbox-locust", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"projectType": "application", | ||
"sourceRoot": "apps/sandbox/locust/locust", | ||
"targets": { | ||
"lock": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "poetry lock --no-update", | ||
"cwd": "{projectRoot}" | ||
} | ||
}, | ||
"build": { | ||
"executor": "@nxlv/python:build", | ||
"outputs": ["{projectRoot}/dist"], | ||
"options": { | ||
"outputPath": "{projectRoot}/dist", | ||
"publish": false, | ||
"lockedVersions": true, | ||
"bundleLocalDependencies": true | ||
} | ||
}, | ||
"prepare": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "./install.sh", | ||
"cwd": "{projectRoot}" | ||
} | ||
}, | ||
"update": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "poetry update", | ||
"cwd": "{projectRoot}" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nxlv/python:flake8", | ||
"outputs": ["{workspaceRoot}/reports/{projectRoot}/pylint.txt"], | ||
"options": { | ||
"outputFile": "reports/{projectRoot}/pylint.txt" | ||
} | ||
}, | ||
"serve": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "poetry run locust", | ||
"cwd": "{projectRoot}" | ||
}, | ||
"configurations": { | ||
"agora": { | ||
"locustfile": "sandbox_locust/locustfile_agora.py", | ||
"host": "http://localhost:8000" | ||
}, | ||
"openchallenges": { | ||
"locustfile": "sandbox_locust/locustfile_openchallenges.py", | ||
"host": "https://openchallenges.io" | ||
} | ||
}, | ||
"defaultConfiguration": "agora" | ||
} | ||
}, | ||
"tags": ["language:python", "package-manager:poetry"], | ||
"release": { | ||
"version": { | ||
"generator": "@nxlv/python:release-version" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[tool.coverage.run] | ||
branch = true | ||
source = [ "sandbox_locust" ] | ||
|
||
[tool.coverage.report] | ||
exclude_lines = [ "if TYPE_CHECKING:" ] | ||
show_missing = true | ||
|
||
[tool.poetry] | ||
name = "sandbox-locust" | ||
version = "1.0.0" | ||
description = "" | ||
authors = [ ] | ||
license = "Proprietary" | ||
readme = "README.md" | ||
|
||
[[tool.poetry.packages]] | ||
include = "sandbox_locust" | ||
|
||
[tool.poetry.dependencies] | ||
python = "3.10.14" | ||
locust = "2.31.8" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
autopep8 = "2.0.2" | ||
flake8 = "6.0.0" | ||
pytest = "7.3.1" | ||
pytest-sugar = "0.9.7" | ||
pytest-cov = "4.1.0" | ||
pytest-html = "3.2.0" | ||
|
||
[tool.locust] | ||
# locustfile = "" | ||
headless = false | ||
# master = false | ||
# expect-workers = 5 | ||
# host = "" | ||
users = 10 | ||
spawn-rate = 2 | ||
run-time = "1m" | ||
csv = "locust" | ||
# tags = ["Critical", "Normal"] | ||
|
||
[build-system] | ||
requires = [ "poetry-core" ] | ||
build-backend = "poetry.core.masonry.api" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from locust import HttpUser, task, between | ||
|
||
|
||
class AgoraUser(HttpUser): | ||
wait_time = between(1, 5) | ||
|
||
@task | ||
def hello_world(self): | ||
self.client.get("/") | ||
self.client.get("/about") |
8 changes: 8 additions & 0 deletions
8
apps/sandbox/locust/sandbox_locust/locustfile_openchallenges.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from locust import HttpUser, task | ||
|
||
|
||
class OpenChallengesUser(HttpUser): | ||
@task | ||
def hello_world(self): | ||
self.client.get("/") | ||
self.client.get("/about") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters