@biorate/nestjs-tools 1.152.0 → 1.152.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biorate/nestjs-tools",
3
- "version": "1.152.0",
3
+ "version": "1.152.1",
4
4
  "description": "NestJS tools",
5
5
  "main": "dist",
6
6
  "scripts": {
@@ -38,14 +38,14 @@
38
38
  "@biorate/errors": "1.102.0",
39
39
  "@biorate/inversion": "1.120.0",
40
40
  "@biorate/opentelemetry": "1.152.0",
41
- "@biorate/prometheus": "1.120.0",
41
+ "@biorate/prometheus": "1.152.1",
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": "e4648a0c8480013fef0867b54dabd8ccf6a85fa1",
48
+ "gitHead": "ed77d69613ed24efaaa76a0c592550492e50d4e4",
49
49
  "devDependencies": {
50
50
  "@types/json-stringify-safe": "5.0.3"
51
51
  }
@@ -5,11 +5,15 @@ import { Request, Response } from 'express';
5
5
  import { createProxyMiddleware } from 'http-proxy-middleware';
6
6
  import { Options, RequestHandler } from 'http-proxy-middleware/dist/types';
7
7
  import { Injectable } from '@nestjs/common';
8
- import { counter, histogram, Counter, Histogram } from '@biorate/prometheus';
8
+ import { counter, Counter, Histogram, Prometheus } from '@biorate/prometheus';
9
9
  import { time } from '@biorate/tools';
10
+ import { inject, Types } from '@biorate/inversion';
11
+ import { IConfig } from '@biorate/config';
10
12
 
11
13
  @Injectable()
12
14
  export class ProxyPrometheusMiddleware {
15
+ @inject(Types.Config) private config: IConfig;
16
+
13
17
  @counter({
14
18
  name: 'http_proxy_server_requests_seconds_count',
15
19
  help: 'Http proxy server requests count',
@@ -17,12 +21,6 @@ export class ProxyPrometheusMiddleware {
17
21
  })
18
22
  private counter: Counter;
19
23
 
20
- @histogram({
21
- name: 'http_proxy_server_requests_seconds',
22
- help: 'Http proxy server requests seconds bucket',
23
- labelNames: ['method', 'uri', 'status'],
24
- buckets: [0.005, 0.01, 0.02, 0.05, 0.1, 0.3, 0.5, 1, 2, 3, 5, 10],
25
- })
26
24
  private histogram: Histogram;
27
25
 
28
26
  private handler: RequestHandler;
@@ -35,6 +33,16 @@ export class ProxyPrometheusMiddleware {
35
33
 
36
34
  private constructor(options: Options = {}) {
37
35
  const { onProxyReq, onProxyRes } = pick(options, 'onProxyReq', 'onProxyRes');
36
+ this.histogram = new Histogram({
37
+ name: 'http_proxy_server_requests_seconds',
38
+ help: 'Http proxy server requests seconds bucket',
39
+ labelNames: ['method', 'uri', 'status'],
40
+ buckets: this.config.get<number[]>(
41
+ 'ProxyPrometheusMiddleware.histogram.buckets',
42
+ [0.005, 0.01, 0.02, 0.05, 0.1, 0.3, 0.5, 1, 2, 3, 5, 10],
43
+ ),
44
+ registers: [Prometheus.registry],
45
+ });
38
46
  this.handler = createProxyMiddleware({
39
47
  ...omit(options, 'onProxyReq', 'onProxyRes'),
40
48
  onProxyReq: (
@@ -3,7 +3,7 @@ import * as onHeaders from 'on-headers';
3
3
  import { Injectable, NestMiddleware } from '@nestjs/common';
4
4
  import { inject, Types } from '@biorate/inversion';
5
5
  import { IConfig } from '@biorate/config';
6
- import { histogram, Histogram } from '@biorate/prometheus';
6
+ import { Prometheus, Histogram } from '@biorate/prometheus';
7
7
  import { Request, Response, NextFunction } from 'express';
8
8
  import { time } from '@biorate/tools';
9
9
  import { RoutesInterceptor } from '../interceptors';
@@ -18,12 +18,6 @@ export class ResponseTimeMiddleware implements NestMiddleware {
18
18
 
19
19
  private readonly digits: number;
20
20
 
21
- @histogram({
22
- name: 'http_server_requests_seconds',
23
- help: 'Http server requests seconds bucket',
24
- labelNames: ['method', 'uri', 'status'],
25
- buckets: [0.005, 0.01, 0.02, 0.05, 0.1, 0.3, 0.5, 1, 2, 3, 5, 10],
26
- })
27
21
  private histogram: Histogram;
28
22
 
29
23
  public constructor() {
@@ -39,6 +33,16 @@ export class ResponseTimeMiddleware implements NestMiddleware {
39
33
  'app.middleware.ResponseTimeMiddleware.digits',
40
34
  3,
41
35
  );
36
+ this.histogram = new Histogram({
37
+ name: 'http_server_requests_seconds',
38
+ help: 'Http server requests seconds bucket',
39
+ labelNames: ['method', 'uri', 'status'],
40
+ buckets: this.config.get<number[]>(
41
+ 'ResponseTimeMiddleware.histogram.buckets',
42
+ [0.005, 0.01, 0.02, 0.05, 0.1, 0.3, 0.5, 1, 2, 3, 5, 10],
43
+ ),
44
+ registers: [Prometheus.registry],
45
+ });
42
46
  }
43
47
 
44
48
  public use(req: Request, res: Response, next: NextFunction) {