Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Use health checks, container logs, and infrastructure metrics to monitor your de
| Service | Endpoint | Returns |
|---|---|---|
| app | `GET /api/health` | `{"status":"ok","timestamp":"..."}` |
| realtime | `GET /health` on port 3002 | `{"status":"ok","timestamp":"...","connections":0}` |
| realtime | `GET /health` on port 3002 | `{"status":"ok"}` |

<Callout type="warn">
`/api/health` is a **liveness** signal only. It returns `200` as long as the process is serving HTTP — it does not check the database, Redis, or object storage. A healthy response does not mean the app can serve traffic successfully, so do not treat it as a dependency check. Verify dependencies with the [smoke test](/platform/self-hosting/verify) instead.
Expand Down
1 change: 0 additions & 1 deletion apps/realtime/src/handlers/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function createRoomManager(overrides?: Partial<IRoomManager>): IRoomManager {
updateRoomLastModified: vi.fn().mockResolvedValue(undefined),
emitToRoom: vi.fn(),
getUniqueUserCount: vi.fn().mockResolvedValue(1),
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
shutdown: vi.fn().mockResolvedValue(undefined),
initialize: vi.fn().mockResolvedValue(undefined),
io: {
Expand Down
1 change: 0 additions & 1 deletion apps/realtime/src/handlers/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function createRoomManager(overrides?: Partial<IRoomManager>): IRoomManager {
updateRoomLastModified: vi.fn().mockResolvedValue(undefined),
emitToRoom: vi.fn(),
getUniqueUserCount: vi.fn().mockResolvedValue(1),
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
shutdown: vi.fn().mockResolvedValue(undefined),
initialize: vi.fn().mockResolvedValue(undefined),
io: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function createRoomManager(overrides?: Partial<IRoomManager>): IRoomManager {
updateRoomLastModified: vi.fn().mockResolvedValue(undefined),
emitToRoom: vi.fn(),
getUniqueUserCount: vi.fn().mockResolvedValue(1),
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
shutdown: vi.fn().mockResolvedValue(undefined),
initialize: vi.fn().mockResolvedValue(undefined),
io: {
Expand Down
5 changes: 0 additions & 5 deletions apps/realtime/src/rooms/redis-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,4 @@ export class RedisRoomManager implements IRoomManager {
const users = await this.getRoomUsers(room)
return new Set(users.map((u) => u.userId)).size
}

async getTotalActiveConnections(): Promise<number> {
// Local instance only; the true cross-pod count would require aggregation.
return this._io.sockets.sockets.size
}
}
3 changes: 0 additions & 3 deletions apps/realtime/src/rooms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,4 @@ export interface IRoomManager {

/** Number of unique users in a room. */
getUniqueUserCount(room: RoomRef): Promise<number>

/** Total active connections tracked by this instance. */
getTotalActiveConnections(): Promise<number>
}
10 changes: 9 additions & 1 deletion apps/realtime/src/routes/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function createMocks(req: Partial<IncomingMessage>) {
const to = vi.fn(() => ({ emit }))
const roomManager = {
io: { to },
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
isReady: vi.fn().mockReturnValue(true),
emitToRoom: vi.fn(),
} as unknown as IRoomManager
Expand Down Expand Up @@ -55,6 +54,15 @@ function requestWithBody(url: string, body: unknown): Partial<IncomingMessage> {
}

describe('createHttpHandler', () => {
it('answers the public health probe with liveness only', async () => {
const { handler, req, res, writeHead, end } = createMocks({ method: 'GET', url: '/health' })

await handler(req, res)

expect(writeHead).toHaveBeenCalledWith(200, { 'Content-Type': 'application/json' })
expect(JSON.parse(end.mock.calls[0][0])).toEqual({ status: 'ok' })
})

it('invalidates the shared generation before notifying every open editor', async () => {
mockInvalidateDocument.mockResolvedValueOnce({ status: 'applied', docId: 'old-document' })
const { handler, req, res, writeHead, to, emit } = createMocks(
Expand Down
19 changes: 3 additions & 16 deletions apps/realtime/src/routes/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,10 @@ export function createHttpHandler(roomManager: IRoomManager, logger: Logger) {
return async (req: IncomingMessage, res: ServerResponse) => {
res.setHeader('X-Robots-Tag', 'noindex, nofollow')

// Health check doesn't require auth
// Unauthenticated and publicly reachable, so it reports liveness only.
if (req.method === 'GET' && req.url === '/health') {
try {
const connections = await roomManager.getTotalActiveConnections()
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(
JSON.stringify({
status: 'ok',
timestamp: new Date().toISOString(),
connections,
})
)
} catch (error) {
logger.error('Error in health check:', error)
res.writeHead(503, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ status: 'error', message: 'Health check failed' }))
}
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ status: 'ok' }))
return
}

Expand Down
Loading