Skip to content

Commit

Permalink
Revert "chore: remove workload script (#33)"
Browse files Browse the repository at this point in the history
This reverts commit 3a1a2a5.
  • Loading branch information
watson committed Sep 11, 2018
1 parent 3a1a2a5 commit 9d2bc5f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
70 changes: 70 additions & 0 deletions .workload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict'

require('elastic-apm-node').start({
servieName: process.env.WORKLOAD_ELASTIC_APM_SERVICE_NAME,
serverUrl: process.env.WORKLOAD_ELASTIC_APM_SERVER_URL,
active: process.env.NODE_ENV === 'production'
})

var Workload = require('workload')
var conf = require('./server/config')
var url = conf.server.url + '/'
var api = url + 'api/'

module.exports = {
max: 120,
filters: [
Workload.stdFilters.expand,
Workload.stdFilters.workdays,
fillOutOrder
],
requests: [
{weight: 10, url: url},
{weight: 10, url: url + 'favicon.ico'},
{weight: 1, url: url, method: 'OPTIONS'},

// api
{weight: 8, url: api + 'stats'},
{weight: 7, url: api + 'products'},
{weight: 8, url: api + 'products/top'},
{weight: 6, url: api + 'products/{1..6}'},
{weight: 3, url: api + 'products/{1..6}/customers'},
{weight: 1, url: api + 'products/5/customers?count=orders&limit=50'},
{weight: 3, url: api + 'types'},
{weight: 3, url: api + 'types/{1..3}'},
{weight: 5, url: api + 'customers'},
{weight: 4, url: api + 'customers/{1..1000}'},
{weight: 7, url: api + 'orders'},
{weight: 1, url: api + 'orders', method: 'POST'},
{weight: 6, url: api + 'orders/{1..500}'},

// errors
{weight: 2, url: url + 'log-error'},
{weight: 2, url: url + 'log-message'},
{weight: 1, url: url + 'is-it-coffee-time'},
{weight: 1, url: url + 'throw-error'},
{weight: 1, url: url + 'throw-async-error'}
]
}

function fillOutOrder (req, next) {
if (req.method === 'POST' && req.url === api + 'orders') {
var order = {
customer_id: randId(1000),
lines: []
}
for (var n = 0; n < 5; n++) {
order.lines.push({id: randId(3), amount: rand(3) + 1})
}
req.json = order
}
next(req)
}

function rand (max) {
return Math.round(Math.random() * max)
}

function randId (max) {
return rand(max - 1) + 1
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"express": "^4.14.0",
"pg": "^6.1.2",
"redis": "^2.6.3",
"request": "^2.79.0"
"request": "^2.79.0",
"workload": "^2.3.0"
},
"devDependencies": {
"dotenv": "^4.0.0",
Expand All @@ -25,7 +26,8 @@
"client-pull": "(cd client && git pull)",
"client-install": "npm install --prefix client",
"client-build": "npm run build --prefix client",
"start": "node server.js"
"start": "node server.js",
"workload": "workload -f .workload.js"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 9d2bc5f

Please sign in to comment.