1
0
forked from wrenn/wrenn

Add unauthenticated /health endpoint to control plane

Returns JSON with status and build version for monitoring and
load balancer health checks.
This commit is contained in:
2026-04-16 16:13:42 +06:00
parent bba5f80294
commit e6e3975426
2 changed files with 10 additions and 2 deletions

View File

@ -28,6 +28,7 @@ var openapiYAML []byte
type Server struct { type Server struct {
router chi.Router router chi.Router
BuildSvc *service.BuildService BuildSvc *service.BuildService
version string
} }
// New constructs the chi router and registers all routes. // New constructs the chi router and registers all routes.
@ -48,6 +49,7 @@ func New(
mailer email.Mailer, mailer email.Mailer,
extensions []cpextension.Extension, extensions []cpextension.Extension,
sctx cpextension.ServerContext, sctx cpextension.ServerContext,
version string,
) *Server { ) *Server {
r := chi.NewRouter() r := chi.NewRouter()
r.Use(requestLogger()) r.Use(requestLogger())
@ -86,6 +88,12 @@ func New(
adminCapsules := newAdminCapsuleHandler(sandboxSvc, queries, pool, al) adminCapsules := newAdminCapsuleHandler(sandboxSvc, queries, pool, al)
meH := newMeHandler(queries, pgPool, rdb, jwtSecret, mailer, oauthRegistry, oauthRedirectURL, teamSvc) meH := newMeHandler(queries, pgPool, rdb, jwtSecret, mailer, oauthRegistry, oauthRedirectURL, teamSvc)
// Health check.
r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"status":"ok","version":%q}`, version)
})
// OpenAPI spec and docs. // OpenAPI spec and docs.
r.Get("/openapi.yaml", serveOpenAPI) r.Get("/openapi.yaml", serveOpenAPI)
r.Get("/docs", serveDocs) r.Get("/docs", serveDocs)
@ -268,7 +276,7 @@ func New(
ext.RegisterRoutes(r, sctx) ext.RegisterRoutes(r, sctx)
} }
return &Server{router: r, BuildSvc: buildSvc} return &Server{router: r, BuildSvc: buildSvc, version: version}
} }
// Handler returns the HTTP handler. // Handler returns the HTTP handler.

View File

@ -175,7 +175,7 @@ func Run(opts ...Option) {
} }
// API server. // API server.
srv := api.New(queries, hostPool, hostScheduler, pool, rdb, []byte(cfg.JWTSecret), oauthRegistry, cfg.OAuthRedirectURL, ca, al, channelSvc, mailer, o.extensions, sctx) srv := api.New(queries, hostPool, hostScheduler, pool, rdb, []byte(cfg.JWTSecret), oauthRegistry, cfg.OAuthRedirectURL, ca, al, channelSvc, mailer, o.extensions, sctx, o.version)
// Start template build workers (2 concurrent). // Start template build workers (2 concurrent).
stopBuildWorkers := srv.BuildSvc.StartWorkers(ctx, 2) stopBuildWorkers := srv.BuildSvc.StartWorkers(ctx, 2)