@spinajs/metrics 2.0.151 → 2.0.152

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.
Files changed (35) hide show
  1. package/lib/cjs/config/metrics.d.ts +24 -0
  2. package/lib/cjs/config/metrics.d.ts.map +1 -1
  3. package/lib/cjs/config/metrics.js +32 -6
  4. package/lib/cjs/config/metrics.js.map +1 -1
  5. package/lib/cjs/controllers/metrics.d.ts +13 -8
  6. package/lib/cjs/controllers/metrics.d.ts.map +1 -1
  7. package/lib/cjs/controllers/metrics.js +32 -15
  8. package/lib/cjs/controllers/metrics.js.map +1 -1
  9. package/lib/cjs/index.d.ts +21 -8
  10. package/lib/cjs/index.d.ts.map +1 -1
  11. package/lib/cjs/index.js +62 -23
  12. package/lib/cjs/index.js.map +1 -1
  13. package/lib/cjs/policies/DefaultMetricsPolicy.d.ts +11 -0
  14. package/lib/cjs/policies/DefaultMetricsPolicy.d.ts.map +1 -0
  15. package/lib/cjs/policies/DefaultMetricsPolicy.js +57 -0
  16. package/lib/cjs/policies/DefaultMetricsPolicy.js.map +1 -0
  17. package/lib/mjs/config/metrics.d.ts +24 -1
  18. package/lib/mjs/config/metrics.d.ts.map +1 -1
  19. package/lib/mjs/config/metrics.js +30 -7
  20. package/lib/mjs/config/metrics.js.map +1 -1
  21. package/lib/mjs/controllers/metrics.d.ts +13 -8
  22. package/lib/mjs/controllers/metrics.d.ts.map +1 -1
  23. package/lib/mjs/controllers/metrics.js +31 -14
  24. package/lib/mjs/controllers/metrics.js.map +1 -1
  25. package/lib/mjs/index.d.ts +21 -8
  26. package/lib/mjs/index.d.ts.map +1 -1
  27. package/lib/mjs/index.js +59 -24
  28. package/lib/mjs/index.js.map +1 -1
  29. package/lib/mjs/policies/DefaultMetricsPolicy.d.ts +11 -0
  30. package/lib/mjs/policies/DefaultMetricsPolicy.d.ts.map +1 -0
  31. package/lib/mjs/policies/DefaultMetricsPolicy.js +54 -0
  32. package/lib/mjs/policies/DefaultMetricsPolicy.js.map +1 -0
  33. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  34. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  35. package/package.json +9 -12
@@ -1 +1,25 @@
1
+ /**
2
+ *
3
+ * Configuraiton for prom metrics bundle for express
4
+ * https://github.com/jochen-schweizer/express-prom-bundle
5
+ *
6
+ */
7
+ declare const config: {
8
+ metrics: {
9
+ auth: {
10
+ token: string;
11
+ policy: string;
12
+ };
13
+ /**
14
+ * * Configuraiton for prom metrics bundle for express
15
+ * https://github.com/jochen-schweizer/express-prom-bundle
16
+ */
17
+ http: {
18
+ includeStatusCode: boolean;
19
+ includeMethod: boolean;
20
+ includePath: boolean;
21
+ };
22
+ };
23
+ };
24
+ export default config;
1
25
  //# sourceMappingURL=metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,QAAA,MAAM,MAAM;;;;;;QASJ;;;WAGG;;;;;;;CAYR,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1,7 +1,33 @@
