tabletcommand-logger 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/index.js +9 -4
- package/build/index.js.map +1 -1
- package/build/middleware/metrics.js +25 -19
- package/build/middleware/metrics.js.map +1 -1
- package/build/middleware/status-logger.js +7 -3
- package/build/middleware/status-logger.js.map +1 -1
- package/build/test/middleware-metrics.js +35 -19
- package/build/test/middleware-metrics.js.map +1 -1
- package/definitions/index.d.ts +12 -8
- package/definitions/index.d.ts.map +1 -1
- package/definitions/middleware/metrics.d.ts +1 -0
- package/definitions/middleware/metrics.d.ts.map +1 -1
- package/definitions/middleware/status-logger.d.ts.map +1 -1
- package/definitions/types/express.aug.d.ts.map +1 -1
- package/package.json +23 -19
- package/src/index.ts +9 -4
- package/src/middleware/metrics.ts +24 -17
- package/src/middleware/status-logger.ts +15 -10
- package/src/test/middleware-metrics.ts +36 -18
- package/src/tsconfig.json +1 -1
- package/src/types/express.aug.ts +12 -12
- package/build/middleware/types.js +0 -2
- package/build/middleware/types.js.map +0 -1
- package/src/middleware/types.ts +0 -0
package/README.md
ADDED
package/build/index.js
CHANGED
|
@@ -3,14 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.statusLogger = exports.metricsMiddleware = exports.loggerMiddleware = exports.logger = void 0;
|
|
6
7
|
const bunyan_logger_1 = __importDefault(require("./bunyan-logger"));
|
|
7
8
|
const logger_1 = __importDefault(require("./middleware/logger"));
|
|
8
9
|
const metrics_1 = __importDefault(require("./middleware/metrics"));
|
|
9
10
|
const status_logger_1 = __importDefault(require("./middleware/status-logger"));
|
|
11
|
+
exports.logger = bunyan_logger_1.default;
|
|
12
|
+
exports.loggerMiddleware = logger_1.default;
|
|
13
|
+
exports.metricsMiddleware = metrics_1.default;
|
|
14
|
+
exports.statusLogger = status_logger_1.default;
|
|
10
15
|
exports.default = {
|
|
11
|
-
logger:
|
|
12
|
-
loggerMiddleware:
|
|
13
|
-
metricsMiddleware:
|
|
14
|
-
statusLogger:
|
|
16
|
+
logger: exports.logger,
|
|
17
|
+
loggerMiddleware: exports.loggerMiddleware,
|
|
18
|
+
metricsMiddleware: exports.metricsMiddleware,
|
|
19
|
+
statusLogger: exports.statusLogger,
|
|
15
20
|
};
|
|
16
21
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,oEAAsC;AACtC,iEAAoD;AACpD,mEAAsD;AACtD,+EAAuD;AAE1C,QAAA,MAAM,GAAG,uBAAO,CAAC;AACjB,QAAA,gBAAgB,GAAG,gBAAiB,CAAC;AACrC,QAAA,iBAAiB,GAAG,iBAAkB,CAAC;AACvC,QAAA,YAAY,GAAG,uBAAa,CAAC;AAE1C,kBAAe;IACb,MAAM,EAAN,cAAM;IACN,gBAAgB,EAAhB,wBAAgB;IAChB,iBAAiB,EAAjB,yBAAiB;IACjB,YAAY,EAAZ,oBAAY;CACb,CAAC"}
|
|
@@ -8,11 +8,11 @@ const url_1 = require("url");
|
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const debug_1 = __importDefault(require("debug"));
|
|
10
10
|
const express_statsd_1 = __importDefault(require("express-statsd"));
|
|
11
|
-
const monitorRequest = express_statsd_1.default();
|
|
11
|
+
const monitorRequest = (0, express_statsd_1.default)();
|
|
12
12
|
// Add an express-statsd key that looks like http.post.api.hello.world for a HTTP POST to /api/hello/world URL
|
|
13
13
|
// See https://github.com/uber/express-statsd
|
|
14
14
|
function metrics(filter) {
|
|
15
|
-
const debug = debug_1.default("tabletcommand-logger:middleware/metrics");
|
|
15
|
+
const debug = (0, debug_1.default)("tabletcommand-logger:middleware/metrics");
|
|
16
16
|
function defaultFilter(pathIn) {
|
|
17
17
|
const uuidRegex = /[-a-f\d]{36}/i;
|
|
18
18
|
const mongoIdRegex = /[a-f\d]{24}/i;
|
|
@@ -31,33 +31,39 @@ function metrics(filter) {
|
|
|
31
31
|
}
|
|
32
32
|
return path;
|
|
33
33
|
}
|
|
34
|
+
function setStatsDKey(req, hostname, env) {
|
|
35
|
+
let method = req.method || "unknown_method";
|
|
36
|
+
method = method.toLowerCase();
|
|
37
|
+
const defaultBase = "http://localhost";
|
|
38
|
+
const urlItem = new url_1.URL(req.url, defaultBase);
|
|
39
|
+
let path = urlItem.pathname.toLowerCase();
|
|
40
|
+
path = path.replace(/\//g, " ").trim().replace(/\s/g, ".");
|
|
41
|
+
let filterFunc = defaultFilter;
|
|
42
|
+
if (lodash_1.default.isFunction(filter)) {
|
|
43
|
+
filterFunc = filter;
|
|
44
|
+
}
|
|
45
|
+
const filteredPath = filterFunc(path);
|
|
46
|
+
req.statsdKey = [
|
|
47
|
+
hostname,
|
|
48
|
+
env,
|
|
49
|
+
"http",
|
|
50
|
+
method,
|
|
51
|
+
filteredPath
|
|
52
|
+
].join(".");
|
|
53
|
+
debug(`req.statsdKey: ${req.statsdKey}`);
|
|
54
|
+
}
|
|
34
55
|
function statsd() {
|
|
35
56
|
return function statsdFunc(req, res, next) {
|
|
36
57
|
const hostname = process.env.NODE_STATSD_PREFIX || os_1.default.hostname();
|
|
37
58
|
const env = process.env.NODE_ENV || "production";
|
|
38
|
-
|
|
39
|
-
method = method.toLowerCase();
|
|
40
|
-
let path = (new url_1.URL(req.url)).pathname.toLowerCase();
|
|
41
|
-
path = path.replace(/\//g, " ").trim().replace(/\s/g, ".");
|
|
42
|
-
let filterFunc = defaultFilter;
|
|
43
|
-
if (lodash_1.default.isFunction(filter)) {
|
|
44
|
-
filterFunc = filter;
|
|
45
|
-
}
|
|
46
|
-
const filteredPath = filterFunc(path);
|
|
47
|
-
req.statsdKey = [
|
|
48
|
-
hostname,
|
|
49
|
-
env,
|
|
50
|
-
"http",
|
|
51
|
-
method,
|
|
52
|
-
filteredPath
|
|
53
|
-
].join(".");
|
|
54
|
-
debug(`req.statsdKey: ${req.statsdKey}`);
|
|
59
|
+
setStatsDKey(req, hostname, env);
|
|
55
60
|
monitorRequest(req, res);
|
|
56
61
|
return next();
|
|
57
62
|
};
|
|
58
63
|
}
|
|
59
64
|
return {
|
|
60
65
|
defaultFilter,
|
|
66
|
+
setStatsDKey,
|
|
61
67
|
statsd,
|
|
62
68
|
};
|
|
63
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/middleware/metrics.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,6BAA0B;AAE1B,oDAAuB;AACvB,kDAAiC;AACjC,oEAA2C;AAK3C,MAAM,cAAc,GAAG,wBAAa,
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/middleware/metrics.ts"],"names":[],"mappings":"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"}
|
|
@@ -14,14 +14,17 @@ function shouldIgnore(req, res) {
|
|
|
14
14
|
}
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
+
function requestDuration(endTime, startTime) {
|
|
18
|
+
if (!lodash_1.default.isObject(startTime) || !lodash_1.default.isDate(startTime)) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
return endTime.valueOf() - startTime.valueOf();
|
|
22
|
+
}
|
|
17
23
|
function statusLogger(logger) {
|
|
18
24
|
return function requestLogger(req, res, next) {
|
|
19
25
|
if (!lodash_1.default.isObject(req._startTime)) {
|
|
20
26
|
req._startTime = new Date();
|
|
21
27
|
}
|
|
22
|
-
if (lodash_1.default.isObject(req._startTime) && req._startTime instanceof Date) {
|
|
23
|
-
res.responseTime = new Date().valueOf() - req._startTime.valueOf();
|
|
24
|
-
}
|
|
25
28
|
res.bodyCopy = null;
|
|
26
29
|
// Save a copy of the response body
|
|
27
30
|
const oldJSON = res.json.bind(res);
|
|
@@ -39,6 +42,7 @@ function statusLogger(logger) {
|
|
|
39
42
|
res.bodyCopy = body;
|
|
40
43
|
}
|
|
41
44
|
oldJSON(body);
|
|
45
|
+
res.responseTime = requestDuration(new Date(), req._startTime);
|
|
42
46
|
return res;
|
|
43
47
|
};
|
|
44
48
|
function logRequest() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-logger.js","sourceRoot":"","sources":["../../src/middleware/status-logger.ts"],"names":[],"mappings":";;;;;AAMA,oDAAuB;AAEvB,SAAS,YAAY,CAAC,GAAY,EAAE,GAAa;IAC/C,IAAI,gBAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE;QAC7C,OAAO,IAAI,CAAC;KACb;IAED,MAAM,SAAS,GAAY,gBAAC,CAAC,GAAG,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IAC5D,IAAI,gBAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QACvD,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"status-logger.js","sourceRoot":"","sources":["../../src/middleware/status-logger.ts"],"names":[],"mappings":"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"}
|
|
@@ -5,27 +5,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const chai_1 = require("chai");
|
|
7
7
|
const metrics_1 = __importDefault(require("../middleware/metrics"));
|
|
8
|
-
const metrics = metrics_1.default();
|
|
8
|
+
const metrics = (0, metrics_1.default)();
|
|
9
9
|
describe("Metrics Middleware", function () {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
context("Default Filter", () => {
|
|
11
|
+
it("removes uuid from end of paths", function () {
|
|
12
|
+
const path = "api.user.daafe605-feac-add0-ad0e-89023d48deab";
|
|
13
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
14
|
+
chai_1.assert.equal(cleanPath, "api.user");
|
|
15
|
+
});
|
|
16
|
+
it("removes uuid from middle of paths", function () {
|
|
17
|
+
const path = "api.user.daafe605-feac-add0-ad0e-89023d48deab.info";
|
|
18
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
19
|
+
chai_1.assert.equal(cleanPath, "api.user.info");
|
|
20
|
+
});
|
|
21
|
+
it("removes mongo id from middle of paths", function () {
|
|
22
|
+
const path = "api.online.515a41a3e0387575cc939002.status";
|
|
23
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
24
|
+
chai_1.assert.equal(cleanPath, "api.online.status");
|
|
25
|
+
});
|
|
26
|
+
it("skips paths without uuid", function () {
|
|
27
|
+
const path = "api.user.profile";
|
|
28
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
29
|
+
chai_1.assert.equal(cleanPath, "api.user.profile");
|
|
30
|
+
});
|
|
14
31
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
chai_1.assert.equal(cleanPath, "api.user.profile");
|
|
32
|
+
context("setStatsDKey", () => {
|
|
33
|
+
it("Parses URL without a set base hostname", () => {
|
|
34
|
+
const sampleUrl = "/api/v2/cad-vehicle-status?apikey=somekey";
|
|
35
|
+
const req = {
|
|
36
|
+
method: "POST",
|
|
37
|
+
url: sampleUrl,
|
|
38
|
+
};
|
|
39
|
+
const hostname = "a";
|
|
40
|
+
const env = "b";
|
|
41
|
+
metrics.setStatsDKey(req, hostname, env);
|
|
42
|
+
const expectedStatsdKey = "a.b.http.post.api.v2.cad-vehicle-status";
|
|
43
|
+
chai_1.assert.equal(req.statsdKey, expectedStatsdKey);
|
|
44
|
+
});
|
|
29
45
|
});
|
|
30
46
|
});
|
|
31
47
|
//# sourceMappingURL=middleware-metrics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-metrics.js","sourceRoot":"","sources":["../../src/test/middleware-metrics.ts"],"names":[],"mappings":";;;;;AAAA,+BAA8B;
|
|
1
|
+
{"version":3,"file":"middleware-metrics.js","sourceRoot":"","sources":["../../src/test/middleware-metrics.ts"],"names":[],"mappings":";;;;;AAAA,+BAA8B;AAE9B,oEAAkD;AAClD,MAAM,OAAO,GAAG,IAAA,iBAAa,GAAE,CAAC;AAEhC,QAAQ,CAAC,oBAAoB,EAAE;IAC7B,OAAO,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,gCAAgC,EAAE;YACnC,MAAM,IAAI,GAAG,+CAA+C,CAAC;YAC7D,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9C,aAAM,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mCAAmC,EAAE;YACtC,MAAM,IAAI,GAAG,oDAAoD,CAAC;YAClE,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9C,aAAM,CAAC,KAAK,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE;YAC1C,MAAM,IAAI,GAAG,4CAA4C,CAAC;YAC1D,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9C,aAAM,CAAC,KAAK,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0BAA0B,EAAE;YAC7B,MAAM,IAAI,GAAG,kBAAkB,CAAC;YAChC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9C,aAAM,CAAC,KAAK,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;YAChD,MAAM,SAAS,GAAG,2CAA2C,CAAC;YAC9D,MAAM,GAAG,GAAqB;gBAC5B,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,SAAS;aACf,CAAC;YACF,MAAM,QAAQ,GAAG,GAAG,CAAC;YACrB,MAAM,GAAG,GAAG,GAAG,CAAC;YAChB,OAAO,CAAC,YAAY,CAAC,GAAc,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;YACpD,MAAM,iBAAiB,GAAG,yCAAyC,CAAC;YACpE,aAAM,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/definitions/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import _logger from "./bunyan-logger";
|
|
2
|
+
import _loggerMiddleware from "./middleware/logger";
|
|
3
|
+
import _metricsMiddleware from "./middleware/metrics";
|
|
4
|
+
import _statusLogger from "./middleware/status-logger";
|
|
5
|
+
export declare const logger: typeof _logger;
|
|
6
|
+
export declare const loggerMiddleware: typeof _loggerMiddleware;
|
|
7
|
+
export declare const metricsMiddleware: typeof _metricsMiddleware;
|
|
8
|
+
export declare const statusLogger: typeof _statusLogger;
|
|
5
9
|
declare const _default: {
|
|
6
|
-
logger: typeof
|
|
7
|
-
loggerMiddleware: typeof
|
|
8
|
-
metricsMiddleware: typeof
|
|
9
|
-
statusLogger: typeof
|
|
10
|
+
logger: typeof _logger;
|
|
11
|
+
loggerMiddleware: typeof _loggerMiddleware;
|
|
12
|
+
metricsMiddleware: typeof _metricsMiddleware;
|
|
13
|
+
statusLogger: typeof _statusLogger;
|
|
10
14
|
};
|
|
11
15
|
export default _default;
|
|
12
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,aAAa,MAAM,4BAA4B,CAAC;AAEvD,eAAO,MAAM,MAAM,gBAAU,CAAC;AAC9B,eAAO,MAAM,gBAAgB,0BAAoB,CAAC;AAClD,eAAO,MAAM,iBAAiB,2BAAqB,CAAC;AACpD,eAAO,MAAM,YAAY,sBAAgB,CAAC;;;;;;;AAE1C,wBAKE"}
|
|
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from "express";
|
|
|
2
2
|
declare type FilterFunction = (parameter: string) => string;
|
|
3
3
|
export default function metrics(filter?: FilterFunction): {
|
|
4
4
|
defaultFilter: (pathIn: string) => string;
|
|
5
|
+
setStatsDKey: (req: Request, hostname: string, env: string) => void;
|
|
5
6
|
statsd: () => (req: Request, res: Response, next: NextFunction) => void;
|
|
6
7
|
};
|
|
7
8
|
export declare type MetricsModule = ReturnType<typeof metrics>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/middleware/metrics.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D,aAAK,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;AAMpD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,MAAM,CAAC,EAAE,cAAc;4BAGtB,MAAM,KAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/middleware/metrics.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D,aAAK,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;AAMpD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,MAAM,CAAC,EAAE,cAAc;4BAGtB,MAAM,KAAG,MAAM;wBAmBnB,OAAO,YAAY,MAAM,OAAO,MAAM;wBAuB/B,OAAO,OAAO,QAAQ,QAAQ,YAAY;EAc7E;AAED,oBAAY,aAAa,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-logger.d.ts","sourceRoot":"","sources":["../../src/middleware/status-logger.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,QAAQ,EACT,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"status-logger.d.ts","sourceRoot":"","sources":["../../src/middleware/status-logger.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,QAAQ,EACT,MAAM,SAAS,CAAC;AAwBjB,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,MAAM,EAAE,MAAM,SACd,OAAO,OAAO,QAAQ,QAAQ,YAAY,UA8D9E;AAED,oBAAY,kBAAkB,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.aug.d.ts","sourceRoot":"","sources":["../../src/types/express.aug.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"express.aug.d.ts","sourceRoot":"","sources":["../../src/types/express.aug.ts"],"names":[],"mappings":"AACA,OAAO,EAAG,CAAC;AAGX,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,SAAS,EAAE,MAAM,CAAC;YAClB,UAAU,CAAC,EAAE,IAAI,CAAC;SACnB;QAED,UAAU,QAAQ;YAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,SAAS,CAAC,EAAE,OAAO,CAAC;YACpB,YAAY,EAAE,MAAM,CAAC;SACtB;KACF;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tabletcommand-logger",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Tablet Command Logging Configuration",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "gulp ts",
|
|
@@ -13,38 +13,42 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git://github.com/tabletcommand/tabletcommand-logger.git"
|
|
15
15
|
},
|
|
16
|
+
"main": "build/index.js",
|
|
17
|
+
"types": "definitions/index.d.ts",
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"bunyan": "^1.8.15",
|
|
18
|
-
"debug": "^4.3.
|
|
20
|
+
"debug": "^4.3.4",
|
|
19
21
|
"express-statsd": "^0.3.0",
|
|
20
22
|
"lodash": "^4.17.21"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
23
|
-
"@types/bunyan": "^1.8.
|
|
24
|
-
"@types/chai": "^4.
|
|
25
|
-
"@types/debug": "4.1.
|
|
26
|
-
"@types/express": "^4.17.
|
|
25
|
+
"@types/bunyan": "^1.8.8",
|
|
26
|
+
"@types/chai": "^4.3.1",
|
|
27
|
+
"@types/debug": "4.1.7",
|
|
28
|
+
"@types/express": "^4.17.13",
|
|
29
|
+
"@types/express-serve-static-core": "^4.17.28",
|
|
27
30
|
"@types/gulp-copy": "0.0.4",
|
|
28
|
-
"@types/lodash": "^4.14.
|
|
29
|
-
"@types/mocha": "^
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
32
|
-
"@typescript-eslint/parser": "^
|
|
33
|
-
"chai": "^4.3.
|
|
34
|
-
"del": "^6.
|
|
35
|
-
"eslint": "^
|
|
36
|
-
"eslint-config-standard": "^
|
|
37
|
-
"eslint-plugin-import": "^2.
|
|
31
|
+
"@types/lodash": "^4.14.182",
|
|
32
|
+
"@types/mocha": "^9.1.1",
|
|
33
|
+
"@types/node": "^17.0.40",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
35
|
+
"@typescript-eslint/parser": "^5.27.1",
|
|
36
|
+
"chai": "^4.3.6",
|
|
37
|
+
"del": "^6.1.1",
|
|
38
|
+
"eslint": "^8.17.0",
|
|
39
|
+
"eslint-config-standard": "^17.0.0",
|
|
40
|
+
"eslint-plugin-import": "^2.26.0",
|
|
38
41
|
"eslint-plugin-mocha-only": "0.0.3",
|
|
39
42
|
"eslint-plugin-node": "^11.1.0",
|
|
40
|
-
"eslint-plugin-promise": "^
|
|
41
|
-
"eslint-plugin-security": "^1.
|
|
43
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
44
|
+
"eslint-plugin-security": "^1.5.0",
|
|
42
45
|
"eslint-plugin-standard": "^4.1.0",
|
|
43
46
|
"gulp": "^4.0.2",
|
|
47
|
+
"gulp-cli": "^2.3.0",
|
|
44
48
|
"gulp-copy": "^4.0.1",
|
|
45
49
|
"gulp-eslint": "^6.0.0",
|
|
46
50
|
"gulp-mocha": "^8.0.0",
|
|
47
51
|
"gulp-shell": "^0.8.0",
|
|
48
|
-
"mocha": "^
|
|
52
|
+
"mocha": "^10.0.0"
|
|
49
53
|
}
|
|
50
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import _logger from "./bunyan-logger";
|
|
3
|
+
import _loggerMiddleware from "./middleware/logger";
|
|
4
|
+
import _metricsMiddleware from "./middleware/metrics";
|
|
5
|
+
import _statusLogger from "./middleware/status-logger";
|
|
6
|
+
|
|
7
|
+
export const logger = _logger;
|
|
8
|
+
export const loggerMiddleware = _loggerMiddleware;
|
|
9
|
+
export const metricsMiddleware = _metricsMiddleware;
|
|
10
|
+
export const statusLogger = _statusLogger;
|
|
6
11
|
|
|
7
12
|
export default {
|
|
8
13
|
logger,
|
|
@@ -34,27 +34,33 @@ export default function metrics(filter?: FilterFunction) {
|
|
|
34
34
|
return path;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function setStatsDKey(req: Request, hostname: string, env: string) {
|
|
38
|
+
let method = req.method || "unknown_method";
|
|
39
|
+
method = method.toLowerCase();
|
|
40
|
+
const defaultBase = "http://localhost";
|
|
41
|
+
const urlItem = new URL(req.url, defaultBase);
|
|
42
|
+
let path = urlItem.pathname.toLowerCase();
|
|
43
|
+
path = path.replace(/\//g, " ").trim().replace(/\s/g, ".");
|
|
44
|
+
let filterFunc = defaultFilter;
|
|
45
|
+
if (_.isFunction(filter)) {
|
|
46
|
+
filterFunc = filter;
|
|
47
|
+
}
|
|
48
|
+
const filteredPath = filterFunc(path);
|
|
49
|
+
req.statsdKey = [
|
|
50
|
+
hostname,
|
|
51
|
+
env,
|
|
52
|
+
"http",
|
|
53
|
+
method,
|
|
54
|
+
filteredPath
|
|
55
|
+
].join(".");
|
|
56
|
+
debug(`req.statsdKey: ${req.statsdKey}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
37
59
|
function statsd() {
|
|
38
60
|
return function statsdFunc(req: Request, res: Response, next: NextFunction) {
|
|
39
61
|
const hostname = process.env.NODE_STATSD_PREFIX || os.hostname();
|
|
40
62
|
const env = process.env.NODE_ENV || "production";
|
|
41
|
-
|
|
42
|
-
method = method.toLowerCase();
|
|
43
|
-
let path = (new URL(req.url)).pathname.toLowerCase();
|
|
44
|
-
path = path.replace(/\//g, " ").trim().replace(/\s/g, ".");
|
|
45
|
-
let filterFunc = defaultFilter;
|
|
46
|
-
if (_.isFunction(filter)) {
|
|
47
|
-
filterFunc = filter;
|
|
48
|
-
}
|
|
49
|
-
const filteredPath = filterFunc(path);
|
|
50
|
-
req.statsdKey = [
|
|
51
|
-
hostname,
|
|
52
|
-
env,
|
|
53
|
-
"http",
|
|
54
|
-
method,
|
|
55
|
-
filteredPath
|
|
56
|
-
].join(".");
|
|
57
|
-
debug(`req.statsdKey: ${req.statsdKey}`);
|
|
63
|
+
setStatsDKey(req, hostname, env);
|
|
58
64
|
monitorRequest(req, res);
|
|
59
65
|
return next();
|
|
60
66
|
};
|
|
@@ -62,6 +68,7 @@ export default function metrics(filter?: FilterFunction) {
|
|
|
62
68
|
|
|
63
69
|
return {
|
|
64
70
|
defaultFilter,
|
|
71
|
+
setStatsDKey,
|
|
65
72
|
statsd,
|
|
66
73
|
};
|
|
67
74
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import bunyan from "bunyan";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
3
|
NextFunction,
|
|
4
|
-
Request,
|
|
5
|
-
Response,
|
|
4
|
+
Request,
|
|
5
|
+
Response,
|
|
6
6
|
} from "express";
|
|
7
7
|
import _ from "lodash";
|
|
8
8
|
|
|
@@ -19,33 +19,38 @@ function shouldIgnore(req: Request, res: Response): boolean {
|
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function requestDuration(endTime: Date, startTime?: Date): number {
|
|
23
|
+
if (!_.isObject(startTime) || !_.isDate(startTime)) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return endTime.valueOf() - startTime.valueOf();
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export default function statusLogger(logger: bunyan) {
|
|
23
31
|
return function requestLogger(req: Request, res: Response, next: NextFunction) {
|
|
24
32
|
if (!_.isObject(req._startTime)) {
|
|
25
33
|
req._startTime = new Date();
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
if (_.isObject(req._startTime) && req._startTime instanceof Date) {
|
|
29
|
-
res.responseTime = new Date().valueOf() - req._startTime.valueOf();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
36
|
res.bodyCopy = null;
|
|
33
37
|
|
|
34
38
|
// Save a copy of the response body
|
|
35
39
|
const oldJSON = res.json.bind(res);
|
|
36
40
|
|
|
37
41
|
// Used when using res.json(body);
|
|
38
|
-
res.json = function newJson(body: unknown|string): Response {
|
|
42
|
+
res.json = function newJson(body: unknown | string): Response {
|
|
39
43
|
if (_.isString(body)) {
|
|
40
44
|
try {
|
|
41
45
|
res.bodyCopy = JSON.parse(body);
|
|
42
46
|
} catch (e) {
|
|
43
47
|
res.bodyCopy = body;
|
|
44
|
-
}
|
|
48
|
+
}
|
|
45
49
|
} else {
|
|
46
50
|
res.bodyCopy = body;
|
|
47
51
|
}
|
|
48
52
|
oldJSON(body);
|
|
53
|
+
res.responseTime = requestDuration(new Date(), req._startTime);
|
|
49
54
|
return res;
|
|
50
55
|
};
|
|
51
56
|
|
|
@@ -82,7 +87,7 @@ export default function statusLogger(logger: bunyan) {
|
|
|
82
87
|
|
|
83
88
|
res.on("finish", logRequest);
|
|
84
89
|
res.on("close", logRequest);
|
|
85
|
-
|
|
90
|
+
|
|
86
91
|
return next();
|
|
87
92
|
};
|
|
88
93
|
}
|
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
|
+
import { Request } from "express";
|
|
2
3
|
import MetricsModule from "../middleware/metrics";
|
|
3
4
|
const metrics = MetricsModule();
|
|
4
5
|
|
|
5
6
|
describe("Metrics Middleware", function() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
context("Default Filter", () => {
|
|
8
|
+
it("removes uuid from end of paths", function() {
|
|
9
|
+
const path = "api.user.daafe605-feac-add0-ad0e-89023d48deab";
|
|
10
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
11
|
+
assert.equal(cleanPath, "api.user");
|
|
12
|
+
});
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
it("removes uuid from middle of paths", function() {
|
|
15
|
+
const path = "api.user.daafe605-feac-add0-ad0e-89023d48deab.info";
|
|
16
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
17
|
+
assert.equal(cleanPath, "api.user.info");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("removes mongo id from middle of paths", function() {
|
|
21
|
+
const path = "api.online.515a41a3e0387575cc939002.status";
|
|
22
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
23
|
+
assert.equal(cleanPath, "api.online.status");
|
|
24
|
+
});
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
it("skips paths without uuid", function() {
|
|
27
|
+
const path = "api.user.profile";
|
|
28
|
+
const cleanPath = metrics.defaultFilter(path);
|
|
29
|
+
assert.equal(cleanPath, "api.user.profile");
|
|
30
|
+
});
|
|
22
31
|
});
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
context("setStatsDKey", () => {
|
|
34
|
+
it("Parses URL without a set base hostname", () => {
|
|
35
|
+
const sampleUrl = "/api/v2/cad-vehicle-status?apikey=somekey";
|
|
36
|
+
const req: Partial<Request> = {
|
|
37
|
+
method: "POST",
|
|
38
|
+
url: sampleUrl,
|
|
39
|
+
};
|
|
40
|
+
const hostname = "a";
|
|
41
|
+
const env = "b";
|
|
42
|
+
metrics.setStatsDKey(req as Request, hostname, env);
|
|
43
|
+
const expectedStatsdKey = "a.b.http.post.api.v2.cad-vehicle-status";
|
|
44
|
+
assert.equal(req.statsdKey, expectedStatsdKey);
|
|
45
|
+
});
|
|
28
46
|
});
|
|
29
47
|
});
|
package/src/tsconfig.json
CHANGED
package/src/types/express.aug.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// https://stackoverflow.com/questions/57132428/augmentations-for-the-global-scope-can-only-be-directly-nested-in-external-modul
|
|
2
|
-
export {};
|
|
2
|
+
export { };
|
|
3
3
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
5
|
declare global {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
7
|
+
namespace Express {
|
|
8
|
+
interface Request {
|
|
9
|
+
statsdKey: string;
|
|
10
|
+
_startTime?: Date;
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
13
|
+
interface Response {
|
|
14
|
+
bodyCopy?: unknown; // Same as express response.body
|
|
15
|
+
chunkCopy?: unknown;
|
|
16
|
+
responseTime: number;
|
|
18
17
|
}
|
|
18
|
+
}
|
|
19
19
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/middleware/types.ts"],"names":[],"mappings":""}
|
package/src/middleware/types.ts
DELETED
|
File without changes
|