UNPKG

@ahmedhegazee/nestjs-telescope

Version:

Advanced observability and monitoring solution for NestJS applications with ML-powered analytics, enterprise features, and production-ready scaling

578 lines 26.9 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Week7AnalyticsController = exports.GenerateReportDto = exports.ExportDataDto = void 0; const common_1 = require("@nestjs/common"); const rxjs_1 = require("rxjs"); const swagger_1 = require("@nestjs/swagger"); const job_watcher_service_1 = require("../../watchers/job/job-watcher.service"); const cache_watcher_service_1 = require("../../watchers/cache/cache-watcher.service"); const analytics_service_1 = require("../../core/services/analytics.service"); const performance_correlation_service_1 = require("../../core/services/performance-correlation.service"); const export_reporting_service_1 = require("../../core/services/export-reporting.service"); class ExportDataDto { } exports.ExportDataDto = ExportDataDto; class GenerateReportDto { } exports.GenerateReportDto = GenerateReportDto; let Week7AnalyticsController = class Week7AnalyticsController { constructor(jobWatcherService, cacheWatcherService, analyticsService, performanceCorrelationService, exportReportingService) { this.jobWatcherService = jobWatcherService; this.cacheWatcherService = cacheWatcherService; this.analyticsService = analyticsService; this.performanceCorrelationService = performanceCorrelationService; this.exportReportingService = exportReportingService; } getJobMetrics() { return this.jobWatcherService.getMetrics(); } getRecentJobs(limit = 50) { return this.jobWatcherService.getRecentJobs(limit); } getJobsByQueue(queueName, limit = 100) { return this.jobWatcherService.getJobsByQueue(queueName, limit); } getQueueHealthByName(queueName) { return this.jobWatcherService.getQueueHealth(queueName); } getQueueHealth() { return this.jobWatcherService.getQueueHealth(); } getJobMetricsStream() { return this.jobWatcherService.getMetricsStream(); } getCacheMetrics() { return this.cacheWatcherService.getMetrics(); } getRecentCacheOperations(limit = 50) { return this.cacheWatcherService.getRecentOperations(limit); } getCacheHealthByInstance(instance) { return this.cacheWatcherService.getCacheHealth(instance); } getCacheHealth() { return this.cacheWatcherService.getCacheHealth(); } getRedisInfoByInstance(instance) { return this.cacheWatcherService.getRedisInfo(instance); } getRedisInfo() { return this.cacheWatcherService.getRedisInfo(); } getRedisHealth() { return this.cacheWatcherService.getRedisHealth(); } async getKeyspaceInfoByInstance(instance) { return this.cacheWatcherService.getKeyspaceInfo(instance); } async getKeyspaceInfo() { return this.cacheWatcherService.getKeyspaceInfo(); } getCacheMetricsStream() { return this.cacheWatcherService.getMetricsStream(); } getAdvancedAnalytics(startDate, endDate) { if (startDate && endDate) { return this.analyticsService.getAnalyticsForTimeRange(new Date(startDate), new Date(endDate)); } return this.analyticsService.getAnalytics(); } getAdvancedAnalyticsStream() { return this.analyticsService.getAnalyticsStream(); } getPerformanceAnalytics() { const analytics = this.analyticsService.getAnalytics(); return analytics.performance; } getErrorAnalytics() { const analytics = this.analyticsService.getAnalytics(); return analytics.errors; } getUserAnalytics() { const analytics = this.analyticsService.getAnalytics(); return analytics.users; } getTrendAnalytics() { const analytics = this.analyticsService.getAnalytics(); return analytics.trends; } getAlertsAndAnomalies() { const analytics = this.analyticsService.getAnalytics(); return analytics.alerts; } getCorrelationMetrics() { return this.performanceCorrelationService.getMetrics(); } getRecentCorrelations(limit = 100) { return this.performanceCorrelationService.getRecentCorrelations(limit); } getCorrelationsByTraceId(traceId) { return this.performanceCorrelationService.getCorrelationsByTraceId(traceId); } getBottlenecksByComponent(component, limit = 50) { return this.performanceCorrelationService.getBottlenecksByComponent(component, limit); } getActiveTraces() { return this.performanceCorrelationService.getActiveTraces(); } getCorrelationStream() { return this.performanceCorrelationService.getCorrelationStream(); } async exportData(exportDto, res) { const options = { ...exportDto, timeRange: exportDto.timeRange ? { start: new Date(exportDto.timeRange.start), end: new Date(exportDto.timeRange.end), } : undefined, }; const result = await this.exportReportingService.exportData(options); if (res && result.success && result.filePath) { const fileName = result.filePath.split('/').pop(); res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`); res.sendFile(result.filePath); return; } return result; } async generateReport(reportDto, res) { const options = { ...reportDto, timeRange: { start: new Date(reportDto.timeRange.start), end: new Date(reportDto.timeRange.end), }, }; const result = await this.exportReportingService.generateReport(options); if (res && result.success && result.filePath) { const fileName = result.filePath.split('/').pop(); res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`); res.sendFile(result.filePath); return; } return result; } getExportHistory() { return this.exportReportingService.getExportHistory(); } getReportTemplates() { return this.exportReportingService.getReportTemplates(); } async getSystemHealthOverview() { const [jobMetrics, cacheMetrics, performanceMetrics, analytics] = await Promise.all([ this.jobWatcherService.getMetrics(), this.cacheWatcherService.getMetrics(), this.performanceCorrelationService.getMetrics(), this.analyticsService.getAnalytics() ]); return { timestamp: new Date(), jobs: { healthScore: jobMetrics.healthScore, healthStatus: jobMetrics.healthStatus, totalJobs: jobMetrics.totalJobs, failureRate: jobMetrics.failureRate, averageExecutionTime: jobMetrics.averageExecutionTime, }, cache: { healthScore: cacheMetrics.healthScore, healthStatus: cacheMetrics.healthStatus, hitRate: cacheMetrics.hitRate, averageResponseTime: cacheMetrics.averageResponseTime, totalOperations: cacheMetrics.totalOperations, }, performance: { averageResponseTime: performanceMetrics.averageResponseTime, p95ResponseTime: performanceMetrics.p95ResponseTime, errorRate: performanceMetrics.errorRate, totalRequests: performanceMetrics.totalRequests, }, system: { totalRequests: analytics.overview.totalRequests, totalErrors: analytics.overview.totalErrors, activeUsers: analytics.overview.activeUsers, throughput: analytics.overview.throughput, }, }; } async getAllActiveAlerts() { const alerts = { jobs: [], cache: [], performance: [], system: [], }; return { timestamp: new Date(), totalAlerts: 0, alerts, }; } acknowledgeAlert(alertId) { const results = { job: this.jobWatcherService.acknowledgeAlert(alertId), cache: this.cacheWatcherService.acknowledgeAlert(alertId), performance: this.performanceCorrelationService.acknowledgeAlert(alertId), }; const acknowledged = Object.values(results).some(result => result === true); return { success: acknowledged, alertId, acknowledgedAt: new Date(), }; } async getDashboardData() { const [jobMetrics, cacheMetrics, analytics, performanceMetrics, correlations] = await Promise.all([ this.jobWatcherService.getMetrics(), this.cacheWatcherService.getMetrics(), this.analyticsService.getAnalytics(), this.performanceCorrelationService.getMetrics(), this.performanceCorrelationService.getRecentCorrelations(20) ]); return { timestamp: new Date(), jobs: { metrics: jobMetrics, recentJobs: this.jobWatcherService.getRecentJobs(10), queueHealth: this.jobWatcherService.getQueueHealth(), }, cache: { metrics: cacheMetrics, recentOperations: this.cacheWatcherService.getRecentOperations(10), health: this.cacheWatcherService.getCacheHealth(), redisHealth: this.cacheWatcherService.getRedisHealth(), }, analytics: { overview: analytics.overview, performance: analytics.performance, trends: analytics.trends, alerts: analytics.alerts, }, correlation: { metrics: performanceMetrics, recentCorrelations: correlations, activeTraces: this.performanceCorrelationService.getActiveTraces(), }, }; } }; exports.Week7AnalyticsController = Week7AnalyticsController; __decorate([ (0, common_1.Get)('jobs/metrics'), (0, swagger_1.ApiOperation)({ summary: 'Get job monitoring metrics' }), (0, swagger_1.ApiResponse)({ status: 200, description: 'Job metrics retrieved successfully' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getJobMetrics", null); __decorate([ (0, common_1.Get)('jobs/recent'), (0, swagger_1.ApiOperation)({ summary: 'Get recent job executions' }), (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }), __param(0, (0, common_1.Query)('limit', new common_1.ParseIntPipe({ optional: true }))), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getRecentJobs", null); __decorate([ (0, common_1.Get)('jobs/queue/:queueName'), (0, swagger_1.ApiOperation)({ summary: 'Get jobs by queue name' }), (0, swagger_1.ApiParam)({ name: 'queueName', description: 'Name of the job queue' }), (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }), __param(0, (0, common_1.Param)('queueName')), __param(1, (0, common_1.Query)('limit', new common_1.ParseIntPipe({ optional: true }))), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Number]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getJobsByQueue", null); __decorate([ (0, common_1.Get)('jobs/health/:queueName'), (0, swagger_1.ApiOperation)({ summary: 'Get queue health status for specific queue' }), (0, swagger_1.ApiParam)({ name: 'queueName', description: 'Specific queue name' }), __param(0, (0, common_1.Param)('queueName')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getQueueHealthByName", null); __decorate([ (0, common_1.Get)('jobs/health'), (0, swagger_1.ApiOperation)({ summary: 'Get health status for all queues' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getQueueHealth", null); __decorate([ (0, common_1.Get)('jobs/stream'), (0, swagger_1.ApiOperation)({ summary: 'Get real-time job metrics stream' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", rxjs_1.Observable) ], Week7AnalyticsController.prototype, "getJobMetricsStream", null); __decorate([ (0, common_1.Get)('cache/metrics'), (0, swagger_1.ApiOperation)({ summary: 'Get cache monitoring metrics' }), (0, swagger_1.ApiResponse)({ status: 200, description: 'Cache metrics retrieved successfully' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getCacheMetrics", null); __decorate([ (0, common_1.Get)('cache/recent'), (0, swagger_1.ApiOperation)({ summary: 'Get recent cache operations' }), (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }), __param(0, (0, common_1.Query)('limit', new common_1.ParseIntPipe({ optional: true }))), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getRecentCacheOperations", null); __decorate([ (0, common_1.Get)('cache/health/:instance'), (0, swagger_1.ApiOperation)({ summary: 'Get specific cache instance health' }), (0, swagger_1.ApiParam)({ name: 'instance', description: 'Cache instance name' }), __param(0, (0, common_1.Param)('instance')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getCacheHealthByInstance", null); __decorate([ (0, common_1.Get)('cache/health'), (0, swagger_1.ApiOperation)({ summary: 'Get health status for all cache instances' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getCacheHealth", null); __decorate([ (0, common_1.Get)('cache/redis/info/:instance'), (0, swagger_1.ApiOperation)({ summary: 'Get specific Redis instance information' }), (0, swagger_1.ApiParam)({ name: 'instance', description: 'Redis instance name' }), __param(0, (0, common_1.Param)('instance')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getRedisInfoByInstance", null); __decorate([ (0, common_1.Get)('cache/redis/info'), (0, swagger_1.ApiOperation)({ summary: 'Get Redis information for all instances' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getRedisInfo", null); __decorate([ (0, common_1.Get)('cache/redis/health'), (0, swagger_1.ApiOperation)({ summary: 'Get Redis health status' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getRedisHealth", null); __decorate([ (0, common_1.Get)('cache/keyspace/:instance'), (0, swagger_1.ApiOperation)({ summary: 'Get Redis keyspace information for specific instance' }), (0, swagger_1.ApiParam)({ name: 'instance', description: 'Redis instance name' }), __param(0, (0, common_1.Param)('instance')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "getKeyspaceInfoByInstance", null); __decorate([ (0, common_1.Get)('cache/keyspace'), (0, swagger_1.ApiOperation)({ summary: 'Get Redis keyspace information for all instances' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "getKeyspaceInfo", null); __decorate([ (0, common_1.Get)('cache/stream'), (0, swagger_1.ApiOperation)({ summary: 'Get real-time cache metrics stream' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", rxjs_1.Observable) ], Week7AnalyticsController.prototype, "getCacheMetricsStream", null); __decorate([ (0, common_1.Get)('advanced'), (0, swagger_1.ApiOperation)({ summary: 'Get comprehensive analytics data' }), (0, swagger_1.ApiQuery)({ name: 'startDate', required: false, type: String }), (0, swagger_1.ApiQuery)({ name: 'endDate', required: false, type: String }), __param(0, (0, common_1.Query)('startDate')), __param(1, (0, common_1.Query)('endDate')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getAdvancedAnalytics", null); __decorate([ (0, common_1.Get)('advanced/stream'), (0, swagger_1.ApiOperation)({ summary: 'Get real-time analytics stream' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", rxjs_1.Observable) ], Week7AnalyticsController.prototype, "getAdvancedAnalyticsStream", null); __decorate([ (0, common_1.Get)('advanced/performance'), (0, swagger_1.ApiOperation)({ summary: 'Get performance analytics' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getPerformanceAnalytics", null); __decorate([ (0, common_1.Get)('advanced/errors'), (0, swagger_1.ApiOperation)({ summary: 'Get error analytics' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getErrorAnalytics", null); __decorate([ (0, common_1.Get)('advanced/users'), (0, swagger_1.ApiOperation)({ summary: 'Get user analytics' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getUserAnalytics", null); __decorate([ (0, common_1.Get)('advanced/trends'), (0, swagger_1.ApiOperation)({ summary: 'Get trend analytics' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getTrendAnalytics", null); __decorate([ (0, common_1.Get)('advanced/alerts'), (0, swagger_1.ApiOperation)({ summary: 'Get active alerts and anomalies' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getAlertsAndAnomalies", null); __decorate([ (0, common_1.Get)('correlation/metrics'), (0, swagger_1.ApiOperation)({ summary: 'Get performance correlation metrics' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getCorrelationMetrics", null); __decorate([ (0, common_1.Get)('correlation/recent'), (0, swagger_1.ApiOperation)({ summary: 'Get recent performance correlations' }), (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }), __param(0, (0, common_1.Query)('limit', new common_1.ParseIntPipe({ optional: true }))), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getRecentCorrelations", null); __decorate([ (0, common_1.Get)('correlation/trace/:traceId'), (0, swagger_1.ApiOperation)({ summary: 'Get correlation data by trace ID' }), (0, swagger_1.ApiParam)({ name: 'traceId', description: 'Trace ID to lookup' }), __param(0, (0, common_1.Param)('traceId')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getCorrelationsByTraceId", null); __decorate([ (0, common_1.Get)('correlation/bottlenecks/:component'), (0, swagger_1.ApiOperation)({ summary: 'Get bottlenecks by component' }), (0, swagger_1.ApiParam)({ name: 'component', description: 'Component name' }), (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }), __param(0, (0, common_1.Param)('component')), __param(1, (0, common_1.Query)('limit', new common_1.ParseIntPipe({ optional: true }))), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Number]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getBottlenecksByComponent", null); __decorate([ (0, common_1.Get)('correlation/active-traces'), (0, swagger_1.ApiOperation)({ summary: 'Get active traces' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getActiveTraces", null); __decorate([ (0, common_1.Get)('correlation/stream'), (0, swagger_1.ApiOperation)({ summary: 'Get real-time correlation stream' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", rxjs_1.Observable) ], Week7AnalyticsController.prototype, "getCorrelationStream", null); __decorate([ (0, common_1.Post)('export/data'), (0, swagger_1.ApiOperation)({ summary: 'Export monitoring data' }), (0, swagger_1.ApiResponse)({ status: 200, description: 'Data exported successfully' }), __param(0, (0, common_1.Body)(common_1.ValidationPipe)), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [ExportDataDto, Object]), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "exportData", null); __decorate([ (0, common_1.Post)('export/report'), (0, swagger_1.ApiOperation)({ summary: 'Generate comprehensive report' }), (0, swagger_1.ApiResponse)({ status: 200, description: 'Report generated successfully' }), __param(0, (0, common_1.Body)(common_1.ValidationPipe)), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [GenerateReportDto, Object]), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "generateReport", null); __decorate([ (0, common_1.Get)('export/history'), (0, swagger_1.ApiOperation)({ summary: 'Get export history' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getExportHistory", null); __decorate([ (0, common_1.Get)('export/templates'), (0, swagger_1.ApiOperation)({ summary: 'Get available report templates' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "getReportTemplates", null); __decorate([ (0, common_1.Get)('health/overview'), (0, swagger_1.ApiOperation)({ summary: 'Get comprehensive system health overview' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "getSystemHealthOverview", null); __decorate([ (0, common_1.Get)('health/alerts'), (0, swagger_1.ApiOperation)({ summary: 'Get all active alerts across all watchers' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "getAllActiveAlerts", null); __decorate([ (0, common_1.Post)('alerts/:alertId/acknowledge'), (0, swagger_1.ApiOperation)({ summary: 'Acknowledge an alert' }), (0, swagger_1.ApiParam)({ name: 'alertId', description: 'Alert ID to acknowledge' }), __param(0, (0, common_1.Param)('alertId')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], Week7AnalyticsController.prototype, "acknowledgeAlert", null); __decorate([ (0, common_1.Get)('dashboard/data'), (0, swagger_1.ApiOperation)({ summary: 'Get comprehensive dashboard data for Week 7 features' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], Week7AnalyticsController.prototype, "getDashboardData", null); exports.Week7AnalyticsController = Week7AnalyticsController = __decorate([ (0, swagger_1.ApiTags)('Week 7 Analytics'), (0, common_1.Controller)('telescope/analytics'), __metadata("design:paramtypes", [job_watcher_service_1.JobWatcherService, cache_watcher_service_1.CacheWatcherService, analytics_service_1.AnalyticsService, performance_correlation_service_1.PerformanceCorrelationService, export_reporting_service_1.ExportReportingService]) ], Week7AnalyticsController); //# sourceMappingURL=analytics.controller.js.map