1
- // import * as bundle from 'express-prom-bundle';
2
- // module.exports = {
3
- // http: {
4
- // middlewares: [],
5
- // },
6
- // };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ *
5
+ * Configuraiton for prom metrics bundle for express
6
+ * https://github.com/jochen-schweizer/express-prom-bundle
7
+ *
8
+ */
9
+ const config = {
10
+ metrics: {
11
+ auth: {
12
+ // set this in your project
13
+ token: "",
14
+ policy: "DefaultMetricsPolicy"
15
+ },
16
+ /**
17
+ * * Configuraiton for prom metrics bundle for express
18
+ * https://github.com/jochen-schweizer/express-prom-bundle
19
+ */
20
+ http: {
21
+ includeStatusCode: true,
22
+ includeMethod: true,
23
+ includePath: true,
24
+ // customLabels: "spinajs",
25
+ // includeUp: true,
26
+ // metricsPath: "/metrics",
27
+ // metricType: "histogram",
28
+ // httpDurationMetricName: 60
29
+ }
30
+ },
31
+ };
32
+ exports.default = config;
7
33
  //# sourceMappingURL=metrics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,qBAAqB;AACrB,YAAY;AACZ,uBAAuB;AACvB,OAAO;AACP,KAAK"}
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":";;AACA;;;;;GAKG;AACH,MAAM,MAAM,GAAG;IACX,OAAO,EAAE;QACL,IAAI,EAAE;YAEF,2BAA2B;YAC3B,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,sBAAsB;SACjC;QAED;;;WAGG;QACH,IAAI,EAAE;YACF,iBAAiB,EAAE,IAAI;YACvB,aAAa,EAAE,IAAI;YACnB,WAAW,EAAE,IAAI;YAClB,2BAA2B;YAC3B,oBAAoB;YACpB,2BAA2B;YAC3B,2BAA2B;YAC3B,6BAA6B;SAC/B;KACJ;CACF,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -1,10 +1,15 @@
1
- import { Bootstrapper } from '@spinajs/di';
2
- import * as client from 'prom-client';
3
- export declare const gauge: typeof client.Gauge;
4
- export declare const histogram: typeof client.Histogram;
5
- export declare const summary: typeof client.Summary;
6
- export declare const counter: typeof client.Counter;
7
- export declare class MetricsBootstrapper extends Bootstrapper {
8
- bootstrap(): void;
1
+ import { BaseController, Response } from '@spinajs/http';
2
+ import * as express from 'express';
3
+ declare class PrometheusResponse extends Response {
4
+ constructor();
5
+ execute(_req: express.Request, res: express.Response): Promise<void>;
9
6
  }
7
+ /**
8
+ * Default controller for serving
9
+ * metrics data. Can be protected by access policy from configuration file
10
+ */
11
+ export declare class Metrics extends BaseController {
12
+ getMetrics(): Promise<PrometheusResponse>;
13
+ }
14
+ export {};
10
15
  //# sourceMappingURL=metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,eAAO,MAAM,KAAK,qBAAe,CAAC;AAClC,eAAO,MAAM,SAAS,yBAAmB,CAAC;AAC1C,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,qBACa,mBAAoB,SAAQ,YAAY;IAC5C,SAAS,IAAI,IAAI;CAKzB"}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAO,QAAQ,EAAU,MAAM,eAAe,CAAC;AAEhF,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,cAAM,kBAAmB,SAAQ,QAAQ;;IAK1B,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ;CAIlE;AAED;;;GAGG;AACH,qBAEa,OAAQ,SAAQ,cAAc;IAE5B,UAAU;CAGxB"}
@@ -28,23 +28,40 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
  __setModuleDefault(result, mod);
29
29
  return result;
30
30
  };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
31
34
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.MetricsBootstrapper = exports.counter = exports.summary = exports.histogram = exports.gauge = void 0;
33
- const di_1 = require("@spinajs/di");
35
+ exports.Metrics = void 0;
36
+ const http_1 = require("@spinajs/http");
34
37
  const client = __importStar(require("prom-client"));
