@biorate/nestjs-tools 1.156.1 → 1.163.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/CHANGELOG.md +10 -0
- package/dist/src/middlewares/proxy-middleware.js +12 -10
- package/dist/src/middlewares/proxy-middleware.js.map +1 -1
- package/dist/src/middlewares/response-time-middleware.js +12 -10
- package/dist/src/middlewares/response-time-middleware.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/middlewares/proxy-middleware.ts +14 -13
- package/src/middlewares/response-time-middleware.ts +13 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biorate/nestjs-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.163.0",
|
|
4
4
|
"description": "NestJS tools",
|
|
5
5
|
"main": "dist",
|
|
6
6
|
"scripts": {
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
"ws": ">=8.18.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@biorate/axios": "1.156.
|
|
37
|
-
"@biorate/config": "1.156.
|
|
36
|
+
"@biorate/axios": "1.156.2",
|
|
37
|
+
"@biorate/config": "1.156.2",
|
|
38
38
|
"@biorate/errors": "1.102.0",
|
|
39
|
-
"@biorate/inversion": "1.156.
|
|
40
|
-
"@biorate/opentelemetry": "1.
|
|
41
|
-
"@biorate/prometheus": "1.156.
|
|
39
|
+
"@biorate/inversion": "1.156.2",
|
|
40
|
+
"@biorate/opentelemetry": "1.163.0",
|
|
41
|
+
"@biorate/prometheus": "1.156.2",
|
|
42
42
|
"@biorate/tools": "1.102.1",
|
|
43
43
|
"http-proxy": "1.18.1",
|
|
44
44
|
"http-proxy-middleware": "2.0.6",
|
|
45
45
|
"json-stringify-safe": "5.0.1",
|
|
46
46
|
"on-headers": "1.0.2"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "cda7045a715bdb95b6b1d4962e957f9eb30d9450",
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/json-stringify-safe": "5.0.3"
|
|
51
51
|
}
|
|
@@ -21,28 +21,29 @@ export class ProxyPrometheusMiddleware {
|
|
|
21
21
|
})
|
|
22
22
|
private counter: Counter;
|
|
23
23
|
|
|
24
|
-
private histogram: Histogram;
|
|
25
|
-
|
|
26
24
|
private handler: RequestHandler;
|
|
27
25
|
|
|
28
26
|
private time = new WeakMap<Request, { time: () => number }>();
|
|
29
27
|
|
|
28
|
+
private static histogram: Histogram;
|
|
29
|
+
|
|
30
30
|
public static create(options?: Options) {
|
|
31
31
|
return new this(options).handler;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
private constructor(options: Options = {}) {
|
|
35
35
|
const { onProxyReq, onProxyRes } = pick(options, 'onProxyReq', 'onProxyRes');
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
if (!ProxyPrometheusMiddleware.histogram)
|
|
37
|
+
ProxyPrometheusMiddleware.histogram = new Histogram({
|
|
38
|
+
name: 'http_proxy_server_requests_seconds',
|
|
39
|
+
help: 'Http proxy server requests seconds bucket',
|
|
40
|
+
labelNames: ['method', 'uri', 'status'],
|
|
41
|
+
buckets: this.config.get<number[]>(
|
|
42
|
+
'ProxyPrometheusMiddleware.histogram.buckets',
|
|
43
|
+
[0.005, 0.01, 0.02, 0.05, 0.1, 0.3, 0.5, 1, 2, 3, 5, 10],
|
|
44
|
+
),
|
|
45
|
+
registers: [Prometheus.registry],
|
|
46
|
+
});
|
|
46
47
|
this.handler = createProxyMiddleware({
|
|
47
48
|
...omit(options, 'onProxyReq', 'onProxyRes'),
|
|
48
49
|
onProxyReq: (
|
|
@@ -63,7 +64,7 @@ export class ProxyPrometheusMiddleware {
|
|
|
63
64
|
status: res.statusCode,
|
|
64
65
|
})
|
|
65
66
|
.inc();
|
|
66
|
-
|
|
67
|
+
ProxyPrometheusMiddleware.histogram
|
|
67
68
|
.labels({
|
|
68
69
|
method: req.method,
|
|
69
70
|
uri: req.baseUrl,
|
|
@@ -18,7 +18,7 @@ export class ResponseTimeMiddleware implements NestMiddleware {
|
|
|
18
18
|
|
|
19
19
|
private readonly digits: number;
|
|
20
20
|
|
|
21
|
-
private histogram: Histogram;
|
|
21
|
+
private static histogram: Histogram;
|
|
22
22
|
|
|
23
23
|
public constructor() {
|
|
24
24
|
this.suffix = this.config.get<boolean>(
|
|
@@ -33,16 +33,17 @@ export class ResponseTimeMiddleware implements NestMiddleware {
|
|
|
33
33
|
'app.middleware.ResponseTimeMiddleware.digits',
|
|
34
34
|
3,
|
|
35
35
|
);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
if (!ResponseTimeMiddleware.histogram)
|
|
37
|
+
ResponseTimeMiddleware.histogram = new Histogram({
|
|
38
|
+
name: 'http_server_requests_seconds',
|
|
39
|
+
help: 'Http server requests seconds bucket',
|
|
40
|
+
labelNames: ['method', 'uri', 'status'],
|
|
41
|
+
buckets: this.config.get<number[]>(
|
|
42
|
+
'ResponseTimeMiddleware.histogram.buckets',
|
|
43
|
+
[0.005, 0.01, 0.02, 0.05, 0.1, 0.3, 0.5, 1, 2, 3, 5, 10],
|
|
44
|
+
),
|
|
45
|
+
registers: [Prometheus.registry],
|
|
46
|
+
});
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
public use(req: Request, res: Response, next: NextFunction) {
|
|
@@ -51,7 +52,7 @@ export class ResponseTimeMiddleware implements NestMiddleware {
|
|
|
51
52
|
onHeaders(res, () => {
|
|
52
53
|
const time = diff();
|
|
53
54
|
const route = RoutesInterceptor.map.get(req);
|
|
54
|
-
|
|
55
|
+
ResponseTimeMiddleware.histogram
|
|
55
56
|
.labels({
|
|
56
57
|
method: req.method,
|
|
57
58
|
uri:
|