diff --git a/cmd/daemon/serve.go b/cmd/daemon/serve.go index d79457e1c7e9..5cbe2c4d0727 100644 --- a/cmd/daemon/serve.go +++ b/cmd/daemon/serve.go @@ -36,6 +36,7 @@ func servePublic(d driver.Driver, wg *sync.WaitGroup, cmd *cobra.Command, args [ r.StrategyHandler().RegisterPublicRoutes(router) r.SessionHandler().RegisterPublicRoutes(router) r.ErrorHandler().RegisterPublicRoutes(router) + r.HealthHandler().SetRoutes(router.Router, false) n.Use(NewNegroniLoggerMiddleware(l.(*logrus.Logger), "public#"+c.SelfPublicURL().String())) r.WithCSRFHandler(x.NewCSRFHandler( @@ -72,6 +73,7 @@ func serveAdmin(d driver.Driver, wg *sync.WaitGroup, cmd *cobra.Command, args [] router := x.NewRouterAdmin() r.IdentityHandler().RegisterAdminRoutes(router) r.SessionHandler().RegisterAdminRoutes(router) + r.HealthHandler().SetRoutes(router.Router, false) n.Use(NewNegroniLoggerMiddleware(l.(*logrus.Logger), "admin#"+c.SelfAdminURL().String())) telemetry(cmd, n, d) diff --git a/driver/registry.go b/driver/registry.go index 80ee5dea9680..9110cb65ec60 100644 --- a/driver/registry.go +++ b/driver/registry.go @@ -6,6 +6,8 @@ import ( "github.com/justinas/nosurf" "github.com/sirupsen/logrus" + "github.com/ory/x/healthx" + "github.com/ory/herodot" "github.com/ory/hive/selfservice" @@ -65,6 +67,8 @@ type Registry interface { SelfServiceRequestErrorHandler() *selfservice.ErrorHandler LoginRequestManager() selfservice.LoginRequestManager RegistrationRequestManager() selfservice.RegistrationRequestManager + + HealthHandler() *healthx.Handler } func NewRegistry(c configuration.Provider) (Registry, error) { diff --git a/driver/registry_abstract.go b/driver/registry_abstract.go index 9e0c56757aa5..d004af9330ea 100644 --- a/driver/registry_abstract.go +++ b/driver/registry_abstract.go @@ -10,6 +10,8 @@ import ( "github.com/justinas/nosurf" "github.com/sirupsen/logrus" + "github.com/ory/x/healthx" + "github.com/ory/x/tracing" "github.com/ory/x/logrusx" @@ -28,11 +30,12 @@ import ( ) type RegistryAbstract struct { - l logrus.FieldLogger - c configuration.Provider - nosurf *nosurf.CSRFHandler - trc *tracing.Tracer - writer herodot.Writer + l logrus.FieldLogger + c configuration.Provider + nosurf *nosurf.CSRFHandler + trc *tracing.Tracer + writer herodot.Writer + healthxHandler *healthx.Handler identityHandler *identity.Handler identityValidator *identity.Validator @@ -85,6 +88,16 @@ func (m *RegistryAbstract) WithLogger(l logrus.FieldLogger) Registry { return m.r } +func (m *RegistryAbstract) HealthHandler() *healthx.Handler { + if m.healthxHandler == nil { + m.healthxHandler = healthx.NewHandler(m.Writer(), m.BuildVersion(), healthx.ReadyCheckers{ + "database": m.r.Ping, + }) + } + + return m.healthxHandler +} + func (m *RegistryAbstract) WithCSRFHandler(c *nosurf.CSRFHandler) { m.nosurf = c } diff --git a/hive b/hive new file mode 100755 index 000000000000..09b09f81d52d Binary files /dev/null and b/hive differ