35
- exports.gauge = client.Gauge;
36
- exports.histogram = client.Histogram;
37
- exports.summary = client.Summary;
38
- exports.counter = client.Counter;
39
- let MetricsBootstrapper = class MetricsBootstrapper extends di_1.Bootstrapper {
40
- bootstrap() {
41
- client.collectDefaultMetrics({
42
- labels: { NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE },
43
- });
38
+ class PrometheusResponse extends http_1.Response {
39
+ constructor() {
40
+ super(null);
41
+ }
42
+ async execute(_req, res) {
43
+ res.contentType(client.register.contentType);
44
+ res.end(client.register.metrics());
45
+ }
46
+ }
47
+ /**
48
+ * Default controller for serving
49
+ * metrics data. Can be protected by access policy from configuration file
50
+ */
51
+ let Metrics = class Metrics extends http_1.BaseController {
52
+ async getMetrics() {
53
+ return new PrometheusResponse();
44
54
  }
45
55
  };
46
- MetricsBootstrapper = __decorate([
47
- (0, di_1.Injectable)(di_1.Bootstrapper)
48
- ], MetricsBootstrapper);
49
- exports.MetricsBootstrapper = MetricsBootstrapper;
56
+ __decorate([
57
+ (0, http_1.Get)('/'),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", []),
60
+ __metadata("design:returntype", Promise)
61
+ ], Metrics.prototype, "getMetrics", null);
62
+ Metrics = __decorate([
63
+ (0, http_1.BasePath)('metrics'),
64
+ (0, http_1.Policy)('metrics.auth.policy')
65
+ ], Metrics);
66
+ exports.Metrics = Metrics;
50
67
  //# sourceMappingURL=metrics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAuD;AACvD,oDAAsC;AAEzB,QAAA,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;AACrB,QAAA,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;AAC7B,QAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACzB,QAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AAE/B,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,iBAAY;IAC5C,SAAS;QACd,MAAM,CAAC,qBAAqB,CAAC;YAC3B,MAAM,EAAE,EAAE,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;SAC7D,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AANY,mBAAmB;IAD/B,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,mBAAmB,CAM/B;AANY,kDAAmB"}
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAgF;AAChF,oDAAsC;AAGtC,MAAM,kBAAmB,SAAQ,eAAQ;IACvC;QACE,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/D,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAED;;;GAGG;AAGI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,qBAAc;IAE5B,AAAN,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,kBAAkB,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAHc;IADZ,IAAA,UAAG,EAAC,GAAG,CAAC;;;;yCAGR;AAJU,OAAO;IAFnB,IAAA,eAAQ,EAAC,SAAS,CAAC;IACnB,IAAA,aAAM,EAAC,qBAAqB,CAAC;GACjB,OAAO,CAKnB;AALY,0BAAO"}
@@ -1,11 +1,24 @@
1
- import { BaseController, Response } from '@spinajs/http';
2
- import * as express from 'express';
3
- declare class PrometheusResponse extends Response {
4
- constructor();
5
- execute(_req: express.Request, res: express.Response): Promise<void>;
1
+ import { Bootstrapper } from '@spinajs/di';
2
+ import * as client from 'prom-client';
3
+ export declare const gauge: typeof client.Gauge;
4
+ export declare const histogram: typeof client.Histogram;
5
+ export declare const summary: typeof client.Summary;
6
+ export declare const counter: typeof client.Counter;
7
+ export declare class MetricsBootstrapper extends Bootstrapper {
8
+ bootstrap(): void;
6
9
  }
7
- export declare class Metrics extends BaseController {
8
- getMetrics(): Promise<PrometheusResponse>;
10
+ /**
11
+ * Simple wrapper class for handling prom metrics
12
+ */
13
+ export declare class Metrics {
14
+ protected _histograms: Map<string, client.Histogram>;
15
+ protected _gauges: Map<string, client.Gauge>;
16
+ protected _counters: Map<string, client.Counter>;
17
+ protected _summaries: Map<string, client.Summary>;
18
+ constructor();
19
+ histogram<T extends string>(name: string, configuration: client.HistogramConfiguration<T>): client.Histogram<string>;
20
+ gauge<T extends string>(name: string, configuration: client.GaugeConfiguration<T>): client.Gauge<string>;
21
+ counter<T extends string>(name: string, configuration: client.CounterConfiguration<T>): client.Counter<string>;
22
+ summary<T extends string>(name: string, configuration: client.SummaryConfiguration<T>): client.Summary<string>;
9
23
  }
10
- export {};
11
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,cAAM,kBAAmB,SAAQ,QAAQ;;IAK1B,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ;CAIlE;AAED,qBACa,OAAQ,SAAQ,cAAc;IAE5B,UAAU;CAGxB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAkB,MAAM,aAAa,CAAC;AAEvE,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAItC,eAAO,MAAM,KAAK,qBAAe,CAAC;AAClC,eAAO,MAAM,SAAS,yBAAmB,CAAC;AAC1C,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,qBACa,mBAAoB,SAAQ,YAAY;IAC5C,SAAS,IAAI,IAAI;CAoBzB;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IACrD,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;;IAS3C,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAQzF,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAQjF,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAQrF,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;CAO7F"}
package/lib/cjs/index.js CHANGED
@@ -28,35 +28,74 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
  __setModuleDefault(result, mod);
29
29
  return result;
30
30
  };
31
- var __metadata = (this && this.__metadata) || function (k, v) {
32
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Metrics = void 0;
36
- const http_1 = require("@spinajs/http");
35
+ exports.Metrics = exports.MetricsBootstrapper = exports.counter = exports.summary = exports.histogram = exports.gauge = void 0;
36
+ const di_1 = require("@spinajs/di");
37
37
  const client = __importStar(require("prom-client"));
38
- class PrometheusResponse extends http_1.Response {
38
+ const express_prom_bundle_1 = __importDefault(require("express-prom-bundle"));
39
+ const configuration_1 = require("@spinajs/configuration");
40
+ exports.gauge = client.Gauge;
41
+ exports.histogram = client.Histogram;
42
+ exports.summary = client.Summary;
43
+ exports.counter = client.Counter;
44
+ let MetricsBootstrapper = class MetricsBootstrapper extends di_1.Bootstrapper {
45
+ bootstrap() {
46
+ client.collectDefaultMetrics({
47
+ labels: { NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE },
48
+ });
49
+ di_1.DI.on('di.resolved.HttpServer', (_, server) => {
50
+ const cfg = _.get(configuration_1.Configuration);
51
+ const promCfg = cfg.get('metrics.http');
52
+ server.use((0, express_prom_bundle_1.default)({
53
+ ...promCfg,
54
+ // disable default autoregister
55
+ // we do this by controller with proper auth handling
56
+ autoregister: false,
57
+ }));
58
+ });
59
+ }
60
+ };
61
+ MetricsBootstrapper = __decorate([
62
+ (0, di_1.Injectable)(di_1.Bootstrapper)
63
+ ], MetricsBootstrapper);
64
+ exports.MetricsBootstrapper = MetricsBootstrapper;
65
+ /**
66
+ * Simple wrapper class for handling prom metrics
67
+ */
68
+ class Metrics {
39
69
  constructor() {
40
- super(null);
70
+ this._histograms = new Map();
71
+ this._gauges = new Map();
72
+ this._counters = new Map();
73
+ this._summaries = new Map();
41
74
  }
42
- async execute(_req, res) {
43
- res.contentType(client.register.contentType);
44
- res.end(client.register.metrics());
75
+ histogram(name, configuration) {
76
+ if (!this._histograms.has(name)) {
77
+ this._histograms.set(name, new client.Histogram(configuration));
78
+ }
79
+ return this._histograms.get(name);
45
80
  }
46
- }
47
- let Metrics = class Metrics extends http_1.BaseController {
48
- async getMetrics() {
49
- return new PrometheusResponse();
81
+ gauge(name, configuration) {
82
+ if (!this._gauges.has(name)) {
83
+ this._gauges.set(name, new client.Gauge(configuration));
84
+ }
85
+ return this._gauges.get(name);
50
86
  }
51
- };
52
- __decorate([
53
- (0, http_1.Get)(),
54
- __metadata("design:type", Function),
55
- __metadata("design:paramtypes", []),
56
- __metadata("design:returntype", Promise)
57
- ], Metrics.prototype, "getMetrics", null);
58
- Metrics = __decorate([
59
- (0, http_1.BasePath)('metrics')
60
- ], Metrics);
87
+ counter(name, configuration) {
88
+ if (!this._counters.has(name)) {
89
+ this._counters.set(name, new client.Gauge(configuration));
90
+ }
91
+ return this._counters.get(name);
92
+ }
93
+ summary(name, configuration) {
94
+ if (!this._summaries.has(name)) {
95
+ this._summaries.set(name, new client.Summary(configuration));
96
+ }
97
+ return this._summaries.get(name);
98
+ }
99
+ }
61
100
  exports.Metrics = Metrics;
62
101
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAwE;AACxE,oDAAsC;AAGtC,MAAM,kBAAmB,SAAQ,eAAQ;IACvC;QACE,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/D,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAGM,IAAM,OAAO,GAAb,MAAM,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AC;IAClC,CAAC;IAEM,OAAO,CAAmB,IAAY,EAAE,aAA6C;QAC1F,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC9B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;SAC9D;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AA5CD,0BA4CC"}
@@ -0,0 +1,11 @@
1
+ import { BasePolicy, IController, IRoute, Request } from '@spinajs/http';
2
+ import { Log } from '@spinajs/log';
3
+ export declare class DefaultMetricsPolicy extends BasePolicy {
4
+ protected Log: Log;
5
+ protected Token: string;
6
+ protected HEADER_TOKEN_FIELD: string;
7
+ protected isDev: boolean;
8
+ isEnabled(_action: IRoute, _instance: IController): boolean;
9
+ execute(req: Request): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=DefaultMetricsPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultMetricsPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/DefaultMetricsPolicy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAG3C,qBACa,oBAAqB,SAAQ,UAAU;IAElD,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAGnB,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;IAExB,SAAS,CAAC,kBAAkB,SAAqB;IAGjD,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC;IAGlB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO;IAIrD,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBlD"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DefaultMetricsPolicy = void 0;
13
+ const configuration_1 = require("@spinajs/configuration");
14
+ const http_1 = require("@spinajs/http");
15
+ const exceptions_1 = require("@spinajs/exceptions");
16
+ const log_1 = require("@spinajs/log");
17
+ const di_1 = require("@spinajs/di");
18
+ let DefaultMetricsPolicy = class DefaultMetricsPolicy extends http_1.BasePolicy {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.HEADER_TOKEN_FIELD = 'x-metrics-token';
22
+ }
23
+ isEnabled(_action, _instance) {
24
+ return true;
25
+ }
26
+ async execute(req) {
27
+ if (this.isDev) {
28
+ return;
29
+ }
30
+ const token = req.headers[this.HEADER_TOKEN_FIELD];
31
+ if (!token) {
32
+ this.Log.warn(`No token is set for restricted area, header field: ${this.HEADER_TOKEN_FIELD}, policy: DefaultMetricsPolicy, ip: ${req.storage.realIp}`);
33
+ throw new exceptions_1.Forbidden('access token is not set');
34
+ }
35
+ if (token !== this.Token) {
36
+ this.Log.warn(`Invalid access token received, token: ${token}, header field: ${this.HEADER_TOKEN_FIELD}, policy: DefaultMetricsPolicy, ip: ${req.storage.realIp}`);
37
+ throw new exceptions_1.Forbidden('invalid access token');
38
+ }
39
+ }
40
+ };
41
+ __decorate([
42
+ (0, log_1.Logger)('Security'),
43
+ __metadata("design:type", log_1.Log)
44
+ ], DefaultMetricsPolicy.prototype, "Log", void 0);
45
+ __decorate([
46
+ (0, configuration_1.Config)('metrics.auth.token'),
47
+ __metadata("design:type", String)
48
+ ], DefaultMetricsPolicy.prototype, "Token", void 0);
49
+ __decorate([
50
+ (0, configuration_1.Config)('configuration.isDevelopment'),
51
+ __metadata("design:type", Boolean)
52
+ ], DefaultMetricsPolicy.prototype, "isDev", void 0);
53
+ DefaultMetricsPolicy = __decorate([
54
+ (0, di_1.Injectable)(http_1.BasePolicy)
55
+ ], DefaultMetricsPolicy);
56
+ exports.DefaultMetricsPolicy = DefaultMetricsPolicy;
57
+ //# sourceMappingURL=DefaultMetricsPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultMetricsPolicy.js","sourceRoot":"","sources":["../../../src/policies/DefaultMetricsPolicy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAgD;AAChD,wCAAyE;AACzE,oDAAgD;AAChD,sCAA2C;AAC3C,oCAAyC;AAGlC,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,iBAAU;IAA7C;;QAOK,uBAAkB,GAAG,iBAAiB,CAAC;IA0BnD,CAAC;IApBQ,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAY;QAC/B,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO;SACR;QAED,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,EAAE;YACV,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,sDAAsD,IAAI,CAAC,kBAAkB,uCAAuC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACxJ,MAAM,IAAI,sBAAS,CAAC,yBAAyB,CAAC,CAAC;SAChD;QAED,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE;YACxB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,yCAAyC,KAAK,mBAAmB,IAAI,CAAC,kBAAkB,uCAAuC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACnK,MAAM,IAAI,sBAAS,CAAC,sBAAsB,CAAC,CAAC;SAC7C;IACH,CAAC;CACF,CAAA;AAhCC;IAAC,IAAA,YAAM,EAAC,UAAU,CAAC;8BACJ,SAAG;iDAAC;AAEnB;IAAC,IAAA,sBAAM,EAAC,oBAAoB,CAAC;;mDACL;AAIxB;IAAC,IAAA,sBAAM,EAAC,6BAA6B,CAAC;;mDACb;AAVd,oBAAoB;IADhC,IAAA,eAAU,EAAC,iBAAU,CAAC;GACV,oBAAoB,CAiChC;AAjCY,oDAAoB"}
@@ -1,2 +1,25 @@
1
- export {};
1
+ /**
2
+ *
3
+ * Configuraiton for prom metrics bundle for express
4
+ * https://github.com/jochen-schweizer/express-prom-bundle
5
+ *
6
+ */
7
+ declare const config: {
8
+ metrics: {
9
+ auth: {
10
+ token: string;
11
+ policy: string;
12
+ };
13
+ /**
14
+ * * Configuraiton for prom metrics bundle for express
15
+ * https://github.com/jochen-schweizer/express-prom-bundle
16
+ */
17
+ http: {
18
+ includeStatusCode: boolean;
19
+ includeMethod: boolean;
20
+ includePath: boolean;
21
+ };
22
+ };
23
+ };
24
+ export default config;
2
25
  //# sourceMappingURL=metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,QAAA,MAAM,MAAM;;;;;;QASJ;;;WAGG;;;;;;;CAYR,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1,8 +1,31 @@
1
- // import * as bundle from 'express-prom-bundle';
2
- export {};
3
- // module.exports = {
4
- // http: {
5
- // middlewares: [],
6
- // },
7
- // };
1
+ /**
2
+ *
3
+ * Configuraiton for prom metrics bundle for express
4
+ * https://github.com/jochen-schweizer/express-prom-bundle
5
+ *
6
+ */
7
+ const config = {
8
+ metrics: {
9
+ auth: {
10
+ // set this in your project
11
+ token: "",
12
+ policy: "DefaultMetricsPolicy"
13
+ },
14
+ /**
15
+ * * Configuraiton for prom metrics bundle for express
16
+ * https://github.com/jochen-schweizer/express-prom-bundle
17
+ */
18
+ http: {
19
+ includeStatusCode: true,
20
+ includeMethod: true,
21
+ includePath: true,
22
+ // customLabels: "spinajs",
23
+ // includeUp: true,
24
+ // metricsPath: "/metrics",
25
+ // metricType: "histogram",
26
+ // httpDurationMetricName: 60
27
+ }
28
+ },
29
+ };
30
+ export default config;
8
31
  //# sourceMappingURL=metrics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":"AAAA,iDAAiD;;AAEjD,qBAAqB;AACrB,YAAY;AACZ,uBAAuB;AACvB,OAAO;AACP,KAAK"}
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/config/metrics.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,MAAM,MAAM,GAAG;IACX,OAAO,EAAE;QACL,IAAI,EAAE;YAEF,2BAA2B;YAC3B,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,sBAAsB;SACjC;QAED;;;WAGG;QACH,IAAI,EAAE;YACF,iBAAiB,EAAE,IAAI;YACvB,aAAa,EAAE,IAAI;YACnB,WAAW,EAAE,IAAI;YAClB,2BAA2B;YAC3B,oBAAoB;YACpB,2BAA2B;YAC3B,2BAA2B;YAC3B,6BAA6B;SAC/B;KACJ;CACF,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1,10 +1,15 @@
1
- import { Bootstrapper } from '@spinajs/di';
2
- import * as client from 'prom-client';
3
- export declare const gauge: typeof client.Gauge;
4
- export declare const histogram: typeof client.Histogram;
5
- export declare const summary: typeof client.Summary;
6
- export declare const counter: typeof client.Counter;
7
- export declare class MetricsBootstrapper extends Bootstrapper {
8
- bootstrap(): void;
1
+ import { BaseController, Response } from '@spinajs/http';
2
+ import * as express from 'express';
3
+ declare class PrometheusResponse extends Response {
4
+ constructor();
5
+ execute(_req: express.Request, res: express.Response): Promise<void>;
9
6
  }
7
+ /**
8
+ * Default controller for serving
9
+ * metrics data. Can be protected by access policy from configuration file
10
+ */
11
+ export declare class Metrics extends BaseController {
12
+ getMetrics(): Promise<PrometheusResponse>;
13
+ }
14
+ export {};
10
15
  //# sourceMappingURL=metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,eAAO,MAAM,KAAK,qBAAe,CAAC;AAClC,eAAO,MAAM,SAAS,yBAAmB,CAAC;AAC1C,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,qBACa,mBAAoB,SAAQ,YAAY;IAC5C,SAAS,IAAI,IAAI;CAKzB"}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAO,QAAQ,EAAU,MAAM,eAAe,CAAC;AAEhF,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,cAAM,kBAAmB,SAAQ,QAAQ;;IAK1B,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ;CAIlE;AAED;;;GAGG;AACH,qBAEa,OAAQ,SAAQ,cAAc;IAE5B,UAAU;CAGxB"}
@@ -4,21 +4,38 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { Injectable, Bootstrapper } from '@spinajs/di';
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { BasePath, BaseController, Get, Response, Policy } from '@spinajs/http';
8
11
  import * as client from 'prom-client';
9
- export const gauge = client.Gauge;
10
- export const histogram = client.Histogram;
11
- export const summary = client.Summary;
12
- export const counter = client.Counter;
13
- let MetricsBootstrapper = class MetricsBootstrapper extends Bootstrapper {
14
- bootstrap() {
15
- client.collectDefaultMetrics({
16
- labels: { NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE },
17
- });
12
+ class PrometheusResponse extends Response {
13
+ constructor() {
14
+ super(null);
15
+ }
16
+ async execute(_req, res) {
17
+ res.contentType(client.register.contentType);
18
+ res.end(client.register.metrics());
19
+ }
20
+ }
21
+ /**
22
+ * Default controller for serving
23
+ * metrics data. Can be protected by access policy from configuration file
24
+ */
25
+ let Metrics = class Metrics extends BaseController {
26
+ async getMetrics() {
27
+ return new PrometheusResponse();
18
28
  }
19
29
  };
20
- MetricsBootstrapper = __decorate([
21
- Injectable(Bootstrapper)
22
- ], MetricsBootstrapper);
23
- export { MetricsBootstrapper };
30
+ __decorate([
31
+ Get('/'),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", []),
34
+ __metadata("design:returntype", Promise)
35
+ ], Metrics.prototype, "getMetrics", null);
36
+ Metrics = __decorate([
37
+ BasePath('metrics'),
38
+ Policy('metrics.auth.policy')
39
+ ], Metrics);
40
+ export { Metrics };
24
41
  //# sourceMappingURL=metrics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;AAC1C,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AAE/B,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,YAAY;IAC5C,SAAS;QACd,MAAM,CAAC,qBAAqB,CAAC;YAC3B,MAAM,EAAE,EAAE,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;SAC7D,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AANY,mBAAmB;IAD/B,UAAU,CAAC,YAAY,CAAC;GACZ,mBAAmB,CAM/B;SANY,mBAAmB"}
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/controllers/metrics.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAGtC,MAAM,kBAAmB,SAAQ,QAAQ;IACvC;QACE,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/D,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAED;;;GAGG;AAGI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,cAAc;IAE5B,AAAN,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,kBAAkB,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAHc;IADZ,GAAG,CAAC,GAAG,CAAC;;;;yCAGR;AAJU,OAAO;IAFnB,QAAQ,CAAC,SAAS,CAAC;IACnB,MAAM,CAAC,qBAAqB,CAAC;GACjB,OAAO,CAKnB;SALY,OAAO"}
@@ -1,11 +1,24 @@
1
- import { BaseController, Response } from '@spinajs/http';
2
- import * as express from 'express';
3
- declare class PrometheusResponse extends Response {
4
- constructor();
5
- execute(_req: express.Request, res: express.Response): Promise<void>;
1
+ import { Bootstrapper } from '@spinajs/di';
2
+ import * as client from 'prom-client';
3
+ export declare const gauge: typeof client.Gauge;
4
+ export declare const histogram: typeof client.Histogram;
5
+ export declare const summary: typeof client.Summary;
6
+ export declare const counter: typeof client.Counter;
7
+ export declare class MetricsBootstrapper extends Bootstrapper {
8
+ bootstrap(): void;
6
9
  }
7
- export declare class Metrics extends BaseController {
8
- getMetrics(): Promise<PrometheusResponse>;
10
+ /**
11
+ * Simple wrapper class for handling prom metrics
12
+ */
13
+ export declare class Metrics {
14
+ protected _histograms: Map<string, client.Histogram>;
15
+ protected _gauges: Map<string, client.Gauge>;
16
+ protected _counters: Map<string, client.Counter>;
17
+ protected _summaries: Map<string, client.Summary>;
18
+ constructor();
19
+ histogram<T extends string>(name: string, configuration: client.HistogramConfiguration<T>): client.Histogram<string>;
20
+ gauge<T extends string>(name: string, configuration: client.GaugeConfiguration<T>): client.Gauge<string>;
21
+ counter<T extends string>(name: string, configuration: client.CounterConfiguration<T>): client.Counter<string>;
22
+ summary<T extends string>(name: string, configuration: client.SummaryConfiguration<T>): client.Summary<string>;
9
23
  }
10
- export {};
11
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,cAAM,kBAAmB,SAAQ,QAAQ;;IAK1B,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ;CAIlE;AAED,qBACa,OAAQ,SAAQ,cAAc;IAE5B,UAAU;CAGxB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAkB,MAAM,aAAa,CAAC;AAEvE,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAItC,eAAO,MAAM,KAAK,qBAAe,CAAC;AAClC,eAAO,MAAM,SAAS,yBAAmB,CAAC;AAC1C,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,qBACa,mBAAoB,SAAQ,YAAY;IAC5C,SAAS,IAAI,IAAI;CAoBzB;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IACrD,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;;IAS3C,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAQzF,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