Skip to content

Commit

Permalink
feat(faucet,store-indexer): add k8s healthcheck endpoints (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Oct 11, 2023
1 parent 521f826 commit 1d0f7e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-boats-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/faucet": minor
"@latticexyz/store-indexer": minor
---

Added `/healthz` and `/readyz` healthcheck endpoints for Kubernetes
4 changes: 4 additions & 0 deletions packages/faucet/bin/faucet-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const server = fastify({

await server.register(import("@fastify/cors"));

// k8s healthchecks
server.get("/healthz", (req, res) => res.code(200).send());
server.get("/readyz", (req, res) => res.code(200).send());

// @see https://trpc.io/docs/server/adapters/fastify
server.register(fastifyTRPCPlugin<AppRouter>, {
prefix: "/trpc",
Expand Down
6 changes: 6 additions & 0 deletions packages/store-indexer/bin/postgres-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const { latestBlockNumber$, storedBlockLogs$ } = await createStoreSync({

storedBlockLogs$.subscribe();

let isCaughtUp = false;
combineLatest([latestBlockNumber$, storedBlockLogs$])
.pipe(
filter(
Expand All @@ -88,6 +89,7 @@ combineLatest([latestBlockNumber$, storedBlockLogs$])
first()
)
.subscribe(() => {
isCaughtUp = true;
console.log("all caught up");
});

Expand All @@ -98,6 +100,10 @@ const server = fastify({

await server.register(import("@fastify/cors"));

// k8s healthchecks
server.get("/healthz", (req, res) => res.code(200).send());
server.get("/readyz", (req, res) => (isCaughtUp ? res.code(200).send("ready") : res.code(424).send("backfilling")));

// @see https://trpc.io/docs/server/adapters/fastify
server.register(fastifyTRPCPlugin<AppRouter>, {
prefix: "/trpc",
Expand Down
6 changes: 6 additions & 0 deletions packages/store-indexer/bin/sqlite-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const { latestBlockNumber$, storedBlockLogs$ } = await syncToSqlite({
maxBlockRange: env.MAX_BLOCK_RANGE,
});

let isCaughtUp = false;
combineLatest([latestBlockNumber$, storedBlockLogs$])
.pipe(
filter(
Expand All @@ -78,6 +79,7 @@ combineLatest([latestBlockNumber$, storedBlockLogs$])
first()
)
.subscribe(() => {
isCaughtUp = true;
console.log("all caught up");
});

Expand All @@ -88,6 +90,10 @@ const server = fastify({

await server.register(import("@fastify/cors"));

// k8s healthchecks
server.get("/healthz", (req, res) => res.code(200).send());
server.get("/readyz", (req, res) => (isCaughtUp ? res.code(200).send("ready") : res.code(424).send("backfilling")));

// @see https://trpc.io/docs/server/adapters/fastify
server.register(fastifyTRPCPlugin<AppRouter>, {
prefix: "/trpc",
Expand Down

0 comments on commit 1d0f7e2

Please sign in to comment.