@takentrade/takentrade-libs 4.1.1 → 4.1.2
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 +6 -57
- package/dist/auth/guards/index.d.ts +1 -0
- package/dist/auth/guards/index.js +1 -0
- package/dist/auth/guards/tnt-base-auth.guard.d.ts +15 -0
- package/dist/auth/guards/tnt-base-auth.guard.js +54 -0
- package/dist/bullmq/config/bull.config.js +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -21
- package/dist/metrics/circuit-breaker-metrics.service.d.ts +0 -61
- package/dist/metrics/circuit-breaker-metrics.service.js +0 -149
- package/dist/metrics/index.d.ts +0 -5
- package/dist/metrics/index.js +0 -21
- package/dist/metrics/metrics-registry.d.ts +0 -50
- package/dist/metrics/metrics-registry.js +0 -156
- package/dist/metrics/metrics-updater.d.ts +0 -32
- package/dist/metrics/metrics-updater.js +0 -102
- package/dist/metrics/metrics.controller.d.ts +0 -11
- package/dist/metrics/metrics.controller.js +0 -32
- package/dist/metrics/metrics.interface.d.ts +0 -53
- package/dist/metrics/metrics.interface.js +0 -23
- package/dist/metrics/metrics.module.d.ts +0 -11
- package/dist/metrics/metrics.module.js +0 -39
- package/dist/metrics/metrics.service.d.ts +0 -50
- package/dist/metrics/metrics.service.js +0 -165
- package/dist/monitoring/alerting.service.d.ts +0 -82
- package/dist/monitoring/alerting.service.js +0 -290
- package/dist/monitoring/index.d.ts +0 -5
- package/dist/monitoring/index.js +0 -21
- package/dist/monitoring/monitoring.interface.d.ts +0 -102
- package/dist/monitoring/monitoring.interface.js +0 -10
- package/dist/monitoring/monitoring.module.d.ts +0 -8
- package/dist/monitoring/monitoring.module.js +0 -44
- package/dist/monitoring/sentry.service.d.ts +0 -65
- package/dist/monitoring/sentry.service.js +0 -218
- package/dist/monitoring/uptime.service.d.ts +0 -59
- package/dist/monitoring/uptime.service.js +0 -213
- package/dist/resilience/circuit-breaker-event-handler.d.ts +0 -16
- package/dist/resilience/circuit-breaker-event-handler.js +0 -70
- package/dist/resilience/circuit-breaker-factory.d.ts +0 -19
- package/dist/resilience/circuit-breaker-factory.js +0 -51
- package/dist/resilience/circuit-breaker-stats.service.d.ts +0 -37
- package/dist/resilience/circuit-breaker-stats.service.js +0 -69
- package/dist/resilience/circuit-breaker.interface.d.ts +0 -59
- package/dist/resilience/circuit-breaker.interface.js +0 -25
- package/dist/resilience/circuit-breaker.module.d.ts +0 -2
- package/dist/resilience/circuit-breaker.module.js +0 -21
- package/dist/resilience/circuit-breaker.service.d.ts +0 -119
- package/dist/resilience/circuit-breaker.service.js +0 -234
- package/dist/resilience/index.d.ts +0 -3
- package/dist/resilience/index.js +0 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takentrade/takentrade-libs",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"author": "Solomon Olatunji",
|
|
5
5
|
"description": "TakeNTrade shared libraries",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"test:watch": "jest --watch",
|
|
15
15
|
"test:cov": "jest --coverage",
|
|
16
|
-
"build": "rm -rf dist && tsc",
|
|
16
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
17
17
|
"lint": "eslint src --ext .ts",
|
|
18
18
|
"format": "prettier --write .",
|
|
19
19
|
"format:check": "prettier --check ."
|
|
@@ -31,48 +31,42 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@nestjs/axios": "^4.0.1",
|
|
33
33
|
"@nestjs/bullmq": "^11.0.4",
|
|
34
|
-
"@nestjs/common": "^11.1.
|
|
35
|
-
"@nestjs/config": "^4.0.
|
|
34
|
+
"@nestjs/common": "^11.1.19",
|
|
35
|
+
"@nestjs/config": "^4.0.4",
|
|
36
|
+
"@nestjs/core": "^11.1.19",
|
|
36
37
|
"@nestjs/jwt": "^11.0.2",
|
|
37
|
-
"@nestjs/microservices": "^11.1.
|
|
38
|
+
"@nestjs/microservices": "^11.1.19",
|
|
38
39
|
"@nestjs/passport": "^11.0.5",
|
|
39
40
|
"@nestjs/terminus": "^11.1.1",
|
|
40
|
-
"@sentry/node": "^10.45.0",
|
|
41
|
-
"@sentry/tracing": "^7.120.4",
|
|
42
41
|
"class-transformer": "^0.5.1",
|
|
43
42
|
"class-validator": "^0.15.1",
|
|
44
|
-
"cloudinary": "^2.
|
|
45
|
-
"cockatiel": "^3.2.1",
|
|
43
|
+
"cloudinary": "^2.10.0",
|
|
46
44
|
"country-codes-list": "^2.0.0",
|
|
47
45
|
"decimal.js": "^10.6.0",
|
|
48
46
|
"ioredis": "^5.10.1",
|
|
49
|
-
"joi": "^18.
|
|
47
|
+
"joi": "^18.2.1",
|
|
50
48
|
"jsonwebtoken": "^9.0.3",
|
|
51
49
|
"object-hash": "^3.0.0",
|
|
52
|
-
"opossum": "^9.0.0",
|
|
53
50
|
"passport": "^0.7.0",
|
|
54
51
|
"passport-jwt": "^4.0.1",
|
|
55
52
|
"pino": "^10.3.1",
|
|
56
53
|
"pino-pretty": "^13.1.3",
|
|
57
|
-
"prom-client": "^15.1.3",
|
|
58
54
|
"rxjs": "^7.8.2",
|
|
59
55
|
"tsup": "^8.5.1",
|
|
60
|
-
"uuid": "^
|
|
56
|
+
"uuid": "^14.0.0"
|
|
61
57
|
},
|
|
62
58
|
"devDependencies": {
|
|
63
|
-
"@nestjs/
|
|
64
|
-
"@nestjs/testing": "^11.1.17",
|
|
59
|
+
"@nestjs/testing": "^11.1.19",
|
|
65
60
|
"@types/jest": "^30.0.0",
|
|
66
61
|
"@types/multer": "^2.1.0",
|
|
67
|
-
"@types/node": "^25.
|
|
62
|
+
"@types/node": "^25.6.2",
|
|
68
63
|
"@types/object-hash": "^3.0.6",
|
|
69
|
-
"@types/opossum": "^8.1.9",
|
|
70
64
|
"@types/passport": "^1.0.17",
|
|
71
65
|
"@types/passport-jwt": "^4.0.1",
|
|
72
|
-
"jest": "^
|
|
73
|
-
"prettier": "^3.8.
|
|
74
|
-
"ts-jest": "^29.
|
|
75
|
-
"typescript": "^
|
|
66
|
+
"jest": "^30.4.2",
|
|
67
|
+
"prettier": "^3.8.3",
|
|
68
|
+
"ts-jest": "^29.4.9",
|
|
69
|
+
"typescript": "^6.0.3"
|
|
76
70
|
},
|
|
77
71
|
"exports": {
|
|
78
72
|
".": "./dist/index.js",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { MetricsService } from './metrics.service';
|
|
2
|
-
/**
|
|
3
|
-
* Circuit Breaker Metrics Integration
|
|
4
|
-
*
|
|
5
|
-
* Automatically collects metrics for circuit breaker operations
|
|
6
|
-
*/
|
|
7
|
-
export declare class CircuitBreakerMetricsService {
|
|
8
|
-
private readonly metricsService;
|
|
9
|
-
private readonly logger;
|
|
10
|
-
private initialized;
|
|
11
|
-
constructor(metricsService: MetricsService);
|
|
12
|
-
/**
|
|
13
|
-
* Initialize circuit breaker metrics
|
|
14
|
-
*/
|
|
15
|
-
initialize(): void;
|
|
16
|
-
/**
|
|
17
|
-
* Record circuit breaker state
|
|
18
|
-
*
|
|
19
|
-
* @param name - Circuit breaker name
|
|
20
|
-
* @param state - State value (0=closed, 1=open, 2=half-open)
|
|
21
|
-
*/
|
|
22
|
-
recordState(name: string, state: number): void;
|
|
23
|
-
/**
|
|
24
|
-
* Record a circuit breaker call
|
|
25
|
-
*
|
|
26
|
-
* @param name - Circuit breaker name
|
|
27
|
-
* @param result - Call result (success, failure, reject, timeout)
|
|
28
|
-
*/
|
|
29
|
-
recordCall(name: string, result: string): void;
|
|
30
|
-
/**
|
|
31
|
-
* Record circuit breaker latency
|
|
32
|
-
*
|
|
33
|
-
* @param name - Circuit breaker name
|
|
34
|
-
* @param latencyMs - Latency in milliseconds
|
|
35
|
-
*/
|
|
36
|
-
recordLatency(name: string, latencyMs: number): void;
|
|
37
|
-
/**
|
|
38
|
-
* Record a circuit breaker failure
|
|
39
|
-
*
|
|
40
|
-
* @param name - Circuit breaker name
|
|
41
|
-
*/
|
|
42
|
-
recordFailure(name: string): void;
|
|
43
|
-
/**
|
|
44
|
-
* Record a circuit breaker success
|
|
45
|
-
*
|
|
46
|
-
* @param name - Circuit breaker name
|
|
47
|
-
*/
|
|
48
|
-
recordSuccess(name: string): void;
|
|
49
|
-
/**
|
|
50
|
-
* Record a circuit breaker reject
|
|
51
|
-
*
|
|
52
|
-
* @param name - Circuit breaker name
|
|
53
|
-
*/
|
|
54
|
-
recordReject(name: string): void;
|
|
55
|
-
/**
|
|
56
|
-
* Record a circuit breaker timeout
|
|
57
|
-
*
|
|
58
|
-
* @param name - Circuit breaker name
|
|
59
|
-
*/
|
|
60
|
-
recordTimeout(name: string): void;
|
|
61
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
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 CircuitBreakerMetricsService_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.CircuitBreakerMetricsService = void 0;
|
|
11
|
-
const common_1 = require("@nestjs/common");
|
|
12
|
-
const metrics_interface_1 = require("./metrics.interface");
|
|
13
|
-
/**
|
|
14
|
-
* Circuit Breaker Metrics Integration
|
|
15
|
-
*
|
|
16
|
-
* Automatically collects metrics for circuit breaker operations
|
|
17
|
-
*/
|
|
18
|
-
let CircuitBreakerMetricsService = CircuitBreakerMetricsService_1 = class CircuitBreakerMetricsService {
|
|
19
|
-
metricsService;
|
|
20
|
-
logger = new common_1.Logger(CircuitBreakerMetricsService_1.name);
|
|
21
|
-
initialized = false;
|
|
22
|
-
constructor(metricsService) {
|
|
23
|
-
this.metricsService = metricsService;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Initialize circuit breaker metrics
|
|
27
|
-
*/
|
|
28
|
-
initialize() {
|
|
29
|
-
if (this.initialized) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
// Circuit breaker state gauge
|
|
33
|
-
this.metricsService.registerGauge({
|
|
34
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.STATE,
|
|
35
|
-
help: 'Circuit breaker state (0=closed, 1=open, 2=half-open)',
|
|
36
|
-
labelNames: ['name'],
|
|
37
|
-
});
|
|
38
|
-
// Total calls counter
|
|
39
|
-
this.metricsService.registerCounter({
|
|
40
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.CALLS_TOTAL,
|
|
41
|
-
help: 'Total circuit breaker calls',
|
|
42
|
-
labelNames: ['name', 'result'],
|
|
43
|
-
});
|
|
44
|
-
// Latency histogram
|
|
45
|
-
this.metricsService.registerHistogram({
|
|
46
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.LATENCY_SECONDS,
|
|
47
|
-
help: 'Circuit breaker request latency in seconds',
|
|
48
|
-
labelNames: ['name'],
|
|
49
|
-
buckets: metrics_interface_1.DEFAULT_LATENCY_BUCKETS,
|
|
50
|
-
});
|
|
51
|
-
// Failures counter
|
|
52
|
-
this.metricsService.registerCounter({
|
|
53
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.FAILURES_TOTAL,
|
|
54
|
-
help: 'Total circuit breaker failures',
|
|
55
|
-
labelNames: ['name'],
|
|
56
|
-
});
|
|
57
|
-
// Successes counter
|
|
58
|
-
this.metricsService.registerCounter({
|
|
59
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.SUCCESSES_TOTAL,
|
|
60
|
-
help: 'Total circuit breaker successes',
|
|
61
|
-
labelNames: ['name'],
|
|
62
|
-
});
|
|
63
|
-
// Rejects counter
|
|
64
|
-
this.metricsService.registerCounter({
|
|
65
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.REJECTS_TOTAL,
|
|
66
|
-
help: 'Total circuit breaker rejects',
|
|
67
|
-
labelNames: ['name'],
|
|
68
|
-
});
|
|
69
|
-
// Timeouts counter
|
|
70
|
-
this.metricsService.registerCounter({
|
|
71
|
-
name: metrics_interface_1.CIRCUIT_BREAKER_METRICS.TIMEOUTS_TOTAL,
|
|
72
|
-
help: 'Total circuit breaker timeouts',
|
|
73
|
-
labelNames: ['name'],
|
|
74
|
-
});
|
|
75
|
-
this.initialized = true;
|
|
76
|
-
this.logger.log('Circuit breaker metrics initialized');
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Record circuit breaker state
|
|
80
|
-
*
|
|
81
|
-
* @param name - Circuit breaker name
|
|
82
|
-
* @param state - State value (0=closed, 1=open, 2=half-open)
|
|
83
|
-
*/
|
|
84
|
-
recordState(name, state) {
|
|
85
|
-
this.metricsService.setGauge(metrics_interface_1.CIRCUIT_BREAKER_METRICS.STATE, state, {
|
|
86
|
-
name,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Record a circuit breaker call
|
|
91
|
-
*
|
|
92
|
-
* @param name - Circuit breaker name
|
|
93
|
-
* @param result - Call result (success, failure, reject, timeout)
|
|
94
|
-
*/
|
|
95
|
-
recordCall(name, result) {
|
|
96
|
-
this.metricsService.incrementCounter(metrics_interface_1.CIRCUIT_BREAKER_METRICS.CALLS_TOTAL, {
|
|
97
|
-
name,
|
|
98
|
-
result,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Record circuit breaker latency
|
|
103
|
-
*
|
|
104
|
-
* @param name - Circuit breaker name
|
|
105
|
-
* @param latencyMs - Latency in milliseconds
|
|
106
|
-
*/
|
|
107
|
-
recordLatency(name, latencyMs) {
|
|
108
|
-
this.metricsService.observeHistogram(metrics_interface_1.CIRCUIT_BREAKER_METRICS.LATENCY_SECONDS, latencyMs / 1000, // Convert to seconds
|
|
109
|
-
{ name });
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Record a circuit breaker failure
|
|
113
|
-
*
|
|
114
|
-
* @param name - Circuit breaker name
|
|
115
|
-
*/
|
|
116
|
-
recordFailure(name) {
|
|
117
|
-
this.metricsService.incrementCounter(metrics_interface_1.CIRCUIT_BREAKER_METRICS.FAILURES_TOTAL, { name });
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Record a circuit breaker success
|
|
121
|
-
*
|
|
122
|
-
* @param name - Circuit breaker name
|
|
123
|
-
*/
|
|
124
|
-
recordSuccess(name) {
|
|
125
|
-
this.metricsService.incrementCounter(metrics_interface_1.CIRCUIT_BREAKER_METRICS.SUCCESSES_TOTAL, { name });
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Record a circuit breaker reject
|
|
129
|
-
*
|
|
130
|
-
* @param name - Circuit breaker name
|
|
131
|
-
*/
|
|
132
|
-
recordReject(name) {
|
|
133
|
-
this.metricsService.incrementCounter(metrics_interface_1.CIRCUIT_BREAKER_METRICS.REJECTS_TOTAL, {
|
|
134
|
-
name,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Record a circuit breaker timeout
|
|
139
|
-
*
|
|
140
|
-
* @param name - Circuit breaker name
|
|
141
|
-
*/
|
|
142
|
-
recordTimeout(name) {
|
|
143
|
-
this.metricsService.incrementCounter(metrics_interface_1.CIRCUIT_BREAKER_METRICS.TIMEOUTS_TOTAL, { name });
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
exports.CircuitBreakerMetricsService = CircuitBreakerMetricsService;
|
|
147
|
-
exports.CircuitBreakerMetricsService = CircuitBreakerMetricsService = CircuitBreakerMetricsService_1 = __decorate([
|
|
148
|
-
(0, common_1.Injectable)()
|
|
149
|
-
], CircuitBreakerMetricsService);
|
package/dist/metrics/index.d.ts
DELETED
package/dist/metrics/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./metrics.interface"), exports);
|
|
18
|
-
__exportStar(require("./metrics.service"), exports);
|
|
19
|
-
__exportStar(require("./metrics.controller"), exports);
|
|
20
|
-
__exportStar(require("./metrics.module"), exports);
|
|
21
|
-
__exportStar(require("./circuit-breaker-metrics.service"), exports);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Counter, Gauge, Histogram, Summary, Registry } from 'prom-client';
|
|
2
|
-
import { MetricEntry, CounterConfig, GaugeConfig, HistogramConfig, SummaryConfig } from './metrics.interface';
|
|
3
|
-
/**
|
|
4
|
-
* Metrics Registry Manager
|
|
5
|
-
*
|
|
6
|
-
* Handles metric registration and retrieval
|
|
7
|
-
*/
|
|
8
|
-
export declare class MetricsRegistry {
|
|
9
|
-
private readonly registry;
|
|
10
|
-
private readonly prefix;
|
|
11
|
-
private readonly logger;
|
|
12
|
-
private readonly metrics;
|
|
13
|
-
constructor(registry: Registry, prefix?: string);
|
|
14
|
-
/**
|
|
15
|
-
* Register a counter metric
|
|
16
|
-
*/
|
|
17
|
-
registerCounter(config: CounterConfig): Counter<string>;
|
|
18
|
-
/**
|
|
19
|
-
* Register a gauge metric
|
|
20
|
-
*/
|
|
21
|
-
registerGauge(config: GaugeConfig): Gauge<string>;
|
|
22
|
-
/**
|
|
23
|
-
* Register a histogram metric
|
|
24
|
-
*/
|
|
25
|
-
registerHistogram(config: HistogramConfig): Histogram<string>;
|
|
26
|
-
/**
|
|
27
|
-
* Register a summary metric
|
|
28
|
-
*/
|
|
29
|
-
registerSummary(config: SummaryConfig): Summary<string>;
|
|
30
|
-
/**
|
|
31
|
-
* Get a metric by name
|
|
32
|
-
*/
|
|
33
|
-
getMetric(name: string): MetricEntry | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Get all registered metric names
|
|
36
|
-
*/
|
|
37
|
-
getMetricNames(): string[];
|
|
38
|
-
/**
|
|
39
|
-
* Check if a metric exists
|
|
40
|
-
*/
|
|
41
|
-
hasMetric(name: string): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Clear all registered metrics
|
|
44
|
-
*/
|
|
45
|
-
clear(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Prefix a metric name with the configured prefix
|
|
48
|
-
*/
|
|
49
|
-
private prefixMetricName;
|
|
50
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetricsRegistry = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const prom_client_1 = require("prom-client");
|
|
6
|
-
const metrics_interface_1 = require("./metrics.interface");
|
|
7
|
-
/**
|
|
8
|
-
* Metrics Registry Manager
|
|
9
|
-
*
|
|
10
|
-
* Handles metric registration and retrieval
|
|
11
|
-
*/
|
|
12
|
-
class MetricsRegistry {
|
|
13
|
-
registry;
|
|
14
|
-
prefix;
|
|
15
|
-
logger = new common_1.Logger(MetricsRegistry.name);
|
|
16
|
-
metrics = new Map();
|
|
17
|
-
constructor(registry, prefix = '') {
|
|
18
|
-
this.registry = registry;
|
|
19
|
-
this.prefix = prefix;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Register a counter metric
|
|
23
|
-
*/
|
|
24
|
-
registerCounter(config) {
|
|
25
|
-
const name = this.prefixMetricName(config.name);
|
|
26
|
-
if (this.metrics.has(name)) {
|
|
27
|
-
const existing = this.metrics.get(name);
|
|
28
|
-
if (existing.type !== metrics_interface_1.MetricType.COUNTER) {
|
|
29
|
-
throw new Error(`Metric '${name}' already exists with type '${existing.type}'`);
|
|
30
|
-
}
|
|
31
|
-
return existing.metric;
|
|
32
|
-
}
|
|
33
|
-
const counter = new prom_client_1.Counter({
|
|
34
|
-
...config,
|
|
35
|
-
name,
|
|
36
|
-
registers: [this.registry],
|
|
37
|
-
});
|
|
38
|
-
this.metrics.set(name, {
|
|
39
|
-
type: metrics_interface_1.MetricType.COUNTER,
|
|
40
|
-
metric: counter,
|
|
41
|
-
config,
|
|
42
|
-
});
|
|
43
|
-
this.logger.debug(`Counter '${name}' registered`);
|
|
44
|
-
return counter;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Register a gauge metric
|
|
48
|
-
*/
|
|
49
|
-
registerGauge(config) {
|
|
50
|
-
const name = this.prefixMetricName(config.name);
|
|
51
|
-
if (this.metrics.has(name)) {
|
|
52
|
-
const existing = this.metrics.get(name);
|
|
53
|
-
if (existing.type !== metrics_interface_1.MetricType.GAUGE) {
|
|
54
|
-
throw new Error(`Metric '${name}' already exists with type '${existing.type}'`);
|
|
55
|
-
}
|
|
56
|
-
return existing.metric;
|
|
57
|
-
}
|
|
58
|
-
const gauge = new prom_client_1.Gauge({
|
|
59
|
-
...config,
|
|
60
|
-
name,
|
|
61
|
-
registers: [this.registry],
|
|
62
|
-
});
|
|
63
|
-
this.metrics.set(name, {
|
|
64
|
-
type: metrics_interface_1.MetricType.GAUGE,
|
|
65
|
-
metric: gauge,
|
|
66
|
-
config,
|
|
67
|
-
});
|
|
68
|
-
this.logger.debug(`Gauge '${name}' registered`);
|
|
69
|
-
return gauge;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Register a histogram metric
|
|
73
|
-
*/
|
|
74
|
-
registerHistogram(config) {
|
|
75
|
-
const name = this.prefixMetricName(config.name);
|
|
76
|
-
if (this.metrics.has(name)) {
|
|
77
|
-
const existing = this.metrics.get(name);
|
|
78
|
-
if (existing.type !== metrics_interface_1.MetricType.HISTOGRAM) {
|
|
79
|
-
throw new Error(`Metric '${name}' already exists with type '${existing.type}'`);
|
|
80
|
-
}
|
|
81
|
-
return existing.metric;
|
|
82
|
-
}
|
|
83
|
-
const histogram = new prom_client_1.Histogram({
|
|
84
|
-
buckets: metrics_interface_1.DEFAULT_LATENCY_BUCKETS,
|
|
85
|
-
...config,
|
|
86
|
-
name,
|
|
87
|
-
registers: [this.registry],
|
|
88
|
-
});
|
|
89
|
-
this.metrics.set(name, {
|
|
90
|
-
type: metrics_interface_1.MetricType.HISTOGRAM,
|
|
91
|
-
metric: histogram,
|
|
92
|
-
config,
|
|
93
|
-
});
|
|
94
|
-
this.logger.debug(`Histogram '${name}' registered`);
|
|
95
|
-
return histogram;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Register a summary metric
|
|
99
|
-
*/
|
|
100
|
-
registerSummary(config) {
|
|
101
|
-
const name = this.prefixMetricName(config.name);
|
|
102
|
-
if (this.metrics.has(name)) {
|
|
103
|
-
const existing = this.metrics.get(name);
|
|
104
|
-
if (existing.type !== metrics_interface_1.MetricType.SUMMARY) {
|
|
105
|
-
throw new Error(`Metric '${name}' already exists with type '${existing.type}'`);
|
|
106
|
-
}
|
|
107
|
-
return existing.metric;
|
|
108
|
-
}
|
|
109
|
-
const summary = new prom_client_1.Summary({
|
|
110
|
-
percentiles: metrics_interface_1.DEFAULT_PERCENTILES,
|
|
111
|
-
...config,
|
|
112
|
-
name,
|
|
113
|
-
registers: [this.registry],
|
|
114
|
-
});
|
|
115
|
-
this.metrics.set(name, {
|
|
116
|
-
type: metrics_interface_1.MetricType.SUMMARY,
|
|
117
|
-
metric: summary,
|
|
118
|
-
config,
|
|
119
|
-
});
|
|
120
|
-
this.logger.debug(`Summary '${name}' registered`);
|
|
121
|
-
return summary;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Get a metric by name
|
|
125
|
-
*/
|
|
126
|
-
getMetric(name) {
|
|
127
|
-
const fullName = this.prefixMetricName(name);
|
|
128
|
-
return this.metrics.get(fullName);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Get all registered metric names
|
|
132
|
-
*/
|
|
133
|
-
getMetricNames() {
|
|
134
|
-
return Array.from(this.metrics.keys());
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Check if a metric exists
|
|
138
|
-
*/
|
|
139
|
-
hasMetric(name) {
|
|
140
|
-
const fullName = this.prefixMetricName(name);
|
|
141
|
-
return this.metrics.has(fullName);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Clear all registered metrics
|
|
145
|
-
*/
|
|
146
|
-
clear() {
|
|
147
|
-
this.metrics.clear();
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Prefix a metric name with the configured prefix
|
|
151
|
-
*/
|
|
152
|
-
prefixMetricName(name) {
|
|
153
|
-
return this.prefix ? `${this.prefix}${name}` : name;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.MetricsRegistry = MetricsRegistry;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { MetricEntry } from './metrics.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Metrics Updater
|
|
4
|
-
*
|
|
5
|
-
* Handles updating metric values
|
|
6
|
-
*/
|
|
7
|
-
export declare class MetricsUpdater {
|
|
8
|
-
/**
|
|
9
|
-
* Increment a counter metric
|
|
10
|
-
*/
|
|
11
|
-
incrementCounter(entry: MetricEntry, labels?: Record<string, string | number>, value?: number): void;
|
|
12
|
-
/**
|
|
13
|
-
* Set a gauge metric value
|
|
14
|
-
*/
|
|
15
|
-
setGauge(entry: MetricEntry, value: number, labels?: Record<string, string | number>): void;
|
|
16
|
-
/**
|
|
17
|
-
* Increment a gauge metric
|
|
18
|
-
*/
|
|
19
|
-
incrementGauge(entry: MetricEntry, labels?: Record<string, string | number>, value?: number): void;
|
|
20
|
-
/**
|
|
21
|
-
* Decrement a gauge metric
|
|
22
|
-
*/
|
|
23
|
-
decrementGauge(entry: MetricEntry, labels?: Record<string, string | number>, value?: number): void;
|
|
24
|
-
/**
|
|
25
|
-
* Observe a histogram metric
|
|
26
|
-
*/
|
|
27
|
-
observeHistogram(entry: MetricEntry, value: number, labels?: Record<string, string | number>): void;
|
|
28
|
-
/**
|
|
29
|
-
* Observe a summary metric
|
|
30
|
-
*/
|
|
31
|
-
observeSummary(entry: MetricEntry, value: number, labels?: Record<string, string | number>): void;
|
|
32
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetricsUpdater = void 0;
|
|
4
|
-
const metrics_interface_1 = require("./metrics.interface");
|
|
5
|
-
/**
|
|
6
|
-
* Metrics Updater
|
|
7
|
-
*
|
|
8
|
-
* Handles updating metric values
|
|
9
|
-
*/
|
|
10
|
-
class MetricsUpdater {
|
|
11
|
-
/**
|
|
12
|
-
* Increment a counter metric
|
|
13
|
-
*/
|
|
14
|
-
incrementCounter(entry, labels, value = 1) {
|
|
15
|
-
if (entry.type !== metrics_interface_1.MetricType.COUNTER) {
|
|
16
|
-
throw new Error(`Metric is not a counter`);
|
|
17
|
-
}
|
|
18
|
-
const counter = entry.metric;
|
|
19
|
-
if (labels) {
|
|
20
|
-
counter.inc(labels, value);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
counter.inc(value);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Set a gauge metric value
|
|
28
|
-
*/
|
|
29
|
-
setGauge(entry, value, labels) {
|
|
30
|
-
if (entry.type !== metrics_interface_1.MetricType.GAUGE) {
|
|
31
|
-
throw new Error(`Metric is not a gauge`);
|
|
32
|
-
}
|
|
33
|
-
const gauge = entry.metric;
|
|
34
|
-
if (labels) {
|
|
35
|
-
gauge.set(labels, value);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
gauge.set(value);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Increment a gauge metric
|
|
43
|
-
*/
|
|
44
|
-
incrementGauge(entry, labels, value = 1) {
|
|
45
|
-
if (entry.type !== metrics_interface_1.MetricType.GAUGE) {
|
|
46
|
-
throw new Error(`Metric is not a gauge`);
|
|
47
|
-
}
|
|
48
|
-
const gauge = entry.metric;
|
|
49
|
-
if (labels) {
|
|
50
|
-
gauge.inc(labels, value);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
gauge.inc(value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Decrement a gauge metric
|
|
58
|
-
*/
|
|
59
|
-
decrementGauge(entry, labels, value = 1) {
|
|
60
|
-
if (entry.type !== metrics_interface_1.MetricType.GAUGE) {
|
|
61
|
-
throw new Error(`Metric is not a gauge`);
|
|
62
|
-
}
|
|
63
|
-
const gauge = entry.metric;
|
|
64
|
-
if (labels) {
|
|
65
|
-
gauge.dec(labels, value);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
gauge.dec(value);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Observe a histogram metric
|
|
73
|
-
*/
|
|
74
|
-
observeHistogram(entry, value, labels) {
|
|
75
|
-
if (entry.type !== metrics_interface_1.MetricType.HISTOGRAM) {
|
|
76
|
-
throw new Error(`Metric is not a histogram`);
|
|
77
|
-
}
|
|
78
|
-
const histogram = entry.metric;
|
|
79
|
-
if (labels) {
|
|
80
|
-
histogram.observe(labels, value);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
histogram.observe(value);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Observe a summary metric
|
|
88
|
-
*/
|
|
89
|
-
observeSummary(entry, value, labels) {
|
|
90
|
-
if (entry.type !== metrics_interface_1.MetricType.SUMMARY) {
|
|
91
|
-
throw new Error(`Metric is not a summary`);
|
|
92
|
-
}
|
|
93
|
-
const summary = entry.metric;
|
|
94
|
-
if (labels) {
|
|
95
|
-
summary.observe(labels, value);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
summary.observe(value);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.MetricsUpdater = MetricsUpdater;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { MetricsService } from './metrics.service';
|
|
2
|
-
export declare class MetricsController {
|
|
3
|
-
private readonly metricsService;
|
|
4
|
-
constructor(metricsService: MetricsService);
|
|
5
|
-
/**
|
|
6
|
-
* Get all metrics in Prometheus format
|
|
7
|
-
*
|
|
8
|
-
* @returns Metrics in Prometheus exposition format
|
|
9
|
-
*/
|
|
10
|
-
getMetrics(): Promise<string>;
|
|
11
|
-
}
|