Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions server/src/controllers/auxiliary.effect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const healthy = (): HealthHttpResponse => ({
ok: true,
status: "ok",
timestamp: 1_784_320_000,
revision: "0123456789abcdef0123456789abcdef01234567",
draining: false,
checks: {
database: {
Expand Down Expand Up @@ -753,6 +754,7 @@ describe("AuxiliaryRouteGroup", () => {
ok: false,
status: "degraded",
timestamp: 1_784_320_001,
revision: "0123456789abcdef0123456789abcdef01234567",
draining: true,
checks: {
database: {
Expand Down
1 change: 1 addition & 0 deletions server/src/controllers/health.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const HealthHttpResponseSchema = Schema.Struct({
ok: Schema.Boolean,
status: Schema.Literals(["ok", "degraded"]),
timestamp: UnixSeconds,
revision: Schema.String,
draining: Schema.Boolean,
checks: Schema.Struct({
database: DatabaseHealth,
Expand Down
8 changes: 6 additions & 2 deletions server/src/controllers/healthCheck.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it } from "bun:test"
import { gitCommitSha } from "@in/server/buildEnv"
import { InlineProtocolClock } from "@in/server/modules/inlineProtocol/clockHealth"
import { combineHealthProbes } from "@in/server/db/connectionPolicy"
import { makeHealthChecker, runHealthChecks, withLifecycleCheck } from "./healthCheck"
Expand Down Expand Up @@ -238,11 +239,14 @@ describe("shared readiness database probe", () => {
checkBroker: () => brokerReady,
})
const lifecycle = { getShutdownState: () => ({ shuttingDown, signal: "SIGTERM" as const, startedAtMs: wall }) }
expect(withLifecycleCheck(await check(), lifecycle).ok).toBe(true)
const ready = withLifecycleCheck(await check(), lifecycle)
expect(ready.ok).toBe(true)
// Monitors compare origins by the serving build's source commit.
expect(ready.revision).toBe(gitCommitSha)
brokerReady = false
shuttingDown = true
const draining = withLifecycleCheck(await check(), lifecycle)
expect(draining).toMatchObject({ draining: true, ok: false, checks: { database: { ok: true }, broker: { ok: false } } })
expect(draining).toMatchObject({ draining: true, ok: false, revision: gitCommitSha, checks: { database: { ok: true }, broker: { ok: false } } })
shuttingDown = false
monotonic = 500
wall += 21_000
Expand Down
5 changes: 5 additions & 0 deletions server/src/controllers/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gitCommitSha } from "@in/server/buildEnv"
import {
checkDatabaseHealth,
} from "@in/server/db"
Expand Down Expand Up @@ -51,6 +52,8 @@ export interface HealthResponse {
}

export interface HealthHttpResponse extends HealthResponse {
/** Source commit of the serving build, so monitors can detect origin version drift. */
readonly revision: string
readonly draining: boolean
readonly checks: HealthResponse["checks"] & {
readonly lifecycle: {
Expand Down Expand Up @@ -299,6 +302,7 @@ export const withLifecycleCheck = (
if (liveness.ok) {
return {
...result,
revision: gitCommitSha,
draining: false,
checks: {
...result.checks,
Expand All @@ -309,6 +313,7 @@ export const withLifecycleCheck = (

return {
...result,
revision: gitCommitSha,
ok: false,
status: "degraded",
draining: true,
Expand Down
Loading