From 362e8871371042cbfc90242b4917888ecc2516a5 Mon Sep 17 00:00:00 2001 From: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> Date: Fri, 20 Oct 2023 12:59:53 -0500 Subject: [PATCH] fix: Add routes for intentionally throwing an error to test behavior of sentry Signed-off-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> --- web/mgmt_routes.ts | 35 +++++++++++++++++++++++++++++++++++ web/routes.ts | 33 +-------------------------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/web/mgmt_routes.ts b/web/mgmt_routes.ts index cc69c14..17c3c44 100644 --- a/web/mgmt_routes.ts +++ b/web/mgmt_routes.ts @@ -10,13 +10,17 @@ import { handleSubscriptionEvent, } from "../mgmt/mod.ts"; import { + enqueueMsg, FensakConfigSource, getComputedFensakConfig, getSubscription, + MessageType, mustGetGitHubOrgWithSubscription, + waitForHealthCheckResult, } from "../svcdata/mod.ts"; import type { GitHubOrgWithSubscription } from "../svcdata/mod.ts"; import { isOrgManager } from "../ghstd/mod.ts"; +import { getRandomString } from "../xtd/mod.ts"; interface APIOrganization { slug: string; @@ -38,6 +42,8 @@ export function attachMgmtAPIRoutes(router: Router): void { const corsMW = oakCors({ origin: corsOrigins }); router + .get("/healthz", healthCheck) + .get("/sentry-test", testSentry) .post( "/hooks/mgmt", middlewares.assertMgmtEvent, @@ -59,6 +65,35 @@ export function attachMgmtAPIRoutes(router: Router): void { ); } +async function healthCheck(ctx: Context): Promise { + const requestID = getRandomString(6); + await enqueueMsg({ + type: MessageType.HealthCheck, + payload: { + requestID: requestID, + }, + }); + const result = await waitForHealthCheckResult(requestID); + if (!result) { + ctx.response.status = Status.InternalServerError; + ctx.response.body = { + status: Status.InternalServerError, + msg: "timed out waiting for worker health result", + }; + return; + } + + ctx.response.status = Status.OK; + ctx.response.body = { + status: Status.OK, + msg: "system ok", + }; +} + +function testSentry(_ctx: Context): void { + throw new Error("Test error to ensure sentry is working"); +} + async function handleGetOrganizations(ctx: Context): Promise { const token = ctx.state.apiToken; const octokit = new Octokit({ auth: token }); diff --git a/web/routes.ts b/web/routes.ts index 082fe70..6293c18 100644 --- a/web/routes.ts +++ b/web/routes.ts @@ -5,45 +5,14 @@ import { Context, GitHubWebhookEventName, Router, Status } from "../deps.ts"; import { logger } from "../logging/mod.ts"; import * as middlewares from "../middlewares/mod.ts"; -import { - enqueueMsg, - MessageType, - waitForHealthCheckResult, -} from "../svcdata/mod.ts"; +import { enqueueMsg, MessageType } from "../svcdata/mod.ts"; import { fastRejectEvent } from "../ghevent/mod.ts"; -import { getRandomString } from "../xtd/mod.ts"; export function attachRoutes(router: Router): void { router - .get("/healthz", healthCheck) .post("/hooks/gh", middlewares.assertGitHubWebhook, handleGitHubWebhooks); } -async function healthCheck(ctx: Context): Promise { - const requestID = getRandomString(6); - await enqueueMsg({ - type: MessageType.HealthCheck, - payload: { - requestID: requestID, - }, - }); - const result = await waitForHealthCheckResult(requestID); - if (!result) { - ctx.response.status = Status.InternalServerError; - ctx.response.body = { - status: Status.InternalServerError, - msg: "timed out waiting for worker health result", - }; - return; - } - - ctx.response.status = Status.OK; - ctx.response.body = { - status: Status.OK, - msg: "system ok", - }; -} - async function handleGitHubWebhooks(ctx: Context): Promise { const ghEventName = ctx.request.headers.get("X-GitHub-Event"); if (ghEventName == null) {