From 28db1532b28c6908375ad3536b9dd06480dc261c Mon Sep 17 00:00:00 2001 From: Maris Popens Date: Sat, 26 Sep 2026 22:25:44 +0300 Subject: [PATCH] feat: add /healthz liveness endpoint --- README.md | 1 + main.go | 2 ++ main_test.go | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 246a9dc..7fa9fed 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Everything returns JSON except the track map, which is an SVG image. | `GET /f1/next_map/` | Track map for the next race's circuit. | | `GET /f1/tyre_usage/` | Per-driver compound and stint length for each session of the current weekend that's happened so far (FP1 through Race). Usage only, not allocation - there's no structured source anywhere for a driver's pre-weekend tyre-compound allocation, so this only reports what was actually used once a session's run. Stays on the latest weekend until the next one's first session starts, and keeps finished sessions in memory since OpenF1's free tier locks out all access while any session is live. | | `GET /f1/latest_session/` | Classification of the most recently finished non-race session of the current weekend (practice, sprint qualifying, qualifying or sprint) - best lap for the leader, gap for everyone else. The Grand Prix itself is `/f1/last_race/`. Sourced from OpenF1, so it shares its live-session lockout (finished sessions are kept in memory once fetched). | +| `GET /healthz` | Liveness probe - always `200 {"status":"ok"}` while the process serves HTTP; never calls upstream APIs. | # Development Requires Go 1.26+. diff --git a/main.go b/main.go index 4d08855..d329c7e 100644 --- a/main.go +++ b/main.go @@ -134,6 +134,8 @@ func newServer(a *app) *echo.Echo { e.GET(route.path, route.handler) e.GET(route.path+"/", route.handler) } + // Liveness only - never touches upstream APIs, so an Ergast/OpenF1 outage doesn't restart the pod. + e.GET("/healthz", func(c echo.Context) error { return c.JSON(http.StatusOK, map[string]string{"status": "ok"}) }) return e } diff --git a/main_test.go b/main_test.go index ae8a566..4dcadff 100644 --- a/main_test.go +++ b/main_test.go @@ -106,6 +106,13 @@ func TestDriversContractAndCache(t *testing.T) { } } +func TestHealthz(t *testing.T) { + mock := newUpstreamMock(t) + if result := decode(t, request(t, newServer(testApp(t, mock)), "/healthz")); result["status"] != "ok" || len(mock.hits) != 0 { + t.Fatalf("unexpected response %#v, upstream hits %v", result, mock.hits) + } +} + func TestConstructorsContract(t *testing.T) { mock := newUpstreamMock(t) result := decode(t, request(t, newServer(testApp(t, mock)), "/f1/constructors_standings/"))