Skip to content

Commit

Permalink
add basic chaos monkey to checkpointer
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktrn committed May 8, 2024
1 parent 091f1d8 commit 2a43a21
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/coordinator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const SECURE_CONNECTION = ["1", "true"].includes(process.env.SECURE_CONNECTION ?

const logger = new SimpleLogger(`[${NODE_NAME}]`);

if (CHAOS_MONKEY_ENABLED) {
logger.log("🍌 Chaos monkey enabled");
}

type CheckpointerInitializeReturn = {
canCheckpoint: boolean;
willSimulate: boolean;
Expand Down Expand Up @@ -224,6 +228,22 @@ class Checkpointer {
const $$ = $({ signal: controller.signal });

try {
if (CHAOS_MONKEY_ENABLED) {
console.log("🍌 Chaos monkey wreaking havoc");

const random = Math.random();

if (random < 0.33) {
// Fake long checkpoint duration
await $$`sleep 300`;
} else if (random < 0.66) {
// Fake checkpoint error
await $$`false`;
} else {
// no-op
}
}

const shortCode = nanoid(8);
const imageRef = this.#getImageRef(projectRef, deploymentVersion, shortCode);
const exportLocation = this.#getExportLocation(projectRef, deploymentVersion, shortCode);
Expand Down

0 comments on commit 2a43a21

Please sign in to comment.