2019-12-04 17:15:11 +01:00
|
|
|
package debug
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
2025-07-23 21:56:26 +02:00
|
|
|
"net/url"
|
2019-12-04 17:15:11 +01:00
|
|
|
|
2024-10-16 20:26:00 +02:00
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/checks"
|
2024-09-24 16:10:56 +02:00
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
2022-05-04 14:49:59 +02:00
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
2019-12-04 17:15:11 +01:00
|
|
|
)
|
|
|
|
|
|
2019-12-06 13:14:21 +01:00
|
|
|
// Server initializes the debug service and server.
|
2019-12-04 17:15:11 +01:00
|
|
|
func Server(opts ...Option) (*http.Server, error) {
|
|
|
|
|
options := newOptions(opts...)
|
|
|
|
|
|
2024-10-17 16:13:18 +02:00
|
|
|
healthHandlerConfiguration := handlers.NewCheckHandlerConfiguration().
|
|
|
|
|
WithLogger(options.Logger).
|
|
|
|
|
WithCheck("web reachability", checks.NewHTTPCheck(options.Config.HTTP.Addr))
|
|
|
|
|
|
2025-07-23 21:56:26 +02:00
|
|
|
u, err := url.Parse(options.Config.Identity.LDAP.URI)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 16:13:18 +02:00
|
|
|
readyHandlerConfiguration := healthHandlerConfiguration.
|
2024-10-18 17:30:39 +02:00
|
|
|
WithCheck("nats reachability", checks.NewNatsCheck(options.Config.Events.Endpoint)).
|
2025-07-23 21:56:26 +02:00
|
|
|
WithCheck("ldap reachability", checks.NewTCPCheck(u.Host))
|
2024-09-25 11:45:12 +02:00
|
|
|
|
2019-12-06 13:14:21 +01:00
|
|
|
return debug.NewService(
|
|
|
|
|
debug.Logger(options.Logger),
|
2022-01-03 11:10:33 +01:00
|
|
|
debug.Name(options.Config.Service.Name),
|
2022-06-13 10:41:14 +02:00
|
|
|
debug.Version(version.GetString()),
|
2019-12-06 13:14:21 +01:00
|
|
|
debug.Address(options.Config.Debug.Addr),
|
|
|
|
|
debug.Token(options.Config.Debug.Token),
|
|
|
|
|
debug.Pprof(options.Config.Debug.Pprof),
|
|
|
|
|
debug.Zpages(options.Config.Debug.Zpages),
|
2024-10-17 16:13:18 +02:00
|
|
|
debug.Health(handlers.NewCheckHandler(healthHandlerConfiguration)),
|
|
|
|
|
debug.Ready(handlers.NewCheckHandler(readyHandlerConfiguration)),
|
2019-12-06 13:14:21 +01:00
|
|
|
), nil
|
|
|
|
|
}
|