@nest-omni/core 3.1.2-6 → 3.1.2-8
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/common/dto/dto-extensions.js +6 -5
- package/common/utils.d.ts +1 -0
- package/common/utils.js +6 -0
- package/http-client/config/http-client.config.d.ts +6 -0
- package/http-client/config/http-client.config.js +87 -0
- package/http-client/config/index.d.ts +1 -0
- package/http-client/config/index.js +17 -0
- package/http-client/decorators/http-client.decorators.d.ts +72 -0
- package/http-client/decorators/http-client.decorators.js +204 -0
- package/http-client/decorators/index.d.ts +1 -0
- package/http-client/decorators/index.js +17 -0
- package/http-client/entities/http-log.entity.d.ts +98 -0
- package/http-client/entities/http-log.entity.js +143 -0
- package/http-client/entities/index.d.ts +1 -0
- package/http-client/entities/index.js +17 -0
- package/http-client/errors/http-client.errors.d.ts +56 -0
- package/http-client/errors/http-client.errors.js +149 -0
- package/http-client/errors/index.d.ts +1 -0
- package/http-client/errors/index.js +17 -0
- package/http-client/examples/advanced-usage.example.d.ts +23 -0
- package/http-client/examples/advanced-usage.example.js +319 -0
- package/http-client/examples/basic-usage.example.d.ts +61 -0
- package/http-client/examples/basic-usage.example.js +171 -0
- package/http-client/examples/index.d.ts +3 -0
- package/http-client/examples/index.js +19 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +98 -0
- package/http-client/examples/multi-api-configuration.example.js +353 -0
- package/http-client/http-client.module.d.ts +11 -0
- package/http-client/http-client.module.js +254 -0
- package/http-client/index.d.ts +10 -0
- package/http-client/index.js +27 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +152 -0
- package/http-client/interfaces/api-client-config.interface.js +12 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +123 -0
- package/http-client/interfaces/http-client-config.interface.js +2 -0
- package/http-client/services/api-client-registry.service.d.ts +40 -0
- package/http-client/services/api-client-registry.service.js +411 -0
- package/http-client/services/cache.service.d.ts +24 -0
- package/http-client/services/cache.service.js +264 -0
- package/http-client/services/circuit-breaker.service.d.ts +33 -0
- package/http-client/services/circuit-breaker.service.js +180 -0
- package/http-client/services/http-client.service.d.ts +43 -0
- package/http-client/services/http-client.service.js +384 -0
- package/http-client/services/http-log-query.service.d.ts +56 -0
- package/http-client/services/http-log-query.service.js +414 -0
- package/http-client/services/index.d.ts +7 -0
- package/http-client/services/index.js +23 -0
- package/http-client/services/log-cleanup.service.d.ts +64 -0
- package/http-client/services/log-cleanup.service.js +268 -0
- package/http-client/services/logging.service.d.ts +36 -0
- package/http-client/services/logging.service.js +445 -0
- package/http-client/utils/call-stack-extractor.util.d.ts +29 -0
- package/http-client/utils/call-stack-extractor.util.js +138 -0
- package/http-client/utils/context-extractor.util.d.ts +44 -0
- package/http-client/utils/context-extractor.util.js +173 -0
- package/http-client/utils/curl-generator.util.d.ts +9 -0
- package/http-client/utils/curl-generator.util.js +169 -0
- package/http-client/utils/index.d.ts +4 -0
- package/http-client/utils/index.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +30 -0
- package/http-client/utils/retry-recorder.util.js +143 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,414 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var HttpLogQueryService_1;
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.HttpLogQueryService = void 0;
|
|
23
|
+
const common_1 = require("@nestjs/common");
|
|
24
|
+
const typeorm_1 = require("typeorm");
|
|
25
|
+
const http_log_entity_1 = require("../entities/http-log.entity");
|
|
26
|
+
let HttpLogQueryService = HttpLogQueryService_1 = class HttpLogQueryService {
|
|
27
|
+
constructor(dataSource) {
|
|
28
|
+
this.dataSource = dataSource;
|
|
29
|
+
this.logger = new common_1.Logger(HttpLogQueryService_1.name);
|
|
30
|
+
this.logRepository = null;
|
|
31
|
+
this.initializeRepository();
|
|
32
|
+
}
|
|
33
|
+
findLogs() {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
35
|
+
if (!this.logRepository) {
|
|
36
|
+
throw new Error('HTTP log repository not available');
|
|
37
|
+
}
|
|
38
|
+
const { page = 1, limit = 50, sortBy = 'createdAt', sortOrder = 'DESC', includeDetails = false, } = options;
|
|
39
|
+
const queryBuilder = this.buildQuery(options, includeDetails);
|
|
40
|
+
const offset = (page - 1) * limit;
|
|
41
|
+
queryBuilder.skip(offset).take(limit);
|
|
42
|
+
queryBuilder.orderBy(`log.${sortBy}`, sortOrder);
|
|
43
|
+
const [logs, total] = yield queryBuilder.getManyAndCount();
|
|
44
|
+
return {
|
|
45
|
+
logs,
|
|
46
|
+
total,
|
|
47
|
+
page,
|
|
48
|
+
limit,
|
|
49
|
+
totalPages: Math.ceil(total / limit),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
findLogById(id_1) {
|
|
54
|
+
return __awaiter(this, arguments, void 0, function* (id, includeDetails = false) {
|
|
55
|
+
if (!this.logRepository) {
|
|
56
|
+
throw new Error('HTTP log repository not available');
|
|
57
|
+
}
|
|
58
|
+
const queryBuilder = this.logRepository.createQueryBuilder('log');
|
|
59
|
+
if (includeDetails) {
|
|
60
|
+
queryBuilder.leftJoinAndSelect('log.retryRecords', 'retryRecords');
|
|
61
|
+
}
|
|
62
|
+
return queryBuilder.where('log.id = :id', { id }).getOne();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
findLogByRequestId(requestId) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
if (!this.logRepository) {
|
|
68
|
+
throw new Error('HTTP log repository not available');
|
|
69
|
+
}
|
|
70
|
+
return this.logRepository.findOne({
|
|
71
|
+
where: { requestId },
|
|
72
|
+
order: { createdAt: 'DESC' },
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
findErrorLogs() {
|
|
77
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
78
|
+
const queryOptions = Object.assign(Object.assign({}, options), { success: false });
|
|
79
|
+
return this.findLogs(queryOptions);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
findSlowRequests() {
|
|
83
|
+
return __awaiter(this, arguments, void 0, function* (minResponseTime = 5000, options = {}) {
|
|
84
|
+
if (!this.logRepository) {
|
|
85
|
+
throw new Error('HTTP log repository not available');
|
|
86
|
+
}
|
|
87
|
+
const { page = 1, limit = 50 } = options;
|
|
88
|
+
const offset = (page - 1) * limit;
|
|
89
|
+
const [logs, total] = yield this.logRepository
|
|
90
|
+
.createQueryBuilder('log')
|
|
91
|
+
.where('log.responseTime >= :minResponseTime', { minResponseTime })
|
|
92
|
+
.orderBy('log.responseTime', 'DESC')
|
|
93
|
+
.skip(offset)
|
|
94
|
+
.take(limit)
|
|
95
|
+
.getManyAndCount();
|
|
96
|
+
return { logs, total };
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
findRetryLogs() {
|
|
100
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
101
|
+
if (!this.logRepository) {
|
|
102
|
+
throw new Error('HTTP log repository not available');
|
|
103
|
+
}
|
|
104
|
+
const { minRetries = 1, page = 1, limit = 50 } = options;
|
|
105
|
+
const offset = (page - 1) * limit;
|
|
106
|
+
const queryBuilder = this.logRepository
|
|
107
|
+
.createQueryBuilder('log')
|
|
108
|
+
.where('log.attemptCount > :minRetries', { minRetries: minRetries - 1 })
|
|
109
|
+
.orderBy('log.attemptCount', 'DESC')
|
|
110
|
+
.addOrderBy('log.createdAt', 'DESC')
|
|
111
|
+
.skip(offset)
|
|
112
|
+
.take(limit);
|
|
113
|
+
const [logs, total] = yield queryBuilder.getManyAndCount();
|
|
114
|
+
return { logs, total };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getStats() {
|
|
118
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
119
|
+
if (!this.logRepository) {
|
|
120
|
+
throw new Error('HTTP log repository not available');
|
|
121
|
+
}
|
|
122
|
+
const { startDate, endDate, userId, serviceName } = options;
|
|
123
|
+
const baseQuery = this.logRepository.createQueryBuilder('log');
|
|
124
|
+
if (startDate) {
|
|
125
|
+
baseQuery.andWhere('log.createdAt >= :startDate', { startDate });
|
|
126
|
+
}
|
|
127
|
+
if (endDate) {
|
|
128
|
+
baseQuery.andWhere('log.createdAt <= :endDate', { endDate });
|
|
129
|
+
}
|
|
130
|
+
if (userId) {
|
|
131
|
+
baseQuery.andWhere('log.userId = :userId', { userId });
|
|
132
|
+
}
|
|
133
|
+
if (serviceName) {
|
|
134
|
+
baseQuery.andWhere('log.serviceName = :serviceName', { serviceName });
|
|
135
|
+
}
|
|
136
|
+
const [total, successful, failed] = yield Promise.all([
|
|
137
|
+
baseQuery.getCount(),
|
|
138
|
+
baseQuery
|
|
139
|
+
.clone()
|
|
140
|
+
.andWhere('log.success = :success', { success: true })
|
|
141
|
+
.getCount(),
|
|
142
|
+
baseQuery
|
|
143
|
+
.clone()
|
|
144
|
+
.andWhere('log.success = :success', { success: false })
|
|
145
|
+
.getCount(),
|
|
146
|
+
]);
|
|
147
|
+
const responseTimeStats = yield baseQuery
|
|
148
|
+
.select('AVG(log.responseTime)', 'avg')
|
|
149
|
+
.addSelect('MIN(log.responseTime)', 'min')
|
|
150
|
+
.addSelect('MAX(log.responseTime)', 'max')
|
|
151
|
+
.getRawOne();
|
|
152
|
+
const httpMethodStats = yield baseQuery
|
|
153
|
+
.select('log.method', 'method')
|
|
154
|
+
.addSelect('COUNT(*)', 'count')
|
|
155
|
+
.groupBy('log.method')
|
|
156
|
+
.getRawMany();
|
|
157
|
+
const statusStats = yield baseQuery
|
|
158
|
+
.select('log.statusCode', 'statusCode')
|
|
159
|
+
.addSelect('COUNT(*)', 'count')
|
|
160
|
+
.groupBy('log.statusCode')
|
|
161
|
+
.getRawMany();
|
|
162
|
+
const serviceStats = yield baseQuery
|
|
163
|
+
.select('log.serviceName', 'serviceName')
|
|
164
|
+
.addSelect('COUNT(*)', 'count')
|
|
165
|
+
.groupBy('log.serviceName')
|
|
166
|
+
.getRawMany();
|
|
167
|
+
const operationStats = yield baseQuery
|
|
168
|
+
.select('log.operationName', 'operationName')
|
|
169
|
+
.addSelect('COUNT(*)', 'count')
|
|
170
|
+
.groupBy('log.operationName')
|
|
171
|
+
.getRawMany();
|
|
172
|
+
const sourceStats = yield baseQuery
|
|
173
|
+
.select('log.source', 'source')
|
|
174
|
+
.addSelect('COUNT(*)', 'count')
|
|
175
|
+
.groupBy('log.source')
|
|
176
|
+
.getRawMany();
|
|
177
|
+
const errorStats = yield baseQuery
|
|
178
|
+
.clone()
|
|
179
|
+
.where('log.success = :success', { success: false })
|
|
180
|
+
.select('log.errorCode', 'errorCode')
|
|
181
|
+
.addSelect('COUNT(*)', 'count')
|
|
182
|
+
.groupBy('log.errorCode')
|
|
183
|
+
.getRawMany();
|
|
184
|
+
const retryStats = yield baseQuery
|
|
185
|
+
.select('AVG(log.attemptCount)', 'avgAttempts')
|
|
186
|
+
.addSelect('MAX(log.attemptCount)', 'maxAttempts')
|
|
187
|
+
.addSelect('SUM(log.attemptCount - 1)', 'totalRetries')
|
|
188
|
+
.addSelect('COUNT(*)', 'totalRequests')
|
|
189
|
+
.getRawOne();
|
|
190
|
+
const cacheStats = yield baseQuery
|
|
191
|
+
.select('SUM(CASE WHEN log.cacheHit = true THEN 1 ELSE 0 END)', 'cacheHits')
|
|
192
|
+
.addSelect('SUM(CASE WHEN log.cacheHit = false OR log.cacheHit IS NULL THEN 1 ELSE 0 END)', 'cacheMisses')
|
|
193
|
+
.addSelect('COUNT(*)', 'total')
|
|
194
|
+
.getRawOne();
|
|
195
|
+
const percentiles = yield this.calculatePercentiles(baseQuery);
|
|
196
|
+
return {
|
|
197
|
+
totalRequests: total,
|
|
198
|
+
successfulRequests: successful,
|
|
199
|
+
failedRequests: failed,
|
|
200
|
+
successRate: total > 0 ? (successful / total) * 100 : 0,
|
|
201
|
+
averageResponseTime: (responseTimeStats === null || responseTimeStats === void 0 ? void 0 : responseTimeStats.avg) || 0,
|
|
202
|
+
minResponseTime: (responseTimeStats === null || responseTimeStats === void 0 ? void 0 : responseTimeStats.min) || 0,
|
|
203
|
+
maxResponseTime: (responseTimeStats === null || responseTimeStats === void 0 ? void 0 : responseTimeStats.max) || 0,
|
|
204
|
+
p50ResponseTime: percentiles.p50,
|
|
205
|
+
p95ResponseTime: percentiles.p95,
|
|
206
|
+
p99ResponseTime: percentiles.p99,
|
|
207
|
+
requestsByMethod: this.formatStats(httpMethodStats, 'method', 'count'),
|
|
208
|
+
requestsByStatus: this.formatStats(statusStats, 'statusCode', 'count'),
|
|
209
|
+
requestsByService: this.formatStats(serviceStats, 'serviceName', 'count'),
|
|
210
|
+
requestsBySource: this.formatStats(sourceStats, 'source', 'count'),
|
|
211
|
+
errorsByCode: this.formatStats(errorStats, 'errorCode', 'count'),
|
|
212
|
+
retryStats: {
|
|
213
|
+
totalRetries: (retryStats === null || retryStats === void 0 ? void 0 : retryStats.totalRetries) || 0,
|
|
214
|
+
averageRetries: (retryStats === null || retryStats === void 0 ? void 0 : retryStats.avgAttempts)
|
|
215
|
+
? parseFloat(retryStats.avgAttempts) - 1
|
|
216
|
+
: 0,
|
|
217
|
+
maxRetries: (retryStats === null || retryStats === void 0 ? void 0 : retryStats.maxAttempts)
|
|
218
|
+
? parseInt(retryStats.maxAttempts) - 1
|
|
219
|
+
: 0,
|
|
220
|
+
retryRate: total > 0 ? (((retryStats === null || retryStats === void 0 ? void 0 : retryStats.totalRetries) || 0) / total) * 100 : 0,
|
|
221
|
+
},
|
|
222
|
+
cacheStats: {
|
|
223
|
+
cacheHits: (cacheStats === null || cacheStats === void 0 ? void 0 : cacheStats.cacheHits) || 0,
|
|
224
|
+
cacheMisses: (cacheStats === null || cacheStats === void 0 ? void 0 : cacheStats.cacheMisses) || 0,
|
|
225
|
+
cacheHitRate: (cacheStats === null || cacheStats === void 0 ? void 0 : cacheStats.total) > 0
|
|
226
|
+
? (((cacheStats === null || cacheStats === void 0 ? void 0 : cacheStats.cacheHits) || 0) / cacheStats.total) * 100
|
|
227
|
+
: 0,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
deleteOldLogs() {
|
|
233
|
+
return __awaiter(this, arguments, void 0, function* (daysToKeep = 30) {
|
|
234
|
+
if (!this.logRepository) {
|
|
235
|
+
throw new Error('HTTP log repository not available');
|
|
236
|
+
}
|
|
237
|
+
const cutoffDate = new Date();
|
|
238
|
+
cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
|
|
239
|
+
const result = yield this.logRepository
|
|
240
|
+
.createQueryBuilder()
|
|
241
|
+
.delete()
|
|
242
|
+
.where('createdAt < :cutoffDate', { cutoffDate })
|
|
243
|
+
.execute();
|
|
244
|
+
this.logger.log(`Deleted ${result.affected} old HTTP logs (older than ${daysToKeep} days)`);
|
|
245
|
+
return result.affected || 0;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
clearAllLogs() {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
if (!this.logRepository) {
|
|
251
|
+
throw new Error('HTTP log repository not available');
|
|
252
|
+
}
|
|
253
|
+
yield this.logRepository.clear();
|
|
254
|
+
this.logger.warn('Cleared all HTTP logs');
|
|
255
|
+
return 0;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
initializeRepository() {
|
|
259
|
+
if (this.dataSource) {
|
|
260
|
+
try {
|
|
261
|
+
this.logRepository = this.dataSource.getRepository(http_log_entity_1.HttpLogEntity);
|
|
262
|
+
this.logger.log('HTTP log repository initialized');
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
this.logger.error('Failed to initialize HTTP log repository', error);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
calculatePercentiles(queryBuilder) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
try {
|
|
272
|
+
const results = yield queryBuilder
|
|
273
|
+
.select('log.responseTime', 'responseTime')
|
|
274
|
+
.where('log.responseTime IS NOT NULL')
|
|
275
|
+
.orderBy('log.responseTime', 'ASC')
|
|
276
|
+
.getRawMany();
|
|
277
|
+
if (results.length === 0) {
|
|
278
|
+
return { p50: 0, p95: 0, p99: 0 };
|
|
279
|
+
}
|
|
280
|
+
const responseTimes = results
|
|
281
|
+
.map((r) => r.responseTime)
|
|
282
|
+
.sort((a, b) => a - b);
|
|
283
|
+
const total = responseTimes.length;
|
|
284
|
+
const getPercentile = (p) => {
|
|
285
|
+
const index = Math.ceil((p / 100) * total) - 1;
|
|
286
|
+
return responseTimes[Math.max(0, index)];
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
p50: getPercentile(50),
|
|
290
|
+
p95: getPercentile(95),
|
|
291
|
+
p99: getPercentile(99),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
this.logger.warn('Failed to calculate percentiles', error);
|
|
296
|
+
return { p50: 0, p95: 0, p99: 0 };
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
formatStats(stats, keyField, valueField) {
|
|
301
|
+
return stats.reduce((acc, item) => {
|
|
302
|
+
const key = item[keyField] || 'unknown';
|
|
303
|
+
const value = parseInt(item[valueField]) || 0;
|
|
304
|
+
acc[key] = value;
|
|
305
|
+
return acc;
|
|
306
|
+
}, {});
|
|
307
|
+
}
|
|
308
|
+
buildQuery(options, includeDetails = false) {
|
|
309
|
+
if (!this.logRepository) {
|
|
310
|
+
throw new Error('HTTP log repository not available');
|
|
311
|
+
}
|
|
312
|
+
const queryBuilder = this.logRepository.createQueryBuilder('log');
|
|
313
|
+
if (includeDetails) {
|
|
314
|
+
queryBuilder.leftJoinAndSelect('log.retryRecords', 'retryRecords');
|
|
315
|
+
}
|
|
316
|
+
if (options.requestId) {
|
|
317
|
+
queryBuilder.andWhere('log.requestId = :requestId', {
|
|
318
|
+
requestId: options.requestId,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
if (options.userId) {
|
|
322
|
+
queryBuilder.andWhere('log.userId = :userId', { userId: options.userId });
|
|
323
|
+
}
|
|
324
|
+
if (options.method) {
|
|
325
|
+
if (Array.isArray(options.method)) {
|
|
326
|
+
queryBuilder.andWhere('log.method IN (:...methods)', {
|
|
327
|
+
methods: options.method,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
queryBuilder.andWhere('log.method = :method', {
|
|
332
|
+
method: options.method,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (options.url) {
|
|
337
|
+
queryBuilder.andWhere('log.url LIKE :url', { url: `%${options.url}%` });
|
|
338
|
+
}
|
|
339
|
+
if (options.statusCode) {
|
|
340
|
+
if (Array.isArray(options.statusCode)) {
|
|
341
|
+
queryBuilder.andWhere('log.statusCode IN (:...statusCodes)', {
|
|
342
|
+
statusCodes: options.statusCode,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
queryBuilder.andWhere('log.statusCode = :statusCode', {
|
|
347
|
+
statusCode: options.statusCode,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (options.success !== undefined) {
|
|
352
|
+
queryBuilder.andWhere('log.success = :success', {
|
|
353
|
+
success: options.success,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (options.serviceName) {
|
|
357
|
+
queryBuilder.andWhere('log.serviceName = :serviceName', {
|
|
358
|
+
serviceName: options.serviceName,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if (options.operationName) {
|
|
362
|
+
queryBuilder.andWhere('log.operationName = :operationName', {
|
|
363
|
+
operationName: options.operationName,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (options.clientIp) {
|
|
367
|
+
queryBuilder.andWhere('log.clientIp = :clientIp', {
|
|
368
|
+
clientIp: options.clientIp,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (options.source) {
|
|
372
|
+
queryBuilder.andWhere('log.source = :source', { source: options.source });
|
|
373
|
+
}
|
|
374
|
+
if (options.tags && options.tags.length > 0) {
|
|
375
|
+
queryBuilder.andWhere('JSON_CONTAINS(log.tags, :tags)', {
|
|
376
|
+
tags: JSON.stringify(options.tags),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
if (options.errorCode) {
|
|
380
|
+
queryBuilder.andWhere('log.errorCode = :errorCode', {
|
|
381
|
+
errorCode: options.errorCode,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if (options.minResponseTime) {
|
|
385
|
+
queryBuilder.andWhere('log.responseTime >= :minResponseTime', {
|
|
386
|
+
minResponseTime: options.minResponseTime,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
if (options.maxResponseTime) {
|
|
390
|
+
queryBuilder.andWhere('log.responseTime <= :maxResponseTime', {
|
|
391
|
+
maxResponseTime: options.maxResponseTime,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (options.startDate) {
|
|
395
|
+
queryBuilder.andWhere('log.createdAt >= :startDate', {
|
|
396
|
+
startDate: options.startDate,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
if (options.endDate) {
|
|
400
|
+
queryBuilder.andWhere('log.createdAt <= :endDate', {
|
|
401
|
+
endDate: options.endDate,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (options.keyword) {
|
|
405
|
+
queryBuilder.andWhere('(log.url LIKE :keyword OR log.errorMessage LIKE :keyword OR log.body LIKE :keyword)', { keyword: `%${options.keyword}%` });
|
|
406
|
+
}
|
|
407
|
+
return queryBuilder;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
exports.HttpLogQueryService = HttpLogQueryService;
|
|
411
|
+
exports.HttpLogQueryService = HttpLogQueryService = HttpLogQueryService_1 = __decorate([
|
|
412
|
+
(0, common_1.Injectable)(),
|
|
413
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
414
|
+
], HttpLogQueryService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './http-client.service';
|
|
2
|
+
export * from './circuit-breaker.service';
|
|
3
|
+
export * from './logging.service';
|
|
4
|
+
export * from './cache.service';
|
|
5
|
+
export * from './http-log-query.service';
|
|
6
|
+
export * from './log-cleanup.service';
|
|
7
|
+
export * from './api-client-registry.service';
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./http-client.service"), exports);
|
|
18
|
+
__exportStar(require("./circuit-breaker.service"), exports);
|
|
19
|
+
__exportStar(require("./logging.service"), exports);
|
|
20
|
+
__exportStar(require("./cache.service"), exports);
|
|
21
|
+
__exportStar(require("./http-log-query.service"), exports);
|
|
22
|
+
__exportStar(require("./log-cleanup.service"), exports);
|
|
23
|
+
__exportStar(require("./api-client-registry.service"), exports);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { CronExpression } from '@nestjs/schedule';
|
|
3
|
+
import { HttpLogQueryService } from './http-log-query.service';
|
|
4
|
+
export interface LogCleanupConfig {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
strategy: 'retention' | 'size' | 'combination';
|
|
7
|
+
retentionDays: number;
|
|
8
|
+
maxRecords?: number;
|
|
9
|
+
schedule?: CronExpression;
|
|
10
|
+
batchSize?: number;
|
|
11
|
+
preserveErrorLogs?: boolean;
|
|
12
|
+
errorLogRetentionDays?: number;
|
|
13
|
+
preserveImportantLogs?: boolean;
|
|
14
|
+
importantLogRetentionDays?: number;
|
|
15
|
+
preserveSlowRequests?: boolean;
|
|
16
|
+
slowRequestRetentionDays?: number;
|
|
17
|
+
slowRequestThreshold?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface CleanupStats {
|
|
20
|
+
cleanupTime: Date;
|
|
21
|
+
strategy: string;
|
|
22
|
+
beforeCount: number;
|
|
23
|
+
afterCount: number;
|
|
24
|
+
deletedCount: number;
|
|
25
|
+
batchCount: number;
|
|
26
|
+
duration: number;
|
|
27
|
+
errors: string[];
|
|
28
|
+
}
|
|
29
|
+
export declare class HttpLogCleanupService implements OnModuleInit {
|
|
30
|
+
private readonly logQueryService;
|
|
31
|
+
private readonly logger;
|
|
32
|
+
private readonly defaultConfig;
|
|
33
|
+
constructor(logQueryService: HttpLogQueryService, config?: Partial<LogCleanupConfig>);
|
|
34
|
+
private get cleanupConfig();
|
|
35
|
+
onModuleInit(): void;
|
|
36
|
+
scheduledCleanup(): Promise<CleanupStats>;
|
|
37
|
+
manualCleanup(options?: Partial<LogCleanupConfig>): Promise<CleanupStats>;
|
|
38
|
+
getConfig(): LogCleanupConfig;
|
|
39
|
+
updateConfig(config: Partial<LogCleanupConfig>): void;
|
|
40
|
+
getCleanupStatus(): Promise<{
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
config: LogCleanupConfig;
|
|
43
|
+
currentStats: any;
|
|
44
|
+
recommendations: string[];
|
|
45
|
+
}>;
|
|
46
|
+
previewCleanup(config?: Partial<LogCleanupConfig>): Promise<{
|
|
47
|
+
strategy: string;
|
|
48
|
+
currentRecords: number;
|
|
49
|
+
estimatedDeletion: number;
|
|
50
|
+
estimatedAfterCount: number;
|
|
51
|
+
cutoffDate: Date;
|
|
52
|
+
breakdown: {
|
|
53
|
+
normalLogs: number;
|
|
54
|
+
errorLogs: number;
|
|
55
|
+
slowRequests: number;
|
|
56
|
+
importantLogs: number;
|
|
57
|
+
};
|
|
58
|
+
}>;
|
|
59
|
+
private performCleanup;
|
|
60
|
+
private cleanupByRetention;
|
|
61
|
+
private cleanupBySize;
|
|
62
|
+
private cleanupByCombination;
|
|
63
|
+
private createCleanupStats;
|
|
64
|
+
}
|