From c96373f4d54a2857c67a7cd62da2f5d91c0634d6 Mon Sep 17 00:00:00 2001 From: Alain Nicolas Date: Thu, 5 Dec 2024 19:01:48 +0100 Subject: [PATCH] chore: Update Health Check Endpoints for Liveness and Readiness --- packages/linea-ccip-gateway/package.json | 4 ++-- packages/linea-ccip-gateway/src/server.ts | 24 +++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/linea-ccip-gateway/package.json b/packages/linea-ccip-gateway/package.json index 69762984e..75a582305 100644 --- a/packages/linea-ccip-gateway/package.json +++ b/packages/linea-ccip-gateway/package.json @@ -1,6 +1,6 @@ { "name": "@consensys/linea-ccip-gateway", - "version": "1.0.1", + "version": "1.1.0", "main": "dist/index.js", "author": "Consensys", "license": "Apache-2.0", @@ -53,4 +53,4 @@ "@types/supertest": "^2.0.14", "nyc": "^15.1.0" } -} \ No newline at end of file +} diff --git a/packages/linea-ccip-gateway/src/server.ts b/packages/linea-ccip-gateway/src/server.ts index 6e3f39087..526d9c483 100644 --- a/packages/linea-ccip-gateway/src/server.ts +++ b/packages/linea-ccip-gateway/src/server.ts @@ -28,12 +28,20 @@ try { console.log("Server setup complete."); - // Add a health check page - app.get("/health", async (_req, res, _next) => { - const healthcheck = { + // Liveness probe + app.get("/live", async (_req, res, _next) => { + res.send({ uptime: process.uptime(), message: "OK", timestamp: Date.now(), + }); + }); + + // Readiness probe + app.get("/ready", async (_req, res, _next) => { + const readiness = { + message: "OK", + timestamp: Date.now(), }; try { const host = _req.protocol + "://" + _req.get("host"); @@ -47,15 +55,15 @@ try { } const check = await fetch(urlToCheck); if (check.status != 200) { - healthcheck.message = check.statusText; - logError(healthcheck); + readiness.message = check.statusText; + logError(readiness); res.status(check.status).send(); } else { - res.send(healthcheck); + res.send(readiness); } } catch (error) { - healthcheck.message = error; - logError(error, healthcheck); + readiness.message = error; + logError(error, readiness); res.status(500).send(); } });