Skip to content

Commit

Permalink
Add trace_id to health check
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Oct 4, 2023
1 parent a10bfff commit 006f255
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Bun.serve<{key: string}>({
if ( req.method == "GET" ) {
const { pathname } = new URL(req.url);
if ( pathname === "/") return new Response(banner())
if ( pathname === "/health") return toJSON(await checkHealth(true));
if ( pathname === "/health") return await checkHealth();
if ( pathname === "/metrics") return new Response(await prometheus.registry.metrics());
if ( pathname === "/moduleHash") return toJSON(sqlite.selectAll(db, "moduleHash"));
if ( pathname === "/traceId") return toJSON(sqlite.selectAll(db, "traceId"));
Expand Down
12 changes: 7 additions & 5 deletions src/health.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export async function checkHealth(internalData: boolean) {
if (internalData == true){
return {data: "OK", status: { status: 200 }};
}
return {data: "Error: No connected webhooks", status: { status: 400 }};
import { toText } from "./http.js";
import { getSingleMetric } from "./prometheus.js";

export async function checkHealth() {
if (await getSingleMetric("trace_id") > 0 ) {
return new Response("OK");
}
return toText("Error: No connected webhooks", 400);
};

0 comments on commit 006f255

Please sign in to comment.