feat(notifications): production-ready WebSocket gateway (TEC-2766)
- Add RedisIoAdapter (shared/infra) for multi-instance Socket.IO fan-out with graceful fallback to the in-memory IoAdapter when Redis is unreachable. - Pin Socket.IO heartbeat (pingInterval/pingTimeout/connectTimeout) via env-tunable gateway options for reconnect stability. - Expose Prometheus metrics on /notifications: goodgo_ws_connected_clients (Gauge) and goodgo_ws_messages_total (Counter) with namespace/event/ direction labels. Wired through MetricsService and tracked across connect/disconnect + emits. - Unit tests: RedisIoAdapter connect/fallback/close, new MetricsService WS helpers, and gateway metric increments/decrements on auth paths. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -8,11 +8,10 @@ import './instrument';
|
||||
|
||||
import { RequestMethod, ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { IoAdapter } from '@nestjs/platform-socket.io';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import helmet from 'helmet';
|
||||
import { LoggerService, validateEnv } from '@modules/shared';
|
||||
import { LoggerService, RedisIoAdapter, validateEnv } from '@modules/shared';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
@@ -60,7 +59,11 @@ async function bootstrap() {
|
||||
});
|
||||
|
||||
// ── WebSocket Adapter (Socket.IO) ──
|
||||
app.useWebSocketAdapter(new IoAdapter(app));
|
||||
// Redis pub/sub fan-out for multi-instance broadcasts; falls back to the
|
||||
// in-memory IoAdapter when Redis is unreachable (single-node / local dev).
|
||||
const wsAdapter = new RedisIoAdapter(app);
|
||||
await wsAdapter.connectToRedis();
|
||||
app.useWebSocketAdapter(wsAdapter);
|
||||
|
||||
// ── Security Headers (Helmet) ──
|
||||
app.use(
|
||||
|
||||
Reference in New Issue
Block a user