Skip to content

Instantly share code, notes, and snippets.

@watson
Created August 27, 2018 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watson/1113e69b37fedb8e13ed599789eb2426 to your computer and use it in GitHub Desktop.
Save watson/1113e69b37fedb8e13ed599789eb2426 to your computer and use it in GitHub Desktop.
Mock Elastic APM Server that always responds with an error before bothering to read the entire request body
'use strict'
const zlib = require('zlib')
const http = require('http')
const body = zlib.gzipSync(JSON.stringify({
errors: {
ERR_QUEUE_FULL: {
count: 23,
message: 'queue is full'
},
ERR_PROCESSING_TIMEOUT: {
count: 2,
message: 'timeout while waiting to process'
},
ERR_SCHEMA_VALIDATION: {
count: 3,
message: 'could not validate object',
documents: [
{error: '<json-schema-err>', document: '<ndjson-obj>'}
]
},
ERR_INVALID_JSON: {
count: 24,
message: 'could not decode JSON',
documents: [
{error: '<json-decoding-err>', document: '<ndjson-obj>'}
]
},
ERR_INVALID_CONTENT_TYPE: {
message: 'invalid content-type: \'html/text\''
},
ERR_SERVER_ERROR: {
message: 'i/o timeout while reading..'
}
},
accepted: 2320,
dropped: 25,
invalid: 3
}))
const server = http.createServer(function (req, res) {
console.log(req.method, req.url)
res.writeHead(500, {
'Content-Encoding': 'gzip',
'Content-Length': body.length,
'Content-Type': 'application/json'
})
res.end(body)
})
server.listen(8200, function () {
console.log('Server running on http://localhost:8200')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment