From 2626c51a368feaae44e007b3acd9e84528b5d1f3 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Mon, 7 Nov 2022 13:03:38 -0600 Subject: [PATCH 1/5] fix: use backend for `/healthz` page --- coderd/coderd.go | 2 ++ site/src/AppRouter.tsx | 2 -- site/src/pages/HealthzPage/HealthzPage.tsx | 10 ---------- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 site/src/pages/HealthzPage/HealthzPage.tsx diff --git a/coderd/coderd.go b/coderd/coderd.go index ad52edc401cce..d81373638cd2d 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -233,6 +233,8 @@ func New(options *Options) *API { httpmw.CSRF(options.SecureAuthCookie), ) + r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) }) + apps := func(r chi.Router) { r.Use( tracing.Middleware(api.TracerProvider), diff --git a/site/src/AppRouter.tsx b/site/src/AppRouter.tsx index ca9191030c545..11437b855090b 100644 --- a/site/src/AppRouter.tsx +++ b/site/src/AppRouter.tsx @@ -30,7 +30,6 @@ const NotFoundPage = lazy(() => import("./pages/404Page/404Page")) const CliAuthenticationPage = lazy( () => import("./pages/CliAuthPage/CliAuthPage"), ) -const HealthzPage = lazy(() => import("./pages/HealthzPage/HealthzPage")) const AccountPage = lazy( () => import("./pages/UserSettingsPage/AccountPage/AccountPage"), ) @@ -107,7 +106,6 @@ export const AppRouter: FC = () => { } /> } /> - } />
ok
- -export default HealthzPage From 4e69b2eb0cd39662b648354dd2b49a3e9c2adceb Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Mon, 7 Nov 2022 13:16:35 -0600 Subject: [PATCH 2/5] add test --- coderd/coderd_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/coderd/coderd_test.go b/coderd/coderd_test.go index 9fc459fc9e18e..928acff8c4369 100644 --- a/coderd/coderd_test.go +++ b/coderd/coderd_test.go @@ -2,6 +2,7 @@ package coderd_test import ( "context" + "io" "net/http" "net/netip" "strconv" @@ -114,3 +115,16 @@ func TestDERPLatencyCheck(t *testing.T) { defer res.Body.Close() require.Equal(t, http.StatusOK, res.StatusCode) } +func TestHealthz(t *testing.T) { + t.Parallel() + client := coderdtest.New(t, nil) + + res, err := client.Request(context.Background(), "GET", "/healthz", nil) + require.NoError(t, err) + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + require.NoError(t, err) + + assert.Equal(t, "OK", string(body)) +} From 297523d6b76c5bb01a00cf5348f0eacd1ae6176b Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Mon, 7 Nov 2022 13:17:11 -0600 Subject: [PATCH 3/5] fixup! add test --- coderd/coderd_test.go | 1 + site/e2e/pom/HealthzPage.ts | 13 ------------- site/e2e/tests/healthz.spec.ts | 11 ----------- 3 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 site/e2e/pom/HealthzPage.ts delete mode 100644 site/e2e/tests/healthz.spec.ts diff --git a/coderd/coderd_test.go b/coderd/coderd_test.go index 928acff8c4369..5d4cd02949efe 100644 --- a/coderd/coderd_test.go +++ b/coderd/coderd_test.go @@ -123,6 +123,7 @@ func TestHealthz(t *testing.T) { require.NoError(t, err) defer res.Body.Close() + require.Equal(t, http.StatusOK, res.StatusCode) body, err := io.ReadAll(res.Body) require.NoError(t, err) diff --git a/site/e2e/pom/HealthzPage.ts b/site/e2e/pom/HealthzPage.ts deleted file mode 100644 index 7a85ec38fb07b..0000000000000 --- a/site/e2e/pom/HealthzPage.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Locator, Page } from "@playwright/test" -import { BasePom } from "./BasePom" - -export class HealthzPage extends BasePom { - constructor(baseURL: string | undefined, page: Page) { - super(baseURL, "/healthz", page) - } - - getOk(): Locator { - const locator = this.page.locator("text=ok") - return locator - } -} diff --git a/site/e2e/tests/healthz.spec.ts b/site/e2e/tests/healthz.spec.ts deleted file mode 100644 index 8a3c29da65954..0000000000000 --- a/site/e2e/tests/healthz.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { test } from "@playwright/test" -import { HealthzPage } from "../pom/HealthzPage" - -test("Healthz is available without authentication", async ({ - baseURL, - page, -}) => { - const healthzPage = new HealthzPage(baseURL, page) - await page.goto(healthzPage.url, { waitUntil: "networkidle" }) - await healthzPage.getOk().waitFor({ state: "visible" }) -}) From baa8ceb8ce63c77e21d177b0df6bb9d406ee07c6 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Mon, 7 Nov 2022 13:19:16 -0600 Subject: [PATCH 4/5] fixup! add test --- coderd/coderd_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/coderd_test.go b/coderd/coderd_test.go index 5d4cd02949efe..29e6914987f8f 100644 --- a/coderd/coderd_test.go +++ b/coderd/coderd_test.go @@ -119,7 +119,7 @@ func TestHealthz(t *testing.T) { t.Parallel() client := coderdtest.New(t, nil) - res, err := client.Request(context.Background(), "GET", "/healthz", nil) + res, err := client.Request(context.Background(), http.MethodGet, "/healthz", nil) require.NoError(t, err) defer res.Body.Close() From 56fec0c2f9d8541ca05e7f5ba9c81208edc9d585 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Mon, 7 Nov 2022 13:23:22 -0600 Subject: [PATCH 5/5] fixup! add test --- coderd/coderdtest/authorize.go | 1 + 1 file changed, 1 insertion(+) diff --git a/coderd/coderdtest/authorize.go b/coderd/coderdtest/authorize.go index 516b96809a049..e54b3104623ba 100644 --- a/coderd/coderdtest/authorize.go +++ b/coderd/coderdtest/authorize.go @@ -37,6 +37,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) { assertRoute := map[string]RouteCheck{ // These endpoints do not require auth + "GET:/healthz": {NoAuthorize: true}, "GET:/api/v2": {NoAuthorize: true}, "GET:/api/v2/buildinfo": {NoAuthorize: true}, "GET:/api/v2/users/first": {NoAuthorize: true},