handle /ws_debug/health in debugger and add request logging (#8426)
- Fix debugger HTTP health endpoint to also match /ws_debug/health (ingress forwards the full path, not just /health) - Add request logging to all three extra services (LSP, multiplayer, debugger) for HTTP and WebSocket ping/upgrade events Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1069,11 +1069,14 @@ const server = Bun.serve({
|
|||||||
|
|
||||||
// Handle WebSocket upgrade with path-based routing
|
// Handle WebSocket upgrade with path-based routing
|
||||||
if (server.upgrade(req, { data: { path } })) {
|
if (server.upgrade(req, { data: { path } })) {
|
||||||
|
logger.info(`WS upgrade: ${path}`)
|
||||||
return undefined as unknown as Response
|
return undefined as unknown as Response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(`HTTP ${req.method} ${path}`)
|
||||||
|
|
||||||
// Health check endpoint
|
// Health check endpoint
|
||||||
if (path === '/health') {
|
if (path === '/health' || path === '/ws_debug/health') {
|
||||||
return new Response(JSON.stringify({
|
return new Response(JSON.stringify({
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
service: 'debugger',
|
service: 'debugger',
|
||||||
@@ -1102,6 +1105,7 @@ const server = Bun.serve({
|
|||||||
|
|
||||||
// Handle ping test — respond and close immediately
|
// Handle ping test — respond and close immediately
|
||||||
if (path === '/ping') {
|
if (path === '/ping') {
|
||||||
|
logger.info(`WS ping test`)
|
||||||
ws.send(JSON.stringify({ type: 'pong', service: 'debugger' }))
|
ws.send(JSON.stringify({ type: 'pong', service: 'debugger' }))
|
||||||
ws.close()
|
ws.close()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ class HealthHandler(web.RequestHandler):
|
|||||||
self.set_header("Content-Type", "application/json")
|
self.set_header("Content-Type", "application/json")
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
log.info("HTTP GET %s", self.request.uri)
|
||||||
self.write(json.dumps({"status": "ok", "service": "lsp"}))
|
self.write(json.dumps({"status": "ok", "service": "lsp"}))
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
@@ -104,6 +105,7 @@ class HealthHandler(web.RequestHandler):
|
|||||||
|
|
||||||
class PingHandler(websocket.WebSocketHandler):
|
class PingHandler(websocket.WebSocketHandler):
|
||||||
def open(self):
|
def open(self):
|
||||||
|
log.info("WS ping from %s", self.request.remote_ip)
|
||||||
self.write_message(json.dumps({"type": "pong", "service": "lsp"}))
|
self.write_message(json.dumps({"type": "pong", "service": "lsp"}))
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ const setupWSConnection = (conn, req, docName) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
|
console.log(`[${new Date().toISOString()}] HTTP ${req.method} ${req.url} from=${req.socket.remoteAddress}`)
|
||||||
if (req.url === '/' || req.url === '/health' || req.url === '/ws_mp/health') {
|
if (req.url === '/' || req.url === '/health' || req.url === '/ws_mp/health') {
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -144,15 +145,16 @@ wss.on('connection', (ws, req) => {
|
|||||||
docName = docName.slice('ws_mp/'.length)
|
docName = docName.slice('ws_mp/'.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clientIp = req.socket.remoteAddress
|
||||||
|
|
||||||
// Handle ping test — respond and close immediately
|
// Handle ping test — respond and close immediately
|
||||||
if (docName === '__ping__') {
|
if (docName === '__ping__') {
|
||||||
|
console.log(`[${new Date().toISOString()}] WS ping from=${clientIp}`)
|
||||||
ws.send(JSON.stringify({ type: 'pong', service: 'multiplayer' }))
|
ws.send(JSON.stringify({ type: 'pong', service: 'multiplayer' }))
|
||||||
ws.close()
|
ws.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientIp = req.socket.remoteAddress
|
|
||||||
|
|
||||||
console.log(`[${new Date().toISOString()}] CONNECT: doc="${docName}" from=${clientIp}`)
|
console.log(`[${new Date().toISOString()}] CONNECT: doc="${docName}" from=${clientIp}`)
|
||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user