-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Webiks/persistent_stress_tests
Persistent stress tests
- Loading branch information
Showing
15 changed files
with
166 additions
and
108 deletions.
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"server": { | ||
"PORT": 3000 | ||
"PORT": 3000, | ||
"cronJobFile": "stressTests.json" | ||
}, | ||
"cron": { | ||
"options": { | ||
|
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 @@ | ||
[ | ||
] |
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 @@ | ||
version: '3.2' | ||
|
||
services: | ||
cron_server: | ||
image: 223455578796.dkr.ecr.us-west-2.amazonaws.com/monitor-stress:latest | ||
restart: always | ||
container_name: stress | ||
volumes: | ||
- $PWD/config/stressTests.json:/user/app/config/stressTests.json | ||
ports: | ||
- "3000:3000" | ||
extra_hosts: | ||
- "logstash:$ADDRESS" |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "cron_server", | ||
"version": "1.0.0", | ||
"version": "1.2.1", | ||
"description": "New Monitor Cron", | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
|
@@ -11,14 +11,17 @@ | |
"start": "node src/server.js", | ||
"dev": "src/node_modules/.bin/nodemon -L", | ||
"test": "echo \"No test specified\" && exit 0", | ||
"deploy:clean": "docker image prune -f", | ||
"deploy:build": "docker build . -t webiks/cron_server:latest", | ||
"deploy:tag": "docker tag webiks/cron_server:latest webiks/cron_server:latest", | ||
"deploy:push": "docker push webiks/cron_server:latest", | ||
"upload": "npm run deploy:build && npm run deploy:tag && npm run deploy:push", | ||
"deploy:remove": "docker rm -f webiks/cron_server", | ||
"deploy:run": "docker run --name stress -p 3000:3000 -e webiks/cron_server", | ||
"deploy:full": "npm run deploy:build && npm run deploy:remove && npm run deploy:run" | ||
"docker:build": "sh -x ./scripts/docker-build.sh", | ||
"docker:start": "docker-compose up -d", | ||
"docker:stop": "docker-compose down", | ||
"docker:clean": "docker image prune -f", | ||
"docker:remove": "docker rm -f webiks/cron_server", | ||
"aws:deploy": "sh -x ./scripts/deploy.sh", | ||
"aws:full": "npm run docker:build && npm run aws:deploy" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Webiks/stress-as-a-service.git" | ||
}, | ||
"dependencies": { | ||
"express": "^4.17.1", | ||
|
@@ -32,5 +35,6 @@ | |
"nodemon": "^1.18.3", | ||
"npm": "^6.2.0", | ||
"rimraf": "^2.6.3" | ||
} | ||
}, | ||
"homepage": "https://github.com/Webiks/stress-as-a-service#readme" | ||
} |
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 @@ | ||
#!/bin/bash | ||
docker-compose build |
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 @@ | ||
#!/bin/bash | ||
eval "$(aws ecr get-login --no-include-email --region us-west-2)" | ||
|
||
PACKAGE_VERSION=$(node -p "require('./package.json').version") | ||
docker tag webiks/cron_server:"$PACKAGE_VERSION" 223455578796.dkr.ecr.us-west-2.amazonaws.com/monitor-stress:"$PACKAGE_VERSION" | ||
docker tag webiks/cron_server:latest 223455578796.dkr.ecr.us-west-2.amazonaws.com/monitor-stress:latest | ||
docker push 223455578796.dkr.ecr.us-west-2.amazonaws.com/monitor-stress:latest | ||
docker push 223455578796.dkr.ecr.us-west-2.amazonaws.com/monitor-stress:"$PACKAGE_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,4 @@ | ||
#!/bin/bash | ||
PACKAGE_VERSION=$(node -p "require('./package.json').version") | ||
docker build . -t webiks/cron_server:"$PACKAGE_VERSION" | ||
docker tag webiks/cron_server:"$PACKAGE_VERSION" webiks/cron_server:latest |
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 @@ | ||
#!/bin/bash | ||
PACKAGE_VERSION=$(node -p "require('./package.json').version") | ||
docker tag webiks/cron_server:"$PACKAGE_VERSION" webiks/cron_server:latest |
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,81 @@ | ||
'use strict'; | ||
|
||
const uuid = require('uuid/v4'); | ||
const cron = require('node-cron'); | ||
|
||
const stressTests = require('../../config/stressTests.json'); | ||
const config = require('../../config/config.json'); | ||
const storage = require('./storageHandler'); | ||
|
||
const {spawn} = require('child_process'); | ||
|
||
function execute(cmd, args) { | ||
return new Promise((resolve, reject) => { | ||
if (typeof (args) === 'string') { | ||
args = args.split(' '); | ||
} | ||
if (!(args instanceof Array)) { | ||
reject('Arguments must be string or array'); | ||
} | ||
console.log(`${(new Date()).toISOString()} - Cmd: ${cmd}, Args: ${args}`); | ||
const process = spawn(cmd, args); | ||
process.on('exit', (code, signal) => { | ||
if (code === 0) { | ||
console.log(`${(new Date()).toISOString()} - Child process ${process.pid} exited with code ${code}`); | ||
} else { | ||
reject(`${(new Date()).toISOString()} - Child process ${process.pid} exit code: ${code}, exit signal: ${signal}`); | ||
} | ||
}); | ||
process.stdout.setEncoding('utf8'); | ||
process.stdout.on('data', (data) => { | ||
console.log(`${(new Date()).toISOString()} - stdout: ${data}`); | ||
}); | ||
process.stderr.setEncoding('utf8'); | ||
process.stderr.on('data', (data) => { | ||
console.log(`${(new Date()).toISOString()} - stdout: ${data}`); | ||
}); | ||
resolve(process.pid); | ||
}); | ||
}; | ||
|
||
function setCron(exp, command, args) { | ||
let processId = undefined; | ||
const scheduledTask = cron.schedule(exp, | ||
() => { | ||
execute(command, args) | ||
.then((pid) => { | ||
processId = pid; | ||
console.log(`${(new Date()).toISOString()} Spawning new task w/ PID ${pid} and Stress arguments < ${args} >`); | ||
}) | ||
.catch((err) => { | ||
console.log(`${(new Date()).toISOString()}`, err.stack); | ||
}); | ||
}, | ||
{ | ||
scheduled: config.cron.options.scheduled, | ||
timezone: config.cron.options.timezone | ||
} | ||
); | ||
const task = { | ||
processId, | ||
scheduledTask, | ||
exp, | ||
args | ||
}; | ||
return task; | ||
} | ||
|
||
function onload() { | ||
const command = config.task.command; | ||
const tests = stressTests; | ||
tests.forEach((test) => { | ||
const exp = test.exp; | ||
const args = test.args; | ||
const task = setCron(exp, command, args); | ||
const id = test.id; | ||
storage.set(id, task); | ||
console.log(`${(new Date()).toISOString()} Id: ${id}, Exp: ${exp}, Args: ${args}`); | ||
}); | ||
}; | ||
|
||
module.exports = {setCron, onload}; |
This file was deleted.
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,5 @@ | ||
'use strict'; | ||
|
||
const storage = new Map([]); | ||
|
||
module.exports = storage; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module.exports = (err, req, res, next) => { | ||
console.error(`Something bad happened: ${err}`); | ||
console.error(`${(new Date()).toISOString()}, Something bad happened: ${err}`); | ||
if (err instanceof URIError) { | ||
res.redirect('/error'); | ||
} | ||
next(); | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = (req, res, next) => { | ||
// task: save to a file | ||
console.log(`Time: ${Date.now()} : ${req.url}`); | ||
console.log(`${(new Date()).toISOString()}, URL: ${req.method} ${req.url}`); | ||
next(); | ||
}; | ||
}; |
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
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