Comparing version 8.1.1 to 8.1.2
101
lib/index.js
'use strict'; | ||
// Load modules | ||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
const Schema = require('./schema'); | ||
const Monitor = require('./monitor'); | ||
const internals = { | ||
onPostStop(monitor) { | ||
return (server, h) => { | ||
const internals = {}; | ||
return monitor.stop(); | ||
}; | ||
internals.reporters = [ | ||
Joi.object({ | ||
pipe: Joi.func().required(), | ||
start: Joi.func() | ||
}) | ||
.unknown(), | ||
Joi.string() | ||
.valid('stdout', 'stderr'), | ||
Joi.object({ | ||
module: Joi.alternatives().try(Joi.string(), Joi.func()).required(), | ||
name: Joi.string(), | ||
args: Joi.array().default([]) | ||
}) | ||
]; | ||
internals.schema = Joi.object({ | ||
includes: Joi.object({ | ||
request: Joi.array().items(Joi.string().valid('headers', 'payload')).default([]), | ||
response: Joi.array().items(Joi.string().valid('headers', 'payload')).default([]) | ||
}) | ||
.default({ | ||
request: [], | ||
response: [] | ||
}), | ||
reporters: Joi.object() | ||
.pattern(/./, Joi.array().items(...internals.reporters)) | ||
.default({}), | ||
extensions: Joi.array() | ||
.items(Joi.string().invalid('log', 'ops', 'request', 'response')) | ||
.default([]), | ||
ops: Joi.alternatives([ | ||
Joi.object(), | ||
Joi.bool().allow(false) | ||
]) | ||
.default({ | ||
config: {}, | ||
interval: 15000 | ||
}) | ||
}) | ||
.unknown(false); | ||
exports.plugin = { | ||
pkg: require('../package.json'), | ||
requirements: { | ||
hapi: '>=17.0.0' | ||
}, | ||
onPreStart(monitor, options) { | ||
register: function (server, options) { | ||
return (server, h) => { | ||
const settings = Joi.attempt(options, internals.schema); | ||
const monitor = new Monitor(server, settings); | ||
const interval = options.ops.interval; | ||
monitor.startOps(interval); | ||
}; | ||
server.ext('onPostStop', internals.onPostStop(monitor)); | ||
server.ext('onPreStart', internals.onPreStart(monitor, settings)); | ||
monitor.start(); | ||
} | ||
}; | ||
exports.register = (server, options) => { | ||
const result = Joi.validate(options, Schema.monitor); | ||
Hoek.assert(!result.error, 'Invalid', 'monitorOptions', 'options', result.error); | ||
internals.onPostStop = function (monitor) { | ||
const monitor = new Monitor(server, result.value); | ||
server.ext([{ | ||
type: 'onPostStop', | ||
method: internals.onPostStop(monitor) | ||
}, { | ||
type: 'onPreStart', | ||
method: internals.onPreStart(monitor, result.value) | ||
}]); | ||
return (server, h) => { | ||
monitor.start(); | ||
return monitor.stop(); | ||
}; | ||
}; | ||
exports.pkg = require('../package.json'); | ||
internals.onPreStart = function (monitor, options) { | ||
return (server, h) => { | ||
const interval = options.ops.interval; | ||
monitor.startOps(interval); | ||
}; | ||
}; |
'use strict'; | ||
// Load modules | ||
const Os = require('os'); | ||
@@ -15,4 +13,2 @@ | ||
// Declare internals | ||
const internals = { | ||
@@ -23,3 +19,5 @@ host: Os.hostname(), | ||
class Monitor { | ||
module.exports = internals.Monitor = class { | ||
constructor(server, options) { | ||
@@ -69,3 +67,2 @@ | ||
}; | ||
} | ||
@@ -80,6 +77,6 @@ | ||
internals.forOwn(this.settings.reporters, (streamsSpec, reporterName) => { | ||
for (const reporterName in this.settings.reporters) { | ||
const streamsSpec = this.settings.reporters[reporterName]; | ||
if (!streamsSpec.length) { | ||
return; | ||
continue; | ||
} | ||
@@ -92,2 +89,3 @@ | ||
// Already created stream | ||
if (typeof spec.pipe === 'function') { | ||
@@ -98,3 +96,4 @@ streamObjs.push(spec); | ||
// if this is stderr or stdout | ||
// If this is stderr or stdout | ||
if (process[spec]) { | ||
@@ -126,3 +125,3 @@ streamObjs.push(process[spec]); | ||
}); | ||
}); | ||
} | ||
@@ -132,2 +131,3 @@ this._state.report = true; | ||
// Initialize Events | ||
this._server.events.on('log', this._logHandler); | ||
@@ -144,6 +144,6 @@ this._server.events.on({ name: 'request', channels: ['error'] }, this._errorHandler); | ||
// Events can not be any of ['log', 'ops', 'request', 'response', 'tail'] | ||
for (let i = 0; i < this.settings.extensions.length; ++i) { | ||
const event = this.settings.extensions[i]; | ||
this._server.events.on(this.settings.extensions[i], (...args) => { | ||
for (const event of this.settings.extensions) { | ||
this._server.events.on(event, (...args) => { | ||
const payload = { | ||
@@ -154,2 +154,3 @@ event, | ||
}; | ||
this.push(() => Object.assign({}, payload)); | ||
@@ -184,13 +185,2 @@ }); | ||
} | ||
} | ||
module.exports = Monitor; | ||
internals.forOwn = (obj, func) => { | ||
const keys = Object.keys(obj); | ||
for (let i = 0; i < keys.length; ++i) { | ||
const key = keys[i]; | ||
func(obj[key], key); | ||
} | ||
}; |
'use strict'; | ||
// Load modules | ||
const Stream = require('stream'); | ||
const Stream = require('stream'); | ||
const Hoek = require('hoek'); | ||
// Declare internals | ||
const internals = {}; | ||
internals.extractConfig = function (request) { | ||
@@ -17,4 +16,7 @@ | ||
// Payload for "log" events | ||
class ServerLog { | ||
exports.ServerLog = class { | ||
constructor(event) { | ||
@@ -29,7 +31,9 @@ | ||
} | ||
} | ||
}; | ||
// Payload for "error" events | ||
class RequestError { | ||
exports.RequestError = class { | ||
constructor(reqOptions, request, requestError) { | ||
@@ -50,14 +54,15 @@ | ||
} | ||
toJSON() { | ||
const result = Object.assign({}, this, { | ||
error: this.error.output.payload.message | ||
}); | ||
const result = Object.assign({}, this, { error: this.error.output.payload.message }); | ||
return result; | ||
} | ||
} | ||
}; | ||
// Payload for "response" events | ||
class RequestSent { | ||
exports.RequestSent = class { | ||
constructor(reqOptions, resOptions, request, server) { | ||
@@ -80,2 +85,5 @@ | ||
this.httpVersion = request.raw.req.httpVersion; | ||
this.route = request.route.path; | ||
this.log = request.route.settings.log.collect ? request.logs : []; | ||
this.source = { | ||
@@ -86,8 +94,3 @@ remoteAddress: request.info.remoteAddress, | ||
}; | ||
this.route = request.route.path; | ||
/* $lab:coverage:off$ */ | ||
this.log = (request.route.settings.log === false ? [] : request.logs); // Explicitly compare to false for hapi < v15 | ||
/* $lab:coverage:on$ */ | ||
this.tags = request.route.settings.tags; | ||
@@ -103,16 +106,21 @@ | ||
if (resOptions.headers && request.response) { | ||
this.responseHeaders = request.response.headers; | ||
if (request.response) { | ||
if (resOptions.headers) { | ||
this.responseHeaders = request.response.headers; | ||
} | ||
if (resOptions.payload) { | ||
this.responsePayload = request.response.source; | ||
} | ||
} | ||
if (resOptions.payload && request.response) { | ||
this.responsePayload = request.response.source; | ||
} | ||
this.config = internals.extractConfig(request); | ||
} | ||
} | ||
}; | ||
// Payload for "ops" events | ||
class Ops { | ||
exports.Ops = class { | ||
constructor(ops) { | ||
@@ -124,2 +132,3 @@ | ||
this.pid = process.pid; | ||
this.os = { | ||
@@ -130,2 +139,3 @@ load: ops.osload, | ||
}; | ||
this.proc = { | ||
@@ -136,2 +146,3 @@ uptime: ops.psup, | ||
}; | ||
this.load = { | ||
@@ -144,7 +155,9 @@ requests: ops.requests, | ||
} | ||
} | ||
}; | ||
// Payload for "request" events via request.log | ||
class RequestLog { | ||
exports.RequestLog = class { | ||
constructor(reqOptions, request, event) { | ||
@@ -167,5 +180,7 @@ | ||
} | ||
} | ||
}; | ||
class NoOp extends Stream.Transform { | ||
exports.NoOp = class extends Stream.Transform { | ||
constructor() { | ||
@@ -175,2 +190,3 @@ | ||
} | ||
_transform(value, encoding, callback) { | ||
@@ -180,17 +196,2 @@ | ||
} | ||
} | ||
const timeout = function (ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
}; | ||
module.exports = { | ||
ServerLog, | ||
RequestError, | ||
Ops, | ||
RequestLog, | ||
RequestSent, | ||
NoOp, | ||
timeout | ||
}; |
{ | ||
"name": "good", | ||
"description": "Server and process monitoring plugin", | ||
"version": "8.1.1", | ||
"version": "8.1.2", | ||
"repository": "git://github.com/hapijs/good", | ||
@@ -15,24 +15,18 @@ "main": "lib/index.js", | ||
], | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"dependencies": { | ||
"hoek": "5.x.x", | ||
"joi": "13.x.x", | ||
"hoek": "6.x.x", | ||
"joi": "14.x.x", | ||
"oppsy": "2.x.x", | ||
"pumpify": "1.3.x" | ||
}, | ||
"peerDependencies": { | ||
"hapi": ">=17.x.x" | ||
}, | ||
"devDependencies": { | ||
"code": "5.x.x", | ||
"hapi": "17.x.x", | ||
"lab": "15.x.x", | ||
"lab": "18.x.x", | ||
"wreck": "14.x.x" | ||
}, | ||
"scripts": { | ||
"test": "lab -m 5000 -t 100 -v -La code" | ||
"test": "lab -m 5000 -t 100 -L -a code" | ||
}, | ||
"license": "BSD-3-Clause" | ||
} |
@@ -7,3 +7,3 @@ ![good Logo](images/good.png) | ||
Lead Maintainer: [Adam Bretz](https://github.com/arb) | ||
Lead Maintainer: [Open position](https://github.com/hapijs/good/issues/589) | ||
@@ -10,0 +10,0 @@ *good 8 only supports hapi 17+ for hapi 16 please use good 7* |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
17715
4
0
320
- Removedaccept@3.1.3(transitive)
- Removedammo@3.0.3(transitive)
- Removedb64@4.1.2(transitive)
- Removedboom@7.3.0(transitive)
- Removedbounce@1.2.3(transitive)
- Removedbourne@1.3.3(transitive)
- Removedcall@5.0.3(transitive)
- Removedcatbox@10.0.6(transitive)
- Removedcatbox-memory@4.0.1(transitive)
- Removedcontent@4.0.6(transitive)
- Removedcryptiles@4.1.3(transitive)
- Removedhapi@18.1.0(transitive)
- Removedheavy@6.1.2(transitive)
- Removedhoek@5.0.4(transitive)
- Removediron@5.0.6(transitive)
- Removedjoi@13.7.0(transitive)
- Removedmime-db@1.53.0(transitive)
- Removedmimos@4.0.2(transitive)
- Removednigel@3.0.4(transitive)
- Removedpez@4.0.5(transitive)
- Removedpodium@3.2.0(transitive)
- Removedshot@4.0.7(transitive)
- Removedsomever@2.0.0(transitive)
- Removedstatehood@6.0.9(transitive)
- Removedsubtext@6.0.12(transitive)
- Removedteamwork@3.2.0(transitive)
- Removedvise@3.0.2(transitive)
- Removedwreck@14.2.0(transitive)
Updatedhoek@6.x.x
Updatedjoi@14.x.x