Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions simulation-client/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ const config = {
errorInjection: {
enabled: (process.env.ERROR_INJECTION_ENABLED || 'true') === 'true',
probability: parseFloat(process.env.ERROR_INJECTION_PROBABILITY) || 0.05
},

// Scheduled error spikes: crank error probability at fixed minutes each hour
// so every 30-min demo window has a visible spike to investigate.
errorSpike: {
enabled: (process.env.ERROR_SPIKE_ENABLED || 'true') === 'true',
probability: parseFloat(process.env.ERROR_SPIKE_PROBABILITY) || 0.6,
minuteMarks: (process.env.ERROR_SPIKE_MINUTES || '10,40').split(',').map(Number),
durationMinutes: parseInt(process.env.ERROR_SPIKE_DURATION) || 2
}
},

Expand Down
8 changes: 8 additions & 0 deletions simulation-client/src/workflows/SimulationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class SimulationManager {
runtimeMs: runtime,
activeSessions: this.activeSessions.size,
burstActive: this.burstActive,
errorSpikeActive: this.isErrorSpikeActive(),
currentConcurrency: this.getCurrentConcurrency(),
totalSessions: this.metrics.totalSessions,
successfulSessions: this.metrics.successfulSessions,
Expand All @@ -311,6 +312,13 @@ class SimulationManager {
};
}

isErrorSpikeActive() {
const spike = config.simulation.errorSpike;
if (!spike.enabled) return false;
const minute = new Date().getMinutes();
return spike.minuteMarks.some(m => minute >= m && minute < m + spike.durationMinutes);
}

delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down
11 changes: 10 additions & 1 deletion simulation-client/src/workflows/UserWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,16 @@ class UserWorkflow {
// (The gateway FaultInjectionFilter adds independent 500/503 noise.)
async generateErrorTraffic(user) {
if (!config.simulation.errorInjection.enabled) return;
if (Math.random() >= config.simulation.errorInjection.probability) return;

let effectiveProbability = config.simulation.errorInjection.probability;
const spike = config.simulation.errorSpike;
if (spike.enabled) {
const minute = new Date().getMinutes();
if (spike.minuteMarks.some(m => minute >= m && minute < m + spike.durationMinutes)) {
effectiveProbability = spike.probability;
}
}
if (Math.random() >= effectiveProbability) return;

const account = user.accounts && user.accounts.length > 0 ? user.accounts[0] : null;

Expand Down
Loading