-
Notifications
You must be signed in to change notification settings - Fork 2
DRAFT: add first draft of load simulator #172
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a888ee4
chore: add first draft of load simulator
jeastham1993 12fb40a
chore: add env:setup requirement to loadtests
jeastham1993 6866079
feat(load-tests): add GameDay multi-user load testing profiles
jeastham1993 0c274c9
feat(load-tests): add user provisioning and registration flow
jeastham1993 2010bdc
docs(load-tests): improve README and fix logout URL rewriting
jeastham1993 e960f09
chore: update ratelimit config for loadtest
jeastham1993 eac7bc5
add user exists exception
jeastham1993 0113ca5
chore: add Datadog product features
jeastham1993 9b1e57c
chore: remove duplicate docs
jeastham1993 6950812
chore: add links to readme
jeastham1993 183a234
chore: cleanup README
jeastham1993 3429e47
refactor: address PR review feedback for load testing
jeastham1993 339b044
docs: simplify load test README with clearer instructions
jeastham1993 03b1aec
docs: add Datadog telemetry validation instructions to README
jeastham1993 dc6dee9
chore: address PR feedback
jeastham1993 055bc08
chore: add load simulator to mise
jeastham1993 acb5356
chore: add load simulator to mise
jeastham1993 6c37f0b
Merge branch 'main' into feat/load-sim
scottgerring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
|
jeastham1993 marked this conversation as resolved.
|
This file contains hidden or 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,78 @@ | ||
| # Load Testing | ||
|
|
||
| k6-based load tests for Stickerlandia. | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ```bash | ||
| mise run load:smoke # Quick test: 2 users, 30 seconds | ||
| mise run load:test # Full test: ramp to 30 users over 10 minutes | ||
| mise run load:sustained # Multi-user: provision users, run 10 min sustained load | ||
| ``` | ||
|
|
||
| Each command starts services, runs the test, then cleans up. | ||
|
|
||
| ### Test Scenarios | ||
|
|
||
| ```bash | ||
| mise run load:smoke:public # Public endpoints only (no auth) | ||
| mise run load:smoke:auth # Authenticated flows only | ||
| mise run load:smoke:register # Registration flow | ||
| ``` | ||
|
|
||
| ### Keep Services Running | ||
|
|
||
| For iterative testing: | ||
|
|
||
| ```bash | ||
| mise run load:start # Start services | ||
| mise run load:sustained:run # Run test (repeat as needed) | ||
| mise run load:stop # Stop and cleanup | ||
| ``` | ||
|
|
||
| ## Multi-User Pool | ||
|
|
||
| For sustained tests with multiple concurrent users: | ||
|
|
||
| 1. Create `load-tests/data/users.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "users": [ | ||
| {"email": "loadtest-001@example.com", "password": "LoadTest2026!"}, | ||
| {"email": "loadtest-002@example.com", "password": "LoadTest2026!"} | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| 2. Provision users once: `mise run load:provision-users` | ||
|
|
||
| 3. Run tests: `mise run load:sustained` | ||
|
|
||
| ## Validating Telemetry in Datadog | ||
|
|
||
| After running load tests, verify data appears in Datadog: | ||
|
|
||
| | Product | Link | What to Check | | ||
| |---------|------|---------------| | ||
| | APM | [Traces](https://app.datadoghq.com/apm/traces?query=env%3Adevelopment) | Service traces for all requests | | ||
| | Logs | [Logs](https://app.datadoghq.com/logs?query=env%3Adevelopment) | Application logs from all services | | ||
| | RUM | [Sessions](https://app.datadoghq.com/rum/sessions) | Browser sessions (requires frontend interaction) | | ||
| | DSM | [Data Streams](https://app.datadoghq.com/data-streams) | Kafka message flow between services | | ||
| | DBM | [Databases](https://app.datadoghq.com/databases) | Query performance metrics | | ||
| | Profiling | [Profiles](https://app.datadoghq.com/profiling/explorer?query=env%3Adevelopment) | CPU/memory profiles | | ||
|
|
||
| Filter by `env:development` to see load test data. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Override defaults with environment variables: | ||
|
|
||
| ```bash | ||
| WORKLOAD=load SCENARIO=auth mise run load:smoke | ||
| ``` | ||
|
|
||
| | Variable | Default | Options | | ||
| |----------|---------|---------| | ||
| | `WORKLOAD` | `smoke` | `smoke`, `load`, `sustained`, `sustained:auth`, `sustained:catalogue` | | ||
| | `SCENARIO` | `mixed` | `mixed`, `public`, `auth`, `register` | |
This file contains hidden or 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,107 @@ | ||
| /* | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| * Copyright 2025-Present Datadog, Inc. | ||
| */ | ||
|
|
||
| /** | ||
| * Shared URL helpers for k6 load tests. | ||
| * k6 doesn't have native URL constructor, so we implement manual URL parsing. | ||
| */ | ||
|
|
||
| // Configuration from environment | ||
| export const BASE_URL = __ENV.TARGET_URL || 'http://traefik:80'; | ||
| export const DEPLOYMENT_HOST_URL = __ENV.DEPLOYMENT_HOST_URL || 'http://localhost:8080'; | ||
|
|
||
| /** | ||
| * Rewrite external URLs to internal Docker network URLs. | ||
| * OAuth redirects use the configured external hostname (e.g., localhost:8080) | ||
| * but k6 inside Docker needs to use the internal hostname (traefik:80). | ||
| */ | ||
| export function rewriteUrl(url) { | ||
| if (url && url.startsWith(DEPLOYMENT_HOST_URL)) { | ||
| return url.replace(DEPLOYMENT_HOST_URL, BASE_URL); | ||
| } | ||
| return url; | ||
| } | ||
|
|
||
| /** | ||
| * Extract origin (protocol + host) from a URL string. | ||
| */ | ||
| export function getUrlOrigin(url) { | ||
| const match = url.match(/^(https?:\/\/[^\/]+)/); | ||
| return match ? match[1] : ''; | ||
| } | ||
|
|
||
| /** | ||
| * Get the directory path from a URL (everything up to the last /). | ||
| */ | ||
| export function getUrlDirectory(url) { | ||
| const origin = getUrlOrigin(url); | ||
| const path = url.slice(origin.length); | ||
| const lastSlash = path.lastIndexOf('/'); | ||
| return origin + (lastSlash >= 0 ? path.slice(0, lastSlash + 1) : '/'); | ||
| } | ||
|
|
||
| /** | ||
| * Resolve a relative URL against a base URL. | ||
| */ | ||
| export function resolveUrl(baseUrl, relativeUrl) { | ||
| if (relativeUrl.startsWith('http')) { | ||
| return relativeUrl; | ||
| } | ||
| if (relativeUrl.startsWith('/')) { | ||
| return getUrlOrigin(baseUrl) + relativeUrl; | ||
| } | ||
| return getUrlDirectory(baseUrl) + relativeUrl; | ||
| } | ||
|
|
||
| /** | ||
| * Extract access_token from URL query string or fragment. | ||
| * Handles URLs like: http://example.com/callback?access_token=xxx | ||
| * or: http://example.com/callback#access_token=xxx | ||
| * | ||
| * NOTE: k6's goja runtime lacks native URL/URLSearchParams APIs, | ||
| * so we parse manually instead of using `new URL(url).searchParams`. | ||
| */ | ||
| export function extractTokenFromUrl(url) { | ||
| try { | ||
| // Split URL into base and the part after ? or # | ||
| // Handle both query string (?access_token=) and fragment (#access_token=) | ||
| let searchStr = ''; | ||
|
|
||
| const queryIndex = url.indexOf('?'); | ||
| const hashIndex = url.indexOf('#'); | ||
|
|
||
| if (queryIndex !== -1) { | ||
| const endIndex = hashIndex > queryIndex ? hashIndex : url.length; | ||
| searchStr = url.substring(queryIndex + 1, endIndex); | ||
| } else if (hashIndex !== -1) { | ||
| searchStr = url.substring(hashIndex + 1); | ||
| } | ||
|
|
||
| if (searchStr) { | ||
| const params = {}; | ||
| searchStr.split('&').forEach(pair => { | ||
| const eqIndex = pair.indexOf('='); | ||
| if (eqIndex !== -1) { | ||
| const key = decodeURIComponent(pair.substring(0, eqIndex)); | ||
| const value = decodeURIComponent(pair.substring(eqIndex + 1)); | ||
| params[key] = value; | ||
| } | ||
| }); | ||
|
|
||
| if (params.access_token) { | ||
| return { success: true, accessToken: params.access_token }; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.warn('Failed to extract token from URL:', url, e); | ||
| } | ||
| return { success: false, error: 'Could not extract token from URL' }; | ||
| } | ||
|
|
||
| /** | ||
| * Maximum number of redirects to follow to prevent infinite loops. | ||
| */ | ||
| export const MAX_REDIRECTS = 10; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to turn agent on if load-testing is on but monitoring isnt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scottgerring Hmm, good question. I guess for what we are using load testing for is to generate data for the agent. Not load testing in the traditional sense. So yeah, I think we should turn load testing on even if monitoring isn't. Which is what this will do right? Or have I misunderstood docker profiles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an agent - so this'll turn on the datadog-agent, if we ask for load-testing