-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add detailed healthcheck for dependency statuses (#78)
- Loading branch information
1 parent
7d60355
commit efec2de
Showing
8 changed files
with
105 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import express, { Request, Response } from "express"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { Context, version } from "../app"; | ||
import { registrar } from "../services/registrar"; | ||
import { featuresCache } from "../services/cache"; | ||
|
||
let build: { sha: string; date: string }; | ||
function getBuild() { | ||
if (!build) { | ||
build = { | ||
sha: "", | ||
date: "", | ||
}; | ||
const rootPath = path.join(__dirname, "../..", "buildinfo"); | ||
if (fs.existsSync(path.join(rootPath, "SHA"))) { | ||
build.sha = fs.readFileSync(path.join(rootPath, "SHA")).toString().trim(); | ||
} | ||
if (fs.existsSync(path.join(rootPath, "DATE"))) { | ||
build.date = fs | ||
.readFileSync(path.join(rootPath, "DATE")) | ||
.toString() | ||
.trim(); | ||
} | ||
} | ||
return build; | ||
} | ||
|
||
async function getChecks(ctx: Context) { | ||
const checks: Record<string, any> = { | ||
apiServer: "down", | ||
registrar: registrar.status, | ||
}; | ||
const cacheType = ctx?.cacheSettings?.cacheEngine || "memory"; | ||
checks[`cache:${cacheType}`] = await featuresCache?.getStatus?.() || "pending"; | ||
|
||
try { | ||
const resp = await fetch(ctx.growthbookApiHost + "/healthcheck"); | ||
const data = await resp.json(); | ||
if (data?.healthy) checks.apiServer = "up"; | ||
} catch(e) { | ||
console.error("healthcheck API sever error", e); | ||
} | ||
return checks; | ||
} | ||
|
||
const getHealthCheck = async (req: Request, res: Response) => { | ||
const ctx = req.app.locals?.ctx; | ||
|
||
const build = getBuild(); | ||
const checks = await getChecks(ctx); | ||
res.status(200).json({ | ||
ok: true, | ||
proxyVersion: version, | ||
build, | ||
checks, | ||
}); | ||
}; | ||
|
||
export const healthRouter = express.Router(); | ||
|
||
healthRouter.get("/", getHealthCheck); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters