Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update Health Check Endpoints for Liveness and Readiness #263

Merged
merged 1 commit into from
Dec 11, 2024
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
4 changes: 2 additions & 2 deletions packages/linea-ccip-gateway/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -53,4 +53,4 @@
"@types/supertest": "^2.0.14",
"nyc": "^15.1.0"
}
}
}
24 changes: 16 additions & 8 deletions packages/linea-ccip-gateway/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
}
});
Expand Down
Loading