From 8e5a056924da96184ada75856426533ac4b6a1d8 Mon Sep 17 00:00:00 2001 From: i0natan Date: Fri, 5 Apr 2019 11:44:06 +0300 Subject: [PATCH] Genric message --- entry-points/api.js | 2 +- index.js | 1 + package.json | 4 +- pranks/pranks-definition.js | 332 ++++++++++-------- .../index.js | 11 +- ui/src/components/ChaosTest/ChooseChaos.jsx | 2 +- ui/src/stores/prankStore.js | 1 + 7 files changed, 187 insertions(+), 166 deletions(-) diff --git a/entry-points/api.js b/entry-points/api.js index da3aaa3..8c227a8 100644 --- a/entry-points/api.js +++ b/entry-points/api.js @@ -82,7 +82,7 @@ class API { if (prankToEmit.name === "blocked-event-loop" || prankToEmit.name === "memory-load" || prankToEmit.name === "uncaught-exception" || prankToEmit.name === "cpu-load") { socket.broadcast.emit('new-prank-activity', prankToEmit); } - }, 1000); + }, 2000); socket.on('disconnect', function () { diff --git a/index.js b/index.js index d05f0d9..6f2940d 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const API = require('./entry-points/api'); const ChaosControl = require('./chaos-control'); +console.log('Chaos monkey starting point'); module.exports.initialize = (expressApp) => { return { api: new API(expressApp), diff --git a/package.json b/package.json index 18d54f4..e08323e 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "test:manual": "npm run build:ui && nodemon ./tests/manual-testing-with-simple-web-app/index.js", + "test:manual": "nodemon ./tests/manual-testing-with-simple-web-app/index.js", "start": "node ./index.js", - "start:dev": "npm run build:ui && nodemon ./index.js", + "start:dev": "concurrently \"npm run build:ui\" \"npm start --prefix tests/manual-testing-with-simple-web-app\" \"nodemon\"", "build:ui": "npm install --prefix ui && npm run build --prefix ui", "serve": "concurrently \"npm run build:ui\" \"npm run start\"", "start:app": "npm run build:ui && npm run start" diff --git a/pranks/pranks-definition.js b/pranks/pranks-definition.js index d24156a..496a95b 100644 --- a/pranks/pranks-definition.js +++ b/pranks/pranks-definition.js @@ -1,155 +1,183 @@ -class PranksDefinition{ - getAll() { - const result = [{ - name: "500-error-on-route", - friendlyName: "API route returns 500 error", - file: "500-error-on-route", - active: true, - properties: { - urls: ["/api/products", "/anyurl"] +class PranksDefinition { + getAll() { + const result = [{ + name: "500-error-on-route", + friendlyName: "API route returns 500 error", + file: "500-error-on-route", + active: true, + properties: [{ + name: "url", + description: "Which route should return 500 error", + defaultValue: "/api/products", + type: "string" + }], + schedule: { + type: "immediate-schedule", + fadeOutInMS: 10000 + }, + description: 'Our monkey intercepts HTTP routes and return errors on your behalf', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify, error should appear in log', + reality: 'This feature is not implemented yet', + success: 'Yes' + }, + { + name: "Process-exit", + friendlyName: "Process exit", + file: "process-exit", + active: true, + properties: [{ + name: "exitCode", + description: "What should be the process quit exit code", + defaultValue: 1, + type: "number" + }], + schedule: { + type: "immediate-schedule", + fadeOutInMS: 10000 + }, + description: 'Our monkey kills the process', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify, a new process should be instantiated', + reality: 'This feature is not implemented yet', + success: 'No' + }, + { + name: "uncaught-exception", + friendlyName: "Uncaught exception", + file: "uncaught-exception", + active: true, + properties: [{ + name: "message", + Description: "What message should the error include", + defaultValue: "Uncaught exception was thrown by the chaos monkey", + type: "string" + }], + schedule: { + type: "one-time-schedule", + delay: 12000 + }, + description: 'Our monkey Throws an uncaught exception into the void', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify, process should stay alive or new one should get instantiated', + reality: 'This feature is not implemented yet', + success: 'No' + }, + { + name: "unhandled-rejection", + friendlyName: "Unhandled promise rejection", + file: "unhandled-rejection", + active: true, + properties: [{ + name: "message", + Description: "What message should the error include", + defaultValue: "Uncaught exception was thrown by the chaos monkey", + type: "string" + }], + schedule: { + type: "one-time-schedule", + delay: 10000 + }, + description: 'Our monkey Throws an uncaught promise rejection into the void', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify, process should stay alive or new one should get instantiated', + reality: 'This feature is not implemented yet', + success: 'No' + }, + { + name: "memory-load", + friendlyName: "Memory is overloaded", + file: "memory-load", + active: true, + properties: [{ + name: "maxMemorySizeInMB", + Description: "How much memory should be used by the chaos monkey", + defaultValue: 2000, + type: "number" + }], + schedule: { + type: "one-time-schedule", + delay: 1000, + fadeOutInMS: 30000 + }, + description: 'Our monkey constantly increases the RAM, if no limit was specified the entire allowed 1.7GB will be used', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify', + reality: 'This feature is not implemented yet', + success: 'No' + }, + { + name: "cpu-load", + friendlyName: "Busy CPU", + file: "cpu-load", + active: true, + properties: {}, + schedule: { + type: "peaks", + sleepTimeBetweenPeaksInMS: 3000, + pickLengthInMS: 10000, + forHowLong: 8000 + }, + description: 'Our monkey constantly keeps the CPU busy (without blocking the event loop)', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify', + reality: 'This feature is not implemented yet', + success: 'No' + }, + { + name: "blocked-event-loop", + friendlyName: "Blocked event loop", + file: "blocked-event-loop", + active: true, + properties: {}, + schedule: { + type: "peaks", + sleepTimeBetweenPeaksInMS: 3000, + pickLengthInMS: 10000, + forHowLong: 8000 + }, + description: 'Our monkey constantly blocks the event loop', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify', + reality: 'This feature is not implemented yet', + success: 'No' + }, + { + name: "broken-http-integration", + friendlyName: "Broken Integration", + file: "broken-http-integration", + active: true, + properties: + [{ + name: "url", + Description: "What is the URL of the external service that should be mocked", + defaultValue: "http://localhost/otherservice/", + type: "string" }, - schedule: { - type: "immediate-schedule", - fadeOutInMS: 10000 - }, - description: 'Our monkey intercepts HTTP routes and return errors on your behalf', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify, error should appear in log', - reality: 'This feature is not implemented yet', - success: 'Yes' - }, - { - name: "Process-exit", - friendlyName: "Process exit", - file: "process-exit", - active: true, - properties: { - exitCode: 1 - }, - schedule: { - type: "immediate-schedule", - fadeOutInMS: 10000 - }, - description: 'Our monkey kills the process', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify, a new process should be instantiated', - reality: 'This feature is not implemented yet', - success: 'No' - }, - { - name: "uncaught-exception", - friendlyName: "Uncaught exception", - file: "uncaught-exception", - active: true, - properties: { - message: "Uncaught exception was thrown by the chaos monkey" - }, - schedule: { - type: "one-time-schedule", - delay: 12000 - }, - description: 'Our monkey Throws an uncaught exception into the void', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify, process should stay alive or new one should get instantiated', - reality: 'This feature is not implemented yet', - success: 'No' - }, - { - name: "unhandled-rejection", - friendlyName: "Unhandled promise rejection", - file: "unhandled-rejection", - active: true, - properties: { - message: "Uncaught rejection was thrown by the chaos monkey" - }, - schedule: { - type: "one-time-schedule", - delay: 10000 - }, - description: 'Our monkey Throws an uncaught promise rejection into the void', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify, process should stay alive or new one should get instantiated', - reality: 'This feature is not implemented yet', - success: 'No' + { + name: "httpStatus", + Description: "What HTTP status should the mocked URL return", + defaultValue: "500", + type: "number" + } + ], + schedule: { + type: "peaks", + sleepTimeBetweenPeaksInMS: 3000, + pickLengthInMS: 10000, + forHowLong: 8000 }, - { - name: "memory-load", - friendlyName: "Memory is overloaded", - file: "memory-load", - active: true, - properties: { - maxMemorySizeInMB: 10 - }, - schedule: { - type: "one-time-schedule", - delay: 1000, - fadeOutInMS: 30000 - }, - description: 'Our monkey constantly increases the RAM, if no limit was specified the entire allowed 1.7GB will be used', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify', - reality: 'This feature is not implemented yet', - success: 'No' - }, - { - name: "cpu-load", - friendlyName: "Busy CPU", - file: "cpu-load", - active: true, - properties: {}, - schedule: { - type: "peaks", - sleepTimeBetweenPeaksInMS: 3000, - pickLengthInMS: 10000, - forHowLong: 8000 - }, - description: 'Our monkey constantly keeps the CPU busy (without blocking the event loop)', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify', - reality: 'This feature is not implemented yet', - success: 'No' - }, - { - name: "blocked-event-loop", - friendlyName: "Blocked event loop", - file: "blocked-event-loop", - active: true, - properties: {}, - schedule: { - type: "peaks", - sleepTimeBetweenPeaksInMS: 3000, - pickLengthInMS: 10000, - forHowLong: 8000 - }, - description: 'Our monkey constantly blocks the event loop', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify', - reality: 'This feature is not implemented yet', - success: 'No' - }, - { - name: "broken-http-integration", - friendlyName: "Broken Integration", - file: "broken-http-integration", - active: true, - properties: {}, - schedule: { - type: "peaks", - sleepTimeBetweenPeaksInMS: 3000, - pickLengthInMS: 10000, - forHowLong: 8000 - }, - description: 'Our monkey intercepts HTTP calls and return random HTTP erros on their behalf', - lastHappened: new Date(), - expectations: 'Your monitoring system should notify, code should find alternate routes to achieve a decent UX', - reality: 'This feature is not implemented yet', - success: 'No' - } - ]; - - return result; - } - -} + description: 'Our monkey intercepts HTTP calls and return random HTTP erros on their behalf', + lastHappened: new Date(), + expectations: 'Your monitoring system should notify, code should find alternate routes to achieve a decent UX', + reality: 'This feature is not implemented yet', + success: 'No' + } + ]; + + return result; + } + + } -module.exports = PranksDefinition; \ No newline at end of file + module.exports = PranksDefinition; \ No newline at end of file diff --git a/tests/manual-testing-with-simple-web-app/index.js b/tests/manual-testing-with-simple-web-app/index.js index c551d89..c28d228 100644 --- a/tests/manual-testing-with-simple-web-app/index.js +++ b/tests/manual-testing-with-simple-web-app/index.js @@ -8,6 +8,7 @@ const port = process.env.PORT || 8080; app.listen(port); //I wish I could use also a command line -> chaos-monkey -f app.js --test-command='npm test' -r report.html +console.log("Demo web app is now starting") ChaosMonkey.initialize(app); var router = express.Router(); @@ -23,14 +24,4 @@ router.get("/api/products", (req, res) => { }); -process.on("uncaughtException", error => { - console.log(`Uncaught error is now handled error`); - console.log(error); -}); - -process.on("unhandledRejection", (reason, p) => { - console.log(`Uncaught promise is now handled error`); - console.log(p); -}); - app.use(router); \ No newline at end of file diff --git a/ui/src/components/ChaosTest/ChooseChaos.jsx b/ui/src/components/ChaosTest/ChooseChaos.jsx index 484c924..d6f7c9c 100644 --- a/ui/src/components/ChaosTest/ChooseChaos.jsx +++ b/ui/src/components/ChaosTest/ChooseChaos.jsx @@ -43,7 +43,7 @@ class ChooseChaos extends Component { makeCall() { this.interval = setInterval(() => { this.props.store.callApi('http://localhost:8081/chaos/pranks-pool'); - }, 500); + }, 2000); } selectPrank = prank => { diff --git a/ui/src/stores/prankStore.js b/ui/src/stores/prankStore.js index 02273a9..323f465 100644 --- a/ui/src/stores/prankStore.js +++ b/ui/src/stores/prankStore.js @@ -63,6 +63,7 @@ class PrankStore { console.log('Socket Connected'); socket.on('new-prank-activity', data => { if (data) { + console.log(`Just got a new prank ${data}`) this.pranksLog.push(data); } else { console.log(`a NULL prank just ran ${JSON.stringify(data)}`);