From 034b97df67ebeefe85eee608634ee0fce8a4e259 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Mon, 7 Oct 2019 11:03:17 -0700 Subject: [PATCH 01/16] Merge readme info --- API.md | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 241 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index e389db9..ba02f55 100644 --- a/API.md +++ b/API.md @@ -1,11 +1,242 @@ +## Introduction -## good - -**good** is a process monitor that listens for one or more of the below 'event types'. All of these events, _except_ 'ops' map to a hapi event documented [here](https://github.com/hapijs/hapi/blob/master/API.md#server-events). +**good** is a hapi plugin process monitor that listens for one or more of the below 'event types'. All of these events, _except_ 'ops' map to a hapi event documented [here](https://github.com/hapijs/hapi/blob/master/API.md#server-events). Applications with multiple server instances, each with its own monitor should only include one _log_ subscription per destination as general events are a process-wide facility and will result in duplicated log events. +Note: this module is being deprecated on December 1st, 2019 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging). + +## Example Usage + +### Log to Console + +```js +const Hapi = require('@hapi/hapi'); + + +const start = async function () { + + const server = Hapi.server(); + + const handler = function (request, h) { + + request.server.log(['a', 'b', 'c'], 'some message'); + return 'ok'; + }; + + server.route({ path: '/', method: 'GET', handler }) + + await server.register({ + plugin: require('@hapi/good'), + options: { + ops: { + interval: 1000 + }, + reporters: { + myConsoleReporter: [ + { + module: '@hapi/good-squeeze', + name: 'Squeeze', + args: [{ log: '*', response: '*', ops: '*' }] + }, + { + module: '@hapi/good-console' + }, + 'stdout' + ] + } + } + }); + + await server.start(); + console.info(`Server started at ${server.info.uri}`); + await server.inject('/'); +}; + +start(); +``` + +This reporter spec logs ops statistics, request responses, and server log events to the console. It should log to the console something like: +``` +Server started at http://localhost:41759 +190921/234014.495, [log,a,b,c] data: some message +190921/234014.494, (1569109214494:localhost:3616:k0u742ki:10000) [response] http://localhost:41759: get / {} 200 (6ms) +190921/234015.494, [ops] memory: 52Mb, uptime (seconds): 1.148846148, load: [0.02734375,0.0302734375,0] +190921/234016.493, [ops] memory: 52Mb, uptime (seconds): 2.149207332, load: [0.02734375,0.0302734375,0] +190921/234017.494, [ops] memory: 52Mb, uptime (seconds): 3.149818512, load: [0.02734375,0.0302734375,0] +``` + +It uses `@hapi/good-squeeze` to select only log and response events. + +Events that pass the filter stream to `@hapi/good-console` for formatting. See the `good console` [constructor docs](https://github.com/hapijs/good-console#new-goodconsoleconfig) for details on `args` values. + +Formatted events stream to `process.stdout` for display. + +### Log to file + +Create a basic write stream class and use with good: + +```js +const Fs = require('fs-extra'); +const Hapi = require('@hapi/hapi'); + + +class GoodFile extends Fs.WriteStream { + + constructor(path, options) { + + const defaults = { + encoding: 'utf8', + flags: 'a', + mode: 0o666 + }; + + const settings = Object.assign({}, defaults, options); + settings.fd = -1; // Prevent open from being called in `super` + + super(path, settings); + this.open(); + } + + open() { + + this.fd = null; + Fs.ensureFile(this.path, (err) => { + + if (err) { + this.destroy(); + this.emit('error', err); + return; + } + + super.open(); + }); + } +} + + +const start = async function () { + + const server = Hapi.server(); + + const handler = function (request, h) { + + request.server.log(['a', 'b', 'c'], 'some message'); + return 'ok'; + }; + + server.route({ path: '/', method: 'GET', handler }) + + await server.register({ + plugin: require('@hapi/good'), + options: { + ops: { + interval: 1000 + }, + reporters: { + myReporter: [ + { + module: '@hapi/good-squeeze', // Transform payload into a safe string + name: 'SafeJson' + }, + { + module: GoodFile, + args: ['./log.json'] + } + ] + } + } + }); + + await server.start(); + server.log(['log'], 'Server Started'); + await server.inject('/'); +}; + +start(); +``` + +This will create or append a file `./log.json` with the following: +```json +{"event":"log","timestamp":1569109412144,"tags":["log"],"data":"Server Started","pid":3630} +{"event":"log","timestamp":1569109412148,"tags":["a","b","c"],"data":"some message","pid":3630} +{"event":"response","timestamp":1569109412146,"id":"1569109412146:localhost:3630:k0u78b2x:10000","instance":"http://localhost:44883","method":"get","path":"/","query":{},"responseTime":5,"statusCode":200,"pid":3630,"httpVersion":"1.1","route":"/","log":[],"source":{"remoteAddress":"127.0.0.1","userAgent":"shot"},"config":{}} +{"event":"ops","timestamp":1569109413146,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851831},"proc":{"uptime":1.160361771,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8310912,"external":1271839},"delay":0.9361389875411987},"load":{"requests":{"44883":{"total":1,"disconnects":0,"statusCodes":{"200":1}}},"responseTimes":{"44883":{"avg":5,"max":5}},"sockets":{"http":{"total":0},"https":{"total":0}}}} +{"event":"ops","timestamp":1569109414145,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851832},"proc":{"uptime":2.160405932,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8358032,"external":1271887},"delay":0.29865598678588867},"load":{"requests":{"44883":{"total":0,"disconnects":0,"statusCodes":{}}},"responseTimes":{"44883":{"avg":null,"max":0}},"sockets":{"http":{"total":0},"https":{"total":0}}}} +``` + +### Add custom transform stream + +```js +const Stream = require('stream'); +const Hapi = require('@hapi/hapi'); + + +class LogDateTransform extends Stream.Transform { + + constructor() { + + super({ objectMode: true }); + } + + _transform(data, enc, next) { + + const date = new Date(Date.now()).toLocaleString('en-US'); + + if (data.data) { + return next(null, `${data.event}: ${date}: ${data.data}\n`); + } + + next(null); + } +} + + +const start = async function () { + + const server = Hapi.server(); + + const handler = function (request, h) { + + request.server.log(['a', 'b', 'c'], 'some message'); + return 'ok'; + }; + + server.route({ path: '/', method: 'GET', handler }) + + await server.register({ + plugin: require('@hapi/good'), + options: { + ops: { + interval: 1000 + }, + reporters: { + myReporter: [ + new LogDateTransform(), + 'stdout' + ] + } + } + }); + + await server.start(); + server.log('info', 'Server is running...'); + await server.inject('/'); +}; + +start(); +``` + +This reporter logs data with a date time, writing to the console something like: + +``` +log: 9 / 21 / 2019, 4: 47: 25 PM: Server is running... +log: 9 / 21 / 2019, 4: 47: 25 PM: some message +``` + +## Usage + ### Options - `[includes]` - optional configuration object - `[request]` - array of extra hapi request object fields to supply to reporters on "request", "response", and "error" events. Valid values ['headers', 'payload']. Defaults to `[]`. @@ -237,3 +468,10 @@ Because the extension payloads from hapi can vary from one version to another an - `event` - the event name. - `timestamp` - the time the event occurred. - `payload` - array of arguments hapi passed to our event handler function + +## Existing streams + +The following streams are maintained by the hapi community and are known to work with good. Any transform or write stream can work with good, these are just a few inside the hapijs organization. + +- [good-squeeze](https://github.com/hapijs/good-squeeze) +- [good-console](https://github.com/hapijs/good-console) From 1ed5031e1eb5d16d2bcaa04c120e7706b0089fe8 Mon Sep 17 00:00:00 2001 From: Jarrod Yellets Date: Mon, 7 Oct 2019 20:03:39 +0200 Subject: [PATCH 02/16] Update README to new template (#628) --- README.md | 252 +++--------------------------------------------------- 1 file changed, 10 insertions(+), 242 deletions(-) diff --git a/README.md b/README.md index dd438f3..75675ee 100755 --- a/README.md +++ b/README.md @@ -1,250 +1,18 @@ - + # @hapi/good -[**hapi**](https://github.com/hapijs/hapi) process monitoring +#### hapi process monitoring. -[![Build Status](https://secure.travis-ci.org/hapijs/good.svg?branch=master)](http://travis-ci.org/hapijs/good) +**good** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together. -**good** is a hapi plugin to monitor and report on a variety of hapi server events as well as ops information from the host machine. It listens for events emitted by hapi server instances and pushes standardized events to a collection of streams. +### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support -## Note: this module is being deprecated on December 1st, 2019 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging). - -## Example Usage - -### Log to Console - -```js -const Hapi = require('@hapi/hapi'); - - -const start = async function () { - - const server = Hapi.server(); - - const handler = function (request, h) { - - request.server.log(['a', 'b', 'c'], 'some message'); - return 'ok'; - }; - - server.route({ path: '/', method: 'GET', handler }) - - await server.register({ - plugin: require('@hapi/good'), - options: { - ops: { - interval: 1000 - }, - reporters: { - myConsoleReporter: [ - { - module: '@hapi/good-squeeze', - name: 'Squeeze', - args: [{ log: '*', response: '*', ops: '*' }] - }, - { - module: '@hapi/good-console' - }, - 'stdout' - ] - } - } - }); - - await server.start(); - console.info(`Server started at ${server.info.uri}`); - await server.inject('/'); -}; - -start(); -``` - -This reporter spec logs ops statistics, request responses, and server log events to the console. It should log to the console something like: -``` -Server started at http://localhost:41759 -190921/234014.495, [log,a,b,c] data: some message -190921/234014.494, (1569109214494:localhost:3616:k0u742ki:10000) [response] http://localhost:41759: get / {} 200 (6ms) -190921/234015.494, [ops] memory: 52Mb, uptime (seconds): 1.148846148, load: [0.02734375,0.0302734375,0] -190921/234016.493, [ops] memory: 52Mb, uptime (seconds): 2.149207332, load: [0.02734375,0.0302734375,0] -190921/234017.494, [ops] memory: 52Mb, uptime (seconds): 3.149818512, load: [0.02734375,0.0302734375,0] -``` - -It uses `@hapi/good-squeeze` to select only log and response events. - -Events that pass the filter stream to `@hapi/good-console` for formatting. See the `good console` [constructor docs](https://github.com/hapijs/good-console#new-goodconsoleconfig) for details on `args` values. - -Formatted events stream to `process.stdout` for display. - -### Log to file - -Create a basic write stream class and use with good: - -```js -const Fs = require('fs-extra'); -const Hapi = require('@hapi/hapi'); - - -class GoodFile extends Fs.WriteStream { - - constructor(path, options) { - - const defaults = { - encoding: 'utf8', - flags: 'a', - mode: 0o666 - }; - - const settings = Object.assign({}, defaults, options); - settings.fd = -1; // Prevent open from being called in `super` - - super(path, settings); - this.open(); - } - - open() { - - this.fd = null; - Fs.ensureFile(this.path, (err) => { - - if (err) { - this.destroy(); - this.emit('error', err); - return; - } - - super.open(); - }); - } -} - - -const start = async function () { - - const server = Hapi.server(); +## Useful resources - const handler = function (request, h) { +- [Documentation and API](https://hapi.dev/family/good/) +- [Version status](https://hapi.dev/resources/status/#good) (builds, dependencies, node versions, licenses, eol) +- [Project policies](https://hapi.dev/policies/) +- [Free and commercial support options](https://hapi.dev/support/) - request.server.log(['a', 'b', 'c'], 'some message'); - return 'ok'; - }; - - server.route({ path: '/', method: 'GET', handler }) - - await server.register({ - plugin: require('@hapi/good'), - options: { - ops: { - interval: 1000 - }, - reporters: { - myReporter: [ - { - module: '@hapi/good-squeeze', // Transform payload into a safe string - name: 'SafeJson' - }, - { - module: GoodFile, - args: ['./log.json'] - } - ] - } - } - }); - - await server.start(); - server.log(['log'], 'Server Started'); - await server.inject('/'); -}; - -start(); -``` - -This will create or append a file `./log.json` with the following: -```json -{"event":"log","timestamp":1569109412144,"tags":["log"],"data":"Server Started","pid":3630} -{"event":"log","timestamp":1569109412148,"tags":["a","b","c"],"data":"some message","pid":3630} -{"event":"response","timestamp":1569109412146,"id":"1569109412146:localhost:3630:k0u78b2x:10000","instance":"http://localhost:44883","method":"get","path":"/","query":{},"responseTime":5,"statusCode":200,"pid":3630,"httpVersion":"1.1","route":"/","log":[],"source":{"remoteAddress":"127.0.0.1","userAgent":"shot"},"config":{}} -{"event":"ops","timestamp":1569109413146,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851831},"proc":{"uptime":1.160361771,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8310912,"external":1271839},"delay":0.9361389875411987},"load":{"requests":{"44883":{"total":1,"disconnects":0,"statusCodes":{"200":1}}},"responseTimes":{"44883":{"avg":5,"max":5}},"sockets":{"http":{"total":0},"https":{"total":0}}}} -{"event":"ops","timestamp":1569109414145,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851832},"proc":{"uptime":2.160405932,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8358032,"external":1271887},"delay":0.29865598678588867},"load":{"requests":{"44883":{"total":0,"disconnects":0,"statusCodes":{}}},"responseTimes":{"44883":{"avg":null,"max":0}},"sockets":{"http":{"total":0},"https":{"total":0}}}} -``` - -### Add custom transform stream - -```js -const Stream = require('stream'); -const Hapi = require('@hapi/hapi'); - - -class LogDateTransform extends Stream.Transform { - - constructor() { - - super({ objectMode: true }); - } - - _transform(data, enc, next) { - - const date = new Date(Date.now()).toLocaleString('en-US'); - - if (data.data) { - return next(null, `${data.event}: ${date}: ${data.data}\n`); - } - - next(null); - } -} - - -const start = async function () { - - const server = Hapi.server(); - - const handler = function (request, h) { - - request.server.log(['a', 'b', 'c'], 'some message'); - return 'ok'; - }; - - server.route({ path: '/', method: 'GET', handler }) - - await server.register({ - plugin: require('@hapi/good'), - options: { - ops: { - interval: 1000 - }, - reporters: { - myReporter: [ - new LogDateTransform(), - 'stdout' - ] - } - } - }); - - await server.start(); - server.log('info', 'Server is running...'); - await server.inject('/'); -}; - -start(); -``` - -This reporter logs data with a date time, writing to the console something like: - -``` -log: 9 / 21 / 2019, 4: 47: 25 PM: Server is running... -log: 9 / 21 / 2019, 4: 47: 25 PM: some message -``` - -## Existing streams - -The following streams are maintained by the hapi community and are known to work with good. Any transform or write stream can work with good, these are just a few inside the hapijs organization. - -- [good-squeeze](https://github.com/hapijs/good-squeeze) -- [good-console](https://github.com/hapijs/good-console) - -## API - -See the [API Reference](API.md). +## Note: this module is being deprecated on December 1st, 2019 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging). From 17b49408810e085c0cee168f1a257ce5e317b5ec Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Fri, 11 Oct 2019 14:09:34 -0700 Subject: [PATCH 03/16] Fix #629 --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index b36c528..9323544 100755 --- a/lib/utils.js +++ b/lib/utils.js @@ -75,7 +75,7 @@ exports.RequestSent = class { this.method = request.method; this.path = request.path; this.query = request.query; - this.responseTime = request.info.completed - request.info.received; + this.responseTime = (request.info.completed || request.info.responded) - request.info.received; // $lab:coverage:ignore$ this.statusCode = res.statusCode; this.pid = process.pid; this.httpVersion = request.raw.req.httpVersion; From 6335a80e283ac92a097acb22b9cc4d7389ae8c1f Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Fri, 11 Oct 2019 14:09:37 -0700 Subject: [PATCH 04/16] 8.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3a0e48..1b4ada9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/good", "description": "Server and process monitoring plugin", - "version": "8.2.3", + "version": "8.2.4", "repository": "git://github.com/hapijs/good", "main": "lib/index.js", "keywords": [ From 164f88bae70e63582a199b044ed41b47e39fd348 Mon Sep 17 00:00:00 2001 From: nwhitmont Date: Sun, 5 Jan 2020 12:32:10 -0800 Subject: [PATCH 05/16] Add link to changelog (#630) * rm changelog * add link to changelog --- CHANGELOG.md | 3 --- README.md | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 72bda07..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -Breaking changes are documented using GitHub issues, see [issues labeled "release notes"](https://github.com/hapijs/good/issues?q=is%3Aissue+label%3A%22release+notes%22). - -If you want changes of a specific minor or patch release, you can browse the [GitHub milestones](https://github.com/hapijs/good/milestones?state=closed&direction=asc&sort=due_date). diff --git a/README.md b/README.md index 75675ee..7c796b4 100755 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ - [Documentation and API](https://hapi.dev/family/good/) - [Version status](https://hapi.dev/resources/status/#good) (builds, dependencies, node versions, licenses, eol) +- [Changelog](https://hapi.dev/family/good/changelog/) - [Project policies](https://hapi.dev/policies/) - [Free and commercial support options](https://hapi.dev/support/) From 5a5dbed2e03e8c7d0b470c93b6671cfce5ace6ee Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Fri, 10 Jan 2020 10:32:18 -0800 Subject: [PATCH 06/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c796b4..fe30fe6 100755 --- a/README.md +++ b/README.md @@ -16,4 +16,4 @@ - [Project policies](https://hapi.dev/policies/) - [Free and commercial support options](https://hapi.dev/support/) -## Note: this module is being deprecated on December 1st, 2019 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging). +## Note: this module is being deprecated on December 31st, 2020 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging). From c5c4bd0cdea1572970e2386dc53d88d1829717a7 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Sat, 11 Jan 2020 21:20:56 -0800 Subject: [PATCH 07/16] Update deps. Closes #631. Closes #632. Closes #633 --- .npmignore | 3 --- .travis.yml | 3 +-- LICENSE.md | 2 +- lib/index.js | 3 +-- package.json | 20 ++++++++++++-------- test/fixtures/reporter.js | 4 +++- 6 files changed, 18 insertions(+), 17 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index b3d60fb..0000000 --- a/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!lib/** -!.npmignore \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index d3d2573..93acdcd 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: node_js node_js: - - "8" - - "10" - "12" - "node" @@ -14,3 +12,4 @@ install: env: - HAPI_VERSION="18" + - HAPI_VERSION="19" diff --git a/LICENSE.md b/LICENSE.md index ce2e425..b135f04 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2014-2019, Sideway Inc, and project contributors +Copyright (c) 2014-2020, Sideway Inc, and project contributors Copyright (c) 2012-2014, Walmart. All rights reserved. diff --git a/lib/index.js b/lib/index.js index 01f429b..e80b59f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -58,10 +58,9 @@ internals.schema = Joi.object({ exports.plugin = { - name: 'good', pkg: require('../package.json'), requirements: { - hapi: '>=17.9.0' + hapi: '>=18.4.0' }, register: function (server, options) { diff --git a/package.json b/package.json index 1b4ada9..e61e523 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "version": "8.2.4", "repository": "git://github.com/hapijs/good", "main": "lib/index.js", + "files": [ + "lib" + ], "keywords": [ "process", "monitor", @@ -13,19 +16,20 @@ "plugin" ], "dependencies": { - "@hapi/hoek": "8.x.x", - "@hapi/joi": "16.x.x", - "@hapi/oppsy": "2.x.x", + "@hapi/hoek": "9.x.x", + "@hapi/joi": "17.x.x", + "@hapi/oppsy": "3.x.x", "pumpify": "1.x.x" }, "devDependencies": { - "@hapi/code": "6.x.x", - "@hapi/hapi": "18.x.x", - "@hapi/lab": "20.x.x", - "@hapi/wreck": "15.x.x" + "@hapi/code": "8.x.x", + "@hapi/hapi": "19.x.x", + "@hapi/lab": "22.x.x", + "@hapi/wreck": "17.x.x" }, "scripts": { - "test": "lab -m 5000 -t 100 -L -a @hapi/code" + "test": "lab -m 5000 -t 100 -L -a @hapi/code", + "test-cov-html": "lab -a @hapi/code -r html -o coverage.html" }, "license": "BSD-3-Clause" } diff --git a/test/fixtures/reporter.js b/test/fixtures/reporter.js index 2501157..30fae1b 100755 --- a/test/fixtures/reporter.js +++ b/test/fixtures/reporter.js @@ -6,7 +6,9 @@ const Stream = require('stream'); const internals = {}; -module.exports = class extends Stream.Transform { +module.exports = internals.Reporter = class extends Stream.Transform { + + static name = 'test'; constructor() { From 0dc32407059ee0e9f9b82aeb6ff4c86a798f25d6 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Sat, 11 Jan 2020 21:21:01 -0800 Subject: [PATCH 08/16] 9.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e61e523..978f671 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/good", "description": "Server and process monitoring plugin", - "version": "8.2.4", + "version": "9.0.0", "repository": "git://github.com/hapijs/good", "main": "lib/index.js", "files": [ From 8df8429d3dddc93c50cef856e0b7711f9c1bc986 Mon Sep 17 00:00:00 2001 From: Lloyd Benson Date: Sat, 22 Aug 2020 18:43:18 -0500 Subject: [PATCH 09/16] migrate to new travis format (#634) --- .travis.yml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93acdcd..baf8fe9 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,8 @@ -language: node_js +version: ~> 1.0 -node_js: - - "12" - - "node" -sudo: false - -install: - - "npm install" - - "npm install @hapi/hapi@$HAPI_VERSION" - -env: - - HAPI_VERSION="18" - - HAPI_VERSION="19" +import: + - hapijs/ci-config-travis:node_js.yml@main + - hapijs/ci-config-travis:install_plugin.yml@main + - hapijs/ci-config-travis:os.yml@main + - hapijs/ci-config-travis:env.yml@main From 4ec4ebd8d3be20686f49e934320791e2a46c01ff Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Sat, 22 Aug 2020 19:43:38 -0400 Subject: [PATCH 10/16] update dependencies (#635) --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 978f671..c98851d 100644 --- a/package.json +++ b/package.json @@ -19,12 +19,12 @@ "@hapi/hoek": "9.x.x", "@hapi/joi": "17.x.x", "@hapi/oppsy": "3.x.x", - "pumpify": "1.x.x" + "pumpify": "2.x.x" }, "devDependencies": { "@hapi/code": "8.x.x", - "@hapi/hapi": "19.x.x", - "@hapi/lab": "22.x.x", + "@hapi/hapi": "20.x.x", + "@hapi/lab": "23.x.x", "@hapi/wreck": "17.x.x" }, "scripts": { From 5fb99c962a56bcec68edf83fadfd10486aad9c43 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Sat, 22 Aug 2020 20:11:11 -0400 Subject: [PATCH 11/16] make test work on windows (#636) --- test/monitor.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/monitor.js b/test/monitor.js index 37450b5..7e10b56 100755 --- a/test/monitor.js +++ b/test/monitor.js @@ -1,5 +1,7 @@ 'use strict'; +const Path = require('path'); + const Code = require('@hapi/code'); const Hapi = require('@hapi/hapi'); const Hoek = require('@hapi/hoek'); @@ -121,6 +123,7 @@ describe('Monitor', () => { it('correctly passes dynamic arguments to stream constructors', { plan: 4 }, async () => { const Inc = Reporters.Incrementer; + const fixturePath = Path.join(process.cwd(), 'test', 'fixtures', 'reporter.js'); Reporters.Incrementer = function (starting, multiple) { Reporters.Incrementer = Inc; @@ -130,9 +133,9 @@ describe('Monitor', () => { return new Inc(starting, multiple); }; - require.cache[process.cwd() + '/test/fixtures/reporter.js'].exports = function (options) { + require.cache[fixturePath].exports = function (options) { - require.cache[process.cwd() + '/test/fixtures/reporter.js'].exports = Stringify; + require.cache[fixturePath].exports = Stringify; expect(options).to.be.undefined(); return new Stringify(options); }; @@ -141,7 +144,7 @@ describe('Monitor', () => { reporters: { foo: [ new Reporters.Incrementer(10, 5), - { module: require('./fixtures/reporter') } + { module: require(fixturePath) } ] } }); From 91cdc7932f10f3122c448a0995fdd2d41fd6dc97 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 22 Aug 2020 20:12:28 -0400 Subject: [PATCH 12/16] replace @hapi/joi dependency --- lib/index.js | 42 +++++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/index.js b/lib/index.js index e80b59f..4f49b1f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ 'use strict'; -const Joi = require('@hapi/joi'); +const Validate = require('@hapi/validate'); const Monitor = require('./monitor'); @@ -9,45 +9,45 @@ const internals = {}; internals.reporters = [ - Joi.object({ - pipe: Joi.func().required(), - start: Joi.func() + Validate.object({ + pipe: Validate.func().required(), + start: Validate.func() }) .unknown(), - Joi.string() + Validate.string() .valid('stdout', 'stderr'), - Joi.object({ - module: Joi.alternatives().try(Joi.string(), Joi.func(), Joi.object()).required(), - name: Joi.string(), - args: Joi.array().default([]) + Validate.object({ + module: Validate.alternatives().try(Validate.string(), Validate.func(), Validate.object()).required(), + name: Validate.string(), + args: Validate.array().default([]) }) ]; -internals.schema = Joi.object({ +internals.schema = Validate.object({ - includes: Joi.object({ - request: Joi.array().items(Joi.string().valid('headers', 'payload')).default([]), - response: Joi.array().items(Joi.string().valid('headers', 'payload')).default([]) + includes: Validate.object({ + request: Validate.array().items(Validate.string().valid('headers', 'payload')).default([]), + response: Validate.array().items(Validate.string().valid('headers', 'payload')).default([]) }) .default({ request: [], response: [] }), - reporters: Joi.object() - .pattern(/./, Joi.array().items(...internals.reporters)) + reporters: Validate.object() + .pattern(/./, Validate.array().items(...internals.reporters)) .default({}), - extensions: Joi.array() - .items(Joi.string().invalid('log', 'ops', 'request', 'response')) + extensions: Validate.array() + .items(Validate.string().invalid('log', 'ops', 'request', 'response')) .default([]), - ops: Joi.alternatives([ - Joi.object(), - Joi.bool().allow(false) + ops: Validate.alternatives([ + Validate.object(), + Validate.bool().allow(false) ]) .default({ config: {}, @@ -64,7 +64,7 @@ exports.plugin = { }, register: function (server, options) { - const settings = Joi.attempt(options, internals.schema); + const settings = Validate.attempt(options, internals.schema); const monitor = new Monitor(server, settings); server.ext('onPostStop', internals.onPostStop(monitor)); diff --git a/package.json b/package.json index c98851d..99c98e5 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ ], "dependencies": { "@hapi/hoek": "9.x.x", - "@hapi/joi": "17.x.x", "@hapi/oppsy": "3.x.x", + "@hapi/validate": "1.x.x", "pumpify": "2.x.x" }, "devDependencies": { From 26ef30cf1ea7f45fc1ed091d7008c6a06ee60ee5 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 26 Sep 2020 13:04:05 -0400 Subject: [PATCH 13/16] update to lab@24.x.x --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 99c98e5..ec6c737 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "devDependencies": { "@hapi/code": "8.x.x", "@hapi/hapi": "20.x.x", - "@hapi/lab": "23.x.x", + "@hapi/lab": "24.x.x", "@hapi/wreck": "17.x.x" }, "scripts": { From 3a8f3ef07e6284753c57e26089ad53ebfcfc6d21 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 26 Sep 2020 13:04:34 -0400 Subject: [PATCH 14/16] v9.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ec6c737..ba556ab 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/good", "description": "Server and process monitoring plugin", - "version": "9.0.0", + "version": "9.0.1", "repository": "git://github.com/hapijs/good", "main": "lib/index.js", "files": [ From 1adbfce58bdd5cf819ccaca0583c6b314fc02007 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 17 Nov 2020 15:01:26 +0100 Subject: [PATCH 15/16] Fix custom changes --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 08a3535..3848dff 100755 --- a/lib/index.js +++ b/lib/index.js @@ -98,7 +98,7 @@ internals.reconfigure = function (monitor) { return (options) => { monitor.stop(); - const settings = Joi.attempt(options, internals.schema); + const settings = Validate.attempt(options, internals.schema); monitor.configure(settings); monitor.start(); }; From 9fc69ac916293adb91d0fa04a19393d6213642b8 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 17 Nov 2020 15:04:51 +0100 Subject: [PATCH 16/16] Fix previous merge error --- lib/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3848dff..050cce3 100755 --- a/lib/index.js +++ b/lib/index.js @@ -68,7 +68,7 @@ exports.plugin = { const monitor = new Monitor(server, settings); server.ext('onPostStop', internals.onPostStop(monitor)); - server.ext('onPreStart', internals.onPreStart(monitor)); + server.ext('onPreStart', internals.onPreStart(monitor, settings)); server.expose('reconfigure', internals.reconfigure(monitor)); monitor.start(); @@ -85,11 +85,12 @@ internals.onPostStop = function (monitor) { }; -internals.onPreStart = function (monitor) { +internals.onPreStart = function (monitor, options) { return (server, h) => { - monitor.startOps(); + const interval = options.ops.interval; + monitor.startOps(interval); }; };