-
Notifications
You must be signed in to change notification settings - Fork 0
Add fixture profiles for runtime scenario comparisons #46
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
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
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
32 changes: 32 additions & 0 deletions
32
backend/lined/load-tests/runtime-scenarios/command-runner.mjs
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,32 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
|
|
||
| export const runCommand = ( | ||
| command, | ||
| args, | ||
| { allowFailure = false, capture = false, cwd, timeoutMs } = {} | ||
| ) => { | ||
| const result = spawnSync(command, args, { | ||
| cwd, | ||
| encoding: capture ? 'utf-8' : undefined, | ||
| stdio: capture ? ['ignore', 'pipe', 'pipe'] : 'inherit', | ||
| timeout: timeoutMs, | ||
| }); | ||
|
|
||
| if (isTimeout(result, timeoutMs) && !allowFailure) { | ||
| throw new Error(`${command} timed out after ${timeoutMs}ms`); | ||
| } | ||
| if (result.error && !allowFailure) { | ||
| throw result.error; | ||
| } | ||
| if (result.signal && !allowFailure) { | ||
| throw new Error(`${command} was killed by signal ${result.signal}`); | ||
| } | ||
| if (!allowFailure && result.status !== 0) { | ||
| throw new Error(`${command} ${args.join(' ')} failed with exit code ${result.status}`); | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| const isTimeout = (result, timeoutMs) => timeoutMs !== undefined | ||
| && (result.error?.code === 'ETIMEDOUT' || result.signal === 'SIGTERM'); | ||
75 changes: 75 additions & 0 deletions
75
backend/lined/load-tests/runtime-scenarios/fixture-profiles-v1.json
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,75 @@ | ||
| { | ||
| "schema_version": 1, | ||
| "profiles": { | ||
| "local-smoke": { | ||
| "description": "Minimal fixture for local command validation.", | ||
| "workload": "smoke", | ||
| "k6_env": { | ||
| "USER_COUNT": "2", | ||
| "SEED_TASK_COUNT": "2", | ||
| "SEED_EVENT_COUNT": "2", | ||
| "THINK_TIME_SECONDS": "0" | ||
| } | ||
| }, | ||
| "comparison-baseline": { | ||
| "description": "Standard fixture for stable baseline scenario comparison.", | ||
| "workload": "baseline", | ||
| "k6_env": { | ||
| "USER_COUNT": "4", | ||
| "SEED_TASK_COUNT": "12", | ||
| "SEED_EVENT_COUNT": "8", | ||
| "VUS": "5", | ||
| "DURATION": "2m", | ||
| "THINK_TIME_SECONDS": "1" | ||
| } | ||
| }, | ||
| "comparison-read-heavy": { | ||
| "description": "Read-oriented fixture over bounded users, lobby, tasks, and events.", | ||
| "workload": "read-heavy", | ||
| "k6_env": { | ||
| "USER_COUNT": "4", | ||
| "SEED_TASK_COUNT": "12", | ||
| "SEED_EVENT_COUNT": "8", | ||
| "VUS": "5", | ||
| "DURATION": "2m", | ||
| "THINK_TIME_SECONDS": "1" | ||
| } | ||
| }, | ||
| "comparison-write-heavy": { | ||
| "description": "Write-oriented fixture with bounded setup and per-iteration cleanup.", | ||
| "workload": "write-heavy", | ||
| "k6_env": { | ||
| "USER_COUNT": "4", | ||
| "SEED_TASK_COUNT": "12", | ||
| "SEED_EVENT_COUNT": "8", | ||
| "VUS": "5", | ||
| "DURATION": "2m", | ||
| "THINK_TIME_SECONDS": "1" | ||
| } | ||
| }, | ||
| "comparison-mixed": { | ||
| "description": "Mixed read, update, and bounded write fixture for scenario comparison.", | ||
| "workload": "mixed", | ||
| "k6_env": { | ||
| "USER_COUNT": "4", | ||
| "SEED_TASK_COUNT": "12", | ||
| "SEED_EVENT_COUNT": "8", | ||
| "VUS": "5", | ||
| "DURATION": "2m", | ||
| "THINK_TIME_SECONDS": "1" | ||
| } | ||
| }, | ||
| "comparison-stress": { | ||
| "description": "Ramping-VU fixture for local stress comparison.", | ||
| "workload": "stress", | ||
| "k6_env": { | ||
| "USER_COUNT": "4", | ||
| "SEED_TASK_COUNT": "12", | ||
| "SEED_EVENT_COUNT": "8", | ||
| "STRESS_MAX_VUS": "20", | ||
| "STRESS_STAGE_DURATION": "30s", | ||
| "THINK_TIME_SECONDS": "1" | ||
| } | ||
| } | ||
| } | ||
| } |
131 changes: 131 additions & 0 deletions
131
backend/lined/load-tests/runtime-scenarios/fixture-profiles.mjs
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,131 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| export const FIXTURE_PROFILES_PATH = 'load-tests/runtime-scenarios/fixture-profiles-v1.json'; | ||
| export const K6_ENV_KEYS = new Set([ | ||
| 'RUN_ID', | ||
| 'USER_COUNT', | ||
| 'SEED_TASK_COUNT', | ||
| 'SEED_EVENT_COUNT', | ||
| 'VUS', | ||
| 'DURATION', | ||
| 'STRESS_MAX_VUS', | ||
| 'STRESS_STAGE_DURATION', | ||
| 'THINK_TIME_SECONDS', | ||
| ]); | ||
|
|
||
| const PROFILE_KEYS = new Set(['description', 'workload', 'k6_env']); | ||
|
|
||
| export const fixtureProfileNames = ({ cwd = process.cwd(), file = FIXTURE_PROFILES_PATH } = {}) => { | ||
| const artifact = readFixtureArtifact(cwd, file); | ||
| return Object.keys(artifact.profiles).sort(); | ||
| }; | ||
|
|
||
| export const loadFixtureProfile = ( | ||
| name, | ||
| { allowedWorkloads, cwd = process.cwd(), file = FIXTURE_PROFILES_PATH } = {} | ||
| ) => { | ||
| const artifact = readFixtureArtifact(cwd, file); | ||
| const profile = artifact.profiles[name]; | ||
| if (!profile) { | ||
| throw new Error(`--fixture-profile must be one of: ${Object.keys(artifact.profiles).sort().join(', ')}`); | ||
| } | ||
| validateProfile(name, profile, allowedWorkloads); | ||
| return { | ||
| description: profile.description, | ||
| k6Env: { ...profile.k6_env }, | ||
| name, | ||
| schemaVersion: artifact.schema_version, | ||
| workload: profile.workload, | ||
| }; | ||
| }; | ||
|
|
||
| export const applyFixtureProfileDefaults = ( | ||
| options, | ||
| { | ||
| cwd = process.cwd(), | ||
| explicitK6Env = {}, | ||
| fixtureFile = FIXTURE_PROFILES_PATH, | ||
| allowedWorkloads, | ||
| workloadExplicit = false, | ||
| } = {} | ||
| ) => { | ||
| if (!options.fixtureProfile) { | ||
| return options; | ||
| } | ||
|
|
||
| const profile = loadFixtureProfile(options.fixtureProfile, { | ||
| allowedWorkloads, | ||
| cwd, | ||
| file: fixtureFile, | ||
| }); | ||
| const merged = { | ||
| ...options, | ||
| fixtureProfileData: profile, | ||
| k6Env: { | ||
| ...profile.k6Env, | ||
| ...explicitK6Env, | ||
| }, | ||
| }; | ||
| if (!workloadExplicit) { | ||
| merged.workload = profile.workload; | ||
| } | ||
| return merged; | ||
| }; | ||
|
|
||
| const readFixtureArtifact = (cwd, file) => { | ||
| const artifactPath = path.resolve(cwd, file); | ||
| const parsed = JSON.parse(fs.readFileSync(artifactPath, 'utf-8')); | ||
| if (!isRecord(parsed) || parsed.schema_version !== 1 || !isRecord(parsed.profiles)) { | ||
| throw new Error('fixture profile artifact must contain schema_version 1 and profiles'); | ||
| } | ||
| return parsed; | ||
| }; | ||
|
|
||
| const validateProfile = (name, profile, allowedWorkloads) => { | ||
| requireRecord(`fixture profile ${name}`, profile); | ||
| requireKnownProfileKeys(name, profile); | ||
| requireWorkload(name, profile.workload, allowedWorkloads); | ||
| requireK6Env(name, profile.k6_env); | ||
| }; | ||
|
|
||
| const requireRecord = (label, value) => { | ||
| if (!isRecord(value)) { | ||
| throw new Error(`${label} must be an object`); | ||
| } | ||
| }; | ||
|
|
||
| const requireKnownProfileKeys = (name, profile) => { | ||
| const unknownKeys = Object.keys(profile).filter((key) => !PROFILE_KEYS.has(key)); | ||
| if (unknownKeys.length > 0) { | ||
| throw new Error(`fixture profile ${name} has unsupported keys: ${unknownKeys.join(', ')}`); | ||
| } | ||
| }; | ||
|
|
||
| const requireWorkload = (name, workload, allowedWorkloads) => { | ||
| if (typeof workload !== 'string' || workload.length === 0) { | ||
| throw new Error(`fixture profile ${name} must define workload`); | ||
| } | ||
| if (allowedWorkloads && !allowedWorkloads.has(workload)) { | ||
| throw new Error( | ||
| `fixture profile ${name} has unsupported workload ${workload}; ` | ||
| + `allowed: ${Array.from(allowedWorkloads).join(', ')}` | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| const requireK6Env = (name, k6Env) => { | ||
| requireRecord(`fixture profile ${name} k6_env`, k6Env); | ||
| Object.entries(k6Env).forEach(([key, value]) => requireK6EnvEntry(name, key, value)); | ||
| }; | ||
|
|
||
| const requireK6EnvEntry = (name, key, value) => { | ||
| if (!K6_ENV_KEYS.has(key)) { | ||
| throw new Error(`fixture profile ${name} has unsupported k6 env ${key}`); | ||
| } | ||
| if (typeof value !== 'string') { | ||
| throw new Error(`fixture profile ${name} k6 env ${key} must be a string`); | ||
| } | ||
| }; | ||
|
|
||
| const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value); |
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.
No timeout on
spawnSync.kubectl rollout statuscan block for minutes (or indefinitely if a pod never becomes Ready), and a stuck k6 run will also block forever. Consider threading atimeoutoption through the adapters:Even a generous ceiling (e.g. 10 min for rollout, 5 min for k6 smoke) prevents a CI job from hanging until its runner wall-clock limit kills it with no useful error message.
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.
Fixed