From 758ac425ec05328182ef8e81370842c2aa5dedd5 Mon Sep 17 00:00:00 2001 From: Hector Alfaro Date: Wed, 29 Jan 2025 12:51:19 -0500 Subject: [PATCH] Change `/healthz` to `/healthcheck` and remove unused docker compose templates (#54171) --- .../production/deployments/webapp.yaml | 2 +- .../middleware/{healthz.ts => healthcheck.ts} | 2 +- src/frame/middleware/index.ts | 10 +++--- src/redirects/middleware/handle-redirects.ts | 2 +- src/workflows/docker-compose.prod.tmpl.yaml | 33 ------------------- .../docker-compose.staging.tmpl.yaml | 33 ------------------- src/workflows/wait-until-url-is-healthy.ts | 2 +- 7 files changed, 8 insertions(+), 76 deletions(-) rename src/frame/middleware/{healthz.ts => healthcheck.ts} (90%) delete mode 100644 src/workflows/docker-compose.prod.tmpl.yaml delete mode 100644 src/workflows/docker-compose.staging.tmpl.yaml diff --git a/config/kubernetes/production/deployments/webapp.yaml b/config/kubernetes/production/deployments/webapp.yaml index fc0bfb0feb54..a0dac38bf5a6 100644 --- a/config/kubernetes/production/deployments/webapp.yaml +++ b/config/kubernetes/production/deployments/webapp.yaml @@ -53,5 +53,5 @@ spec: httpGet: # WARNING: This should be updated to a meaningful endpoint for your application which will return a 200 once the app is fully started. # See: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes - path: /healthz + path: /healthcheck port: http diff --git a/src/frame/middleware/healthz.ts b/src/frame/middleware/healthcheck.ts similarity index 90% rename from src/frame/middleware/healthz.ts rename to src/frame/middleware/healthcheck.ts index 4a6b5799fd84..e3f8e5b9ff13 100644 --- a/src/frame/middleware/healthz.ts +++ b/src/frame/middleware/healthcheck.ts @@ -9,7 +9,7 @@ const router = express.Router() * instance remains in the pool to handle requests * For example: if we have a failing database connection we may return a 500 status here. */ -router.get('/', function healthz(req, res) { +router.get('/', function healthcheck(req, res) { noCacheControl(res) res.sendStatus(200) diff --git a/src/frame/middleware/index.ts b/src/frame/middleware/index.ts index 518bc14bd9a2..9e2c574f48c4 100644 --- a/src/frame/middleware/index.ts +++ b/src/frame/middleware/index.ts @@ -27,7 +27,7 @@ import findPage from './find-page.js' import blockRobots from './block-robots' import archivedEnterpriseVersionsAssets from '@/archives/middleware/archived-enterprise-versions-assets' import api from './api' -import healthz from './healthz' +import healthcheck from './healthcheck' import manifestJson from './manifest-json' import buildInfo from './build-info' import reqHeaders from './req-headers' @@ -66,16 +66,14 @@ import shielding from '@/shielding/middleware' import tracking from '@/tracking/middleware' import { MAX_REQUEST_TIMEOUT } from '@/frame/lib/constants.js' -const { DEPLOYMENT_ENV, NODE_ENV } = process.env +const { NODE_ENV } = process.env const isTest = NODE_ENV === 'test' || process.env.GITHUB_ACTIONS === 'true' // By default, logging each request (with morgan), is on. And by default // it's off if you're in a production environment or running automated tests. // But if you set the env var, that takes precedence. const ENABLE_DEV_LOGGING = Boolean( - process.env.ENABLE_DEV_LOGGING - ? JSON.parse(process.env.ENABLE_DEV_LOGGING) - : !(DEPLOYMENT_ENV === 'azure' || isTest), + process.env.ENABLE_DEV_LOGGING ? JSON.parse(process.env.ENABLE_DEV_LOGGING) : !isTest, ) const ENABLE_FASTLY_TESTING = JSON.parse(process.env.ENABLE_FASTLY_TESTING || 'false') @@ -120,7 +118,7 @@ export default function (app: Express) { // Put this early to make it as fast as possible because it's used, // and used very often, by the Azure load balancer to check the // health of each node. - app.use('/healthz', healthz) + app.use('/healthcheck', healthcheck) // Must appear before static assets and all other requests // otherwise we won't be able to benefit from that functionality diff --git a/src/redirects/middleware/handle-redirects.ts b/src/redirects/middleware/handle-redirects.ts index a009eb2bda6b..070f5bb42a22 100644 --- a/src/redirects/middleware/handle-redirects.ts +++ b/src/redirects/middleware/handle-redirects.ts @@ -87,7 +87,7 @@ export default function handleRedirects(req: ExtendedRequest, res: Response, nex // the language prefix. // We can't always force on the language prefix because some URLs // aren't pages. They're other middleware endpoints such as - // `/healthz` which should never redirect. + // `/healthcheck` which should never redirect. // But for example, a `/authentication/connecting-to-github-with-ssh` // needs to become `/en/authentication/connecting-to-github-with-ssh` const possibleRedirectTo = `/en${req.path}` diff --git a/src/workflows/docker-compose.prod.tmpl.yaml b/src/workflows/docker-compose.prod.tmpl.yaml deleted file mode 100644 index aa908d22095a..000000000000 --- a/src/workflows/docker-compose.prod.tmpl.yaml +++ /dev/null @@ -1,33 +0,0 @@ -version: '3.7' - -services: - ghdocs-prod: - image: '#{IMAGE}#' - ports: - - '4000:4000' - environment: - NODE_ENV: ${NODE_ENV} - NODE_OPTIONS: ${NODE_OPTIONS} - DD_API_KEY: ${DD_API_KEY} - COOKIE_SECRET: ${COOKIE_SECRET} - HYDRO_ENDPOINT: ${HYDRO_ENDPOINT} - HYDRO_SECRET: ${HYDRO_SECRET} - HAYSTACK_URL: ${HAYSTACK_URL} - HEROKU_APP_NAME: ${HEROKU_APP_NAME} - DEPLOYMENT_ENV: ${DEPLOYMENT_ENV} - HEROKU_PRODUCTION_APP: true - PORT: 4000 - DD_AGENT_HOST: datadog-agent - depends_on: - - datadog-agent - restart: always - - datadog-agent: - image: 'ghdocsprod.azurecr.io/datadog/dogstatsd:latest' - ports: - - '8125:8125' - environment: - DD_API_KEY: ${DD_API_KEY} - DD_AGENT_HOST: datadog-agent - DD_HISTOGRAM_PERCENTILES: 0.99 0.95 0.50 - DD_HOSTNAME_TRUST_UTS_NAMESPACE: true diff --git a/src/workflows/docker-compose.staging.tmpl.yaml b/src/workflows/docker-compose.staging.tmpl.yaml deleted file mode 100644 index 0ca9b2d0fae1..000000000000 --- a/src/workflows/docker-compose.staging.tmpl.yaml +++ /dev/null @@ -1,33 +0,0 @@ -version: '3.7' - -services: - ghdocs-staging: - image: '#{IMAGE}#' - ports: - - '4000:4000' - environment: - NODE_ENV: ${NODE_ENV} - NODE_OPTIONS: ${NODE_OPTIONS} - DD_API_KEY: ${DD_API_KEY} - COOKIE_SECRET: ${COOKIE_SECRET} - HYDRO_ENDPOINT: ${HYDRO_ENDPOINT} - HYDRO_SECRET: ${HYDRO_SECRET} - HAYSTACK_URL: ${HAYSTACK_URL} - HEROKU_APP_NAME: ${HEROKU_APP_NAME} - ENABLED_LANGUAGES: ${ENABLED_LANGUAGES} - DEPLOYMENT_ENV: ${DEPLOYMENT_ENV} - HEROKU_PRODUCTION_APP: true - PORT: 4000 - DD_AGENT_HOST: datadog-agent - depends_on: - - datadog-agent - restart: always - - datadog-agent: - image: datadog/dogstatsd:7.32.4 - ports: - - '8125:8125' - environment: - DD_API_KEY: ${DD_API_KEY} - DD_AGENT_HOST: datadog-agent - DD_HISTOGRAM_PERCENTILES: 0.99 0.95 0.50 diff --git a/src/workflows/wait-until-url-is-healthy.ts b/src/workflows/wait-until-url-is-healthy.ts index 6d3b64374e6d..efed9e05295f 100644 --- a/src/workflows/wait-until-url-is-healthy.ts +++ b/src/workflows/wait-until-url-is-healthy.ts @@ -6,7 +6,7 @@ const DELAY_SECONDS = 15 /* * Promise resolves once url is healthy or fails if timeout has passed - * @param {string} url - health url, e.g. docs.com/healthz + * @param {string} url - health url, e.g. docs.com/healthcheck */ export async function waitUntilUrlIsHealthy(url: string) { try {