From c82a7c560eca405067b854f063c15c4c4c35d547 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Tue, 24 Sep 2024 16:10:56 +0200 Subject: [PATCH 01/16] enhancement: use global ready and health handlers --- services/activitylog/pkg/command/server.go | 6 +-- .../app-provider/pkg/server/debug/server.go | 39 ++---------------- .../app-registry/pkg/server/debug/server.go | 39 ++---------------- services/auth-app/pkg/server/debug/server.go | 39 ++---------------- .../auth-basic/pkg/server/debug/server.go | 39 ++---------------- .../auth-bearer/pkg/server/debug/server.go | 39 ++---------------- .../auth-machine/pkg/server/debug/server.go | 39 ++---------------- .../auth-service/pkg/server/debug/server.go | 39 ++---------------- .../collaboration/pkg/server/debug/server.go | 39 ++---------------- services/frontend/pkg/server/debug/server.go | 39 ++---------------- services/gateway/pkg/server/debug/server.go | 39 ++---------------- services/graph/pkg/server/debug/server.go | 39 ++---------------- services/groups/pkg/server/debug/server.go | 39 ++---------------- services/idm/pkg/server/debug/server.go | 39 ++---------------- services/idp/pkg/server/debug/server.go | 20 +-------- .../invitations/pkg/server/debug/server.go | 39 ++---------------- services/ocdav/pkg/server/debug/server.go | 39 ++---------------- services/ocm/pkg/server/debug/server.go | 39 ++---------------- services/ocs/pkg/server/debug/server.go | 39 ++---------------- services/policies/pkg/command/server.go | 36 +++------------- services/proxy/pkg/server/debug/server.go | 41 +++---------------- services/search/pkg/server/debug/server.go | 39 ++---------------- services/settings/pkg/server/debug/server.go | 39 ++---------------- services/sharing/pkg/server/debug/server.go | 39 ++---------------- .../pkg/server/debug/server.go | 39 ++---------------- .../storage-shares/pkg/server/debug/server.go | 39 ++---------------- .../storage-system/pkg/server/debug/server.go | 39 ++---------------- .../storage-users/pkg/server/debug/server.go | 39 ++---------------- .../thumbnails/pkg/server/debug/server.go | 39 ++---------------- services/users/pkg/server/debug/server.go | 39 ++---------------- services/web/pkg/server/debug/server.go | 39 ++---------------- services/webdav/pkg/server/debug/server.go | 39 ++---------------- services/webfinger/pkg/server/debug/server.go | 39 ++---------------- 33 files changed, 102 insertions(+), 1132 deletions(-) diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index 96601df47eb..af4300a0e8d 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -9,6 +9,9 @@ import ( "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/v2/pkg/store" "github.com/oklog/run" + "github.com/urfave/cli/v2" + microstore "go-micro.dev/v4/store" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -23,8 +26,6 @@ import ( "github.com/owncloud/ocis/v2/services/activitylog/pkg/logging" "github.com/owncloud/ocis/v2/services/activitylog/pkg/metrics" "github.com/owncloud/ocis/v2/services/activitylog/pkg/server/http" - "github.com/urfave/cli/v2" - microstore "go-micro.dev/v4/store" ) var _registeredEvents = []events.Unmarshaller{ @@ -120,7 +121,6 @@ func Server(cfg *config.Config) *cli.Command { http.Context(ctx), // NOTE: not passing this "option" leads to a panic in go-micro http.TraceProvider(tracerProvider), http.Stream(evStream), - http.RegisteredEvents(_registeredEvents), http.Store(evStore), http.GatewaySelector(gatewaySelector), http.HistoryClient(hClient), diff --git a/services/app-provider/pkg/server/debug/server.go b/services/app-provider/pkg/server/debug/server.go index 598a8e2f5ea..5686ae12648 100644 --- a/services/app-provider/pkg/server/debug/server.go +++ b/services/app-provider/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/app-provider/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/app-registry/pkg/server/debug/server.go b/services/app-registry/pkg/server/debug/server.go index e85c77274f9..5686ae12648 100644 --- a/services/app-registry/pkg/server/debug/server.go +++ b/services/app-registry/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/app-registry/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/auth-app/pkg/server/debug/server.go b/services/auth-app/pkg/server/debug/server.go index b87b7e52f11..5686ae12648 100644 --- a/services/auth-app/pkg/server/debug/server.go +++ b/services/auth-app/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/auth-app/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/auth-basic/pkg/server/debug/server.go b/services/auth-basic/pkg/server/debug/server.go index 18b2b02df9b..5686ae12648 100644 --- a/services/auth-basic/pkg/server/debug/server.go +++ b/services/auth-basic/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/auth-basic/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/auth-bearer/pkg/server/debug/server.go b/services/auth-bearer/pkg/server/debug/server.go index fb65e4e169e..5686ae12648 100644 --- a/services/auth-bearer/pkg/server/debug/server.go +++ b/services/auth-bearer/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/auth-bearer/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/auth-machine/pkg/server/debug/server.go b/services/auth-machine/pkg/server/debug/server.go index 4f7323733a5..5686ae12648 100644 --- a/services/auth-machine/pkg/server/debug/server.go +++ b/services/auth-machine/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/auth-machine/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/auth-service/pkg/server/debug/server.go b/services/auth-service/pkg/server/debug/server.go index d4616cb0f6e..5686ae12648 100644 --- a/services/auth-service/pkg/server/debug/server.go +++ b/services/auth-service/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/auth-service/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/collaboration/pkg/server/debug/server.go b/services/collaboration/pkg/server/debug/server.go index 89de713708b..83e1ed1eaa5 100644 --- a/services/collaboration/pkg/server/debug/server.go +++ b/services/collaboration/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/frontend/pkg/server/debug/server.go b/services/frontend/pkg/server/debug/server.go index 4c813dc4fe6..5686ae12648 100644 --- a/services/frontend/pkg/server/debug/server.go +++ b/services/frontend/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/frontend/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/gateway/pkg/server/debug/server.go b/services/gateway/pkg/server/debug/server.go index 18ad6b6f40b..5686ae12648 100644 --- a/services/gateway/pkg/server/debug/server.go +++ b/services/gateway/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/gateway/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/graph/pkg/server/debug/server.go b/services/graph/pkg/server/debug/server.go index 314ef1b783d..3f715977207 100644 --- a/services/graph/pkg/server/debug/server.go +++ b/services/graph/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/graph/pkg/config" ) // Server initializes the debug service and server. @@ -21,39 +20,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/groups/pkg/server/debug/server.go b/services/groups/pkg/server/debug/server.go index bf0fe346a0f..5686ae12648 100644 --- a/services/groups/pkg/server/debug/server.go +++ b/services/groups/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/groups/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/idm/pkg/server/debug/server.go b/services/idm/pkg/server/debug/server.go index 9ac1972d456..3f715977207 100644 --- a/services/idm/pkg/server/debug/server.go +++ b/services/idm/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/idm/pkg/config" ) // Server initializes the debug service and server. @@ -21,39 +20,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/idp/pkg/server/debug/server.go b/services/idp/pkg/server/debug/server.go index f236bc69af4..25d175bee85 100644 --- a/services/idp/pkg/server/debug/server.go +++ b/services/idp/pkg/server/debug/server.go @@ -5,6 +5,7 @@ import ( "net/http" "net/url" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/shared" @@ -25,7 +26,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), debug.Health(health(options.Config, options.Logger)), - debug.Ready(ready(options.Config)), + debug.Ready(handlers.Ready), ), nil } @@ -51,20 +52,3 @@ func health(cfg *config.Config, l log.Logger) func(http.ResponseWriter, *http.Re } } } - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - // if we can call this function, a http(200) is a valid response as - // there is nothing we can check at this point for IDP - // if there is a mishap when initializing, there is a minimal (talking ms or ns window) - // timeframe where this code is callable - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/invitations/pkg/server/debug/server.go b/services/invitations/pkg/server/debug/server.go index 663e3c45d3d..4b8e4a29551 100644 --- a/services/invitations/pkg/server/debug/server.go +++ b/services/invitations/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/invitations/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/ocdav/pkg/server/debug/server.go b/services/ocdav/pkg/server/debug/server.go index 5216000a7ac..5686ae12648 100644 --- a/services/ocdav/pkg/server/debug/server.go +++ b/services/ocdav/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/ocdav/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/ocm/pkg/server/debug/server.go b/services/ocm/pkg/server/debug/server.go index d97b3fde109..5686ae12648 100644 --- a/services/ocm/pkg/server/debug/server.go +++ b/services/ocm/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/ocm/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/ocs/pkg/server/debug/server.go b/services/ocs/pkg/server/debug/server.go index 536c972458e..4b8e4a29551 100644 --- a/services/ocs/pkg/server/debug/server.go +++ b/services/ocs/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/ocs/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 5719335ae21..6118381ada0 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -3,12 +3,13 @@ package command import ( "context" "fmt" - "io" - "net/http" "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" @@ -20,7 +21,6 @@ import ( "github.com/owncloud/ocis/v2/services/policies/pkg/engine/opa" svcEvent "github.com/owncloud/ocis/v2/services/policies/pkg/service/event" svcGRPC "github.com/owncloud/ocis/v2/services/policies/pkg/service/grpc" - "github.com/urfave/cli/v2" ) // Server is the entrypoint for the server command. @@ -129,34 +129,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health( - func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - }, - ), - debug.Ready( - func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - }, - ), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/proxy/pkg/server/debug/server.go b/services/proxy/pkg/server/debug/server.go index ae2a3349b0f..04d0330485c 100644 --- a/services/proxy/pkg/server/debug/server.go +++ b/services/proxy/pkg/server/debug/server.go @@ -2,10 +2,11 @@ package debug import ( "encoding/json" - "io" "net/http" - masker "github.com/ggwhite/go-masker" + "github.com/ggwhite/go-masker" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" @@ -23,44 +24,12 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.ConfigDump(configDump(options.Config)), ), nil } -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - // configDump implements the config dump func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { diff --git a/services/search/pkg/server/debug/server.go b/services/search/pkg/server/debug/server.go index e1ac53041da..3f715977207 100644 --- a/services/search/pkg/server/debug/server.go +++ b/services/search/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/search/pkg/config" ) // Server initializes the debug service and server. @@ -21,39 +20,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/settings/pkg/server/debug/server.go b/services/settings/pkg/server/debug/server.go index 8b667f094fd..4b8e4a29551 100644 --- a/services/settings/pkg/server/debug/server.go +++ b/services/settings/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/settings/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/sharing/pkg/server/debug/server.go b/services/sharing/pkg/server/debug/server.go index 818cf6012b8..5686ae12648 100644 --- a/services/sharing/pkg/server/debug/server.go +++ b/services/sharing/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/sharing/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/storage-publiclink/pkg/server/debug/server.go b/services/storage-publiclink/pkg/server/debug/server.go index 4cf599ceddf..5686ae12648 100644 --- a/services/storage-publiclink/pkg/server/debug/server.go +++ b/services/storage-publiclink/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/storage-shares/pkg/server/debug/server.go b/services/storage-shares/pkg/server/debug/server.go index 2f301be8be9..5686ae12648 100644 --- a/services/storage-shares/pkg/server/debug/server.go +++ b/services/storage-shares/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/storage-system/pkg/server/debug/server.go b/services/storage-system/pkg/server/debug/server.go index b5bc0977b3c..5686ae12648 100644 --- a/services/storage-system/pkg/server/debug/server.go +++ b/services/storage-system/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/storage-system/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/storage-users/pkg/server/debug/server.go b/services/storage-users/pkg/server/debug/server.go index 268324919cd..8c5ce23fbc3 100644 --- a/services/storage-users/pkg/server/debug/server.go +++ b/services/storage-users/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/storage-users/pkg/config" ) // Server initializes the debug service and server. @@ -22,43 +21,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/thumbnails/pkg/server/debug/server.go b/services/thumbnails/pkg/server/debug/server.go index 914167fac8c..4b8e4a29551 100644 --- a/services/thumbnails/pkg/server/debug/server.go +++ b/services/thumbnails/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/users/pkg/server/debug/server.go b/services/users/pkg/server/debug/server.go index b10bacdc204..5686ae12648 100644 --- a/services/users/pkg/server/debug/server.go +++ b/services/users/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/users/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), //debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/web/pkg/server/debug/server.go b/services/web/pkg/server/debug/server.go index 0ffe3259c0a..3f715977207 100644 --- a/services/web/pkg/server/debug/server.go +++ b/services/web/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/web/pkg/config" ) // Server initializes the debug service and server. @@ -21,39 +20,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), ), nil } - -// health implements the health check. -func health(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/webdav/pkg/server/debug/server.go b/services/webdav/pkg/server/debug/server.go index 8c4bd1c6c35..4b8e4a29551 100644 --- a/services/webdav/pkg/server/debug/server.go +++ b/services/webdav/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/webdav/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} diff --git a/services/webfinger/pkg/server/debug/server.go b/services/webfinger/pkg/server/debug/server.go index 2701befb13f..4b8e4a29551 100644 --- a/services/webfinger/pkg/server/debug/server.go +++ b/services/webfinger/pkg/server/debug/server.go @@ -1,12 +1,11 @@ package debug import ( - "io" "net/http" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/webfinger/pkg/config" ) // Server initializes the debug service and server. @@ -21,43 +20,11 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config)), - debug.Ready(ready(options.Config)), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials), ), nil } - -// health implements the health check. -func health(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} - -// ready implements the ready check. -func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } - } -} From 067103947471f56d62ccab8b6b70758743ddfc24 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Wed, 25 Sep 2024 11:45:12 +0200 Subject: [PATCH 02/16] enhancement: add readyz and healthz check handler --- ocis-pkg/handlers/checker.go | 129 ++++++++++++++++++ ocis-pkg/handlers/checker_test.go | 29 ++++ ocis-pkg/handlers/debughandlers.go | 34 ----- ocis-pkg/service/debug/option.go | 12 +- ocis-pkg/service/debug/service.go | 16 ++- ocis-pkg/shared/healthchecklist.go | 29 ---- services/activitylog/pkg/command/server.go | 9 +- services/antivirus/pkg/command/server.go | 12 +- .../app-provider/pkg/server/debug/server.go | 9 +- .../app-registry/pkg/server/debug/server.go | 9 +- services/audit/pkg/command/server.go | 12 +- services/auth-app/pkg/server/debug/server.go | 9 +- .../auth-basic/pkg/server/debug/server.go | 9 +- .../auth-bearer/pkg/server/debug/server.go | 9 +- .../auth-machine/pkg/server/debug/server.go | 9 +- .../auth-service/pkg/server/debug/server.go | 9 +- services/clientlog/pkg/command/server.go | 12 +- .../collaboration/pkg/server/debug/server.go | 9 +- services/eventhistory/pkg/command/server.go | 14 +- services/frontend/pkg/server/debug/server.go | 9 +- services/gateway/pkg/server/debug/server.go | 9 +- services/graph/pkg/server/debug/server.go | 9 +- services/groups/pkg/server/debug/server.go | 9 +- services/idm/pkg/command/server.go | 12 +- services/idm/pkg/server/debug/server.go | 9 +- services/idp/pkg/server/debug/server.go | 49 +++---- .../invitations/pkg/server/debug/server.go | 9 +- services/nats/pkg/command/server.go | 12 +- services/notifications/pkg/command/server.go | 10 +- services/ocdav/pkg/server/debug/server.go | 9 +- services/ocm/pkg/server/debug/server.go | 9 +- services/ocs/pkg/server/debug/server.go | 9 +- services/policies/pkg/command/server.go | 9 +- services/postprocessing/pkg/command/server.go | 14 +- services/proxy/pkg/server/debug/server.go | 12 +- services/search/pkg/server/debug/server.go | 9 +- services/settings/pkg/server/debug/server.go | 9 +- services/sharing/pkg/server/debug/server.go | 9 +- services/sse/pkg/command/server.go | 9 +- .../pkg/server/debug/server.go | 9 +- .../storage-shares/pkg/server/debug/server.go | 9 +- .../storage-system/pkg/server/debug/server.go | 9 +- .../storage-users/pkg/server/debug/server.go | 9 +- .../thumbnails/pkg/server/debug/server.go | 9 +- services/userlog/pkg/command/server.go | 14 +- services/users/pkg/server/debug/server.go | 9 +- services/web/pkg/server/debug/server.go | 9 +- services/webdav/pkg/server/debug/server.go | 9 +- services/webfinger/pkg/server/debug/server.go | 9 +- 49 files changed, 511 insertions(+), 199 deletions(-) create mode 100644 ocis-pkg/handlers/checker.go create mode 100644 ocis-pkg/handlers/checker_test.go delete mode 100644 ocis-pkg/handlers/debughandlers.go delete mode 100644 ocis-pkg/shared/healthchecklist.go diff --git a/ocis-pkg/handlers/checker.go b/ocis-pkg/handlers/checker.go new file mode 100644 index 00000000000..29df6177e37 --- /dev/null +++ b/ocis-pkg/handlers/checker.go @@ -0,0 +1,129 @@ +package handlers + +import ( + "context" + "fmt" + "io" + "maps" + "net" + "net/http" + + "golang.org/x/sync/errgroup" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" +) + +// check is a function that performs a check. +type check func(ctx context.Context) error + +// CheckHandlerConfiguration defines the configuration for the CheckHandler. +type CheckHandlerConfiguration struct { + logger log.Logger + checks map[string]check + limit int + statusFailed int + statusSuccess int +} + +// NewCheckHandlerConfiguration initializes a new CheckHandlerConfiguration. +func NewCheckHandlerConfiguration() CheckHandlerConfiguration { + return CheckHandlerConfiguration{ + checks: make(map[string]check), + limit: -1, + statusFailed: http.StatusInternalServerError, + statusSuccess: http.StatusOK, + } +} + +// WithLogger sets the logger for the CheckHandlerConfiguration. +func (c CheckHandlerConfiguration) WithLogger(l log.Logger) CheckHandlerConfiguration { + c.logger = l + return c +} + +// WithCheck sets a check for the CheckHandlerConfiguration. +func (c CheckHandlerConfiguration) WithCheck(name string, f check) CheckHandlerConfiguration { + if _, ok := c.checks[name]; ok { + c.logger.Panic().Str("check", name).Msg("check already exists") + } + + c.checks[name] = f + return c +} + +// WithLimit limits the number of active goroutines for the checks to at most n +func (c CheckHandlerConfiguration) WithLimit(n int) CheckHandlerConfiguration { + c.limit = n + return c +} + +// WithStatusFailed sets the status code for the failed checks. +func (c CheckHandlerConfiguration) WithStatusFailed(status int) CheckHandlerConfiguration { + c.statusFailed = status + return c +} + +// WithStatusSuccess sets the status code for the successful checks. +func (c CheckHandlerConfiguration) WithStatusSuccess(status int) CheckHandlerConfiguration { + c.statusSuccess = status + return c +} + +// CheckHandler is a http Handler that performs different checks. +type CheckHandler struct { + conf CheckHandlerConfiguration +} + +// NewCheckHandler initializes a new CheckHandler. +func NewCheckHandler(c CheckHandlerConfiguration) *CheckHandler { + c.checks = maps.Clone(c.checks) // prevent check duplication after initialization + return &CheckHandler{ + conf: c, + } +} + +// AddCheck adds a check to the CheckHandler. +func (h *CheckHandler) AddCheck(name string, c check) { + h.conf.WithCheck(name, c) +} + +func (h *CheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + g, ctx := errgroup.WithContext(r.Context()) + g.SetLimit(h.conf.limit) + + for name, check := range h.conf.checks { + g.Go(func() error { + if err := check(ctx); err != nil { // since go 1.22 for loops have a per-iteration scope instead of per-loop scope, no need to pin the check... + return fmt.Errorf("'%s': %w", name, err) + } + + return nil + }) + } + + status := h.conf.statusSuccess + if err := g.Wait(); err != nil { + status = h.conf.statusFailed + h.conf.logger.Error().Err(err).Msg("check failed") + } + + w.Header().Set("Content-Type", "text/plain") // fixMe: should be application/json!?! + w.WriteHeader(status) + + if _, err := io.WriteString(w, http.StatusText(status)); err != nil { // io.WriteString should not fail, but if it does, we want to know. + h.conf.logger.Panic().Err(err).Msg("failed to write response") + } +} + +// NewTCPCheck returns a check that connects to a given tcp endpoint. +func NewTCPCheck(address string) func(ctx context.Context) error { + return func(ctx context.Context) error { + conn, err := net.Dial("tcp", address) + if err != nil { + return err + } + defer conn.Close() + + return nil + } +} diff --git a/ocis-pkg/handlers/checker_test.go b/ocis-pkg/handlers/checker_test.go new file mode 100644 index 00000000000..0c5cadb28d6 --- /dev/null +++ b/ocis-pkg/handlers/checker_test.go @@ -0,0 +1,29 @@ +package handlers_test + +import ( + "context" + "fmt" + "testing" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" +) + +func TestCheckHandler_AddCheck(t *testing.T) { + c := handlers.NewCheckHandlerConfiguration().WithCheck("shared-check", func(ctx context.Context) error { return nil }) + + t.Run("configured checks are unique once added", func(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Errorf("checks should be unique, got %v", r) + } + }() + + h1 := handlers.NewCheckHandler(c) + h1.AddCheck("check-with-same-name", func(ctx context.Context) error { return nil }) + + h2 := handlers.NewCheckHandler(c) + h2.AddCheck("check-with-same-name", func(ctx context.Context) error { return nil }) + + fmt.Print(1) + }) +} diff --git a/ocis-pkg/handlers/debughandlers.go b/ocis-pkg/handlers/debughandlers.go deleted file mode 100644 index ebc6de781ec..00000000000 --- a/ocis-pkg/handlers/debughandlers.go +++ /dev/null @@ -1,34 +0,0 @@ -package handlers - -import ( - "io" - "net/http" -) - -// Health can be used for a health endpoint -func Health(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } -} - -// Ready can be used as a ready endpoint -func Ready(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does, we want to know. - if err != nil { - panic(err) - } -} diff --git a/ocis-pkg/service/debug/option.go b/ocis-pkg/service/debug/option.go index 5f9f593327f..3ed6b162f99 100644 --- a/ocis-pkg/service/debug/option.go +++ b/ocis-pkg/service/debug/option.go @@ -20,9 +20,9 @@ type Options struct { Token string Pprof bool Zpages bool - Health func(http.ResponseWriter, *http.Request) - Ready func(http.ResponseWriter, *http.Request) - ConfigDump func(http.ResponseWriter, *http.Request) + Health http.Handler + Ready http.Handler + ConfigDump http.Handler CorsAllowedOrigins []string CorsAllowedMethods []string CorsAllowedHeaders []string @@ -97,21 +97,21 @@ func Zpages(z bool) Option { } // Health provides a function to set the health option. -func Health(h func(http.ResponseWriter, *http.Request)) Option { +func Health(h http.Handler) Option { return func(o *Options) { o.Health = h } } // Ready provides a function to set the ready option. -func Ready(r func(http.ResponseWriter, *http.Request)) Option { +func Ready(r http.Handler) Option { return func(o *Options) { o.Ready = r } } // ConfigDump to be documented. -func ConfigDump(r func(http.ResponseWriter, *http.Request)) Option { +func ConfigDump(r http.Handler) Option { return func(o *Options) { o.ConfigDump = r } diff --git a/ocis-pkg/service/debug/service.go b/ocis-pkg/service/debug/service.go index 651856f42a9..82e056ea7d4 100644 --- a/ocis-pkg/service/debug/service.go +++ b/ocis-pkg/service/debug/service.go @@ -8,11 +8,12 @@ import ( chimiddleware "github.com/go-chi/chi/v5/middleware" "github.com/justinas/alice" + "github.com/prometheus/client_golang/prometheus/promhttp" + "go.opentelemetry.io/contrib/zpages" + "github.com/owncloud/ocis/v2/ocis-pkg/cors" "github.com/owncloud/ocis/v2/ocis-pkg/middleware" graphMiddleware "github.com/owncloud/ocis/v2/services/graph/pkg/middleware" - "github.com/prometheus/client_golang/prometheus/promhttp" - "go.opentelemetry.io/contrib/zpages" ) // NewService initializes a new debug service. @@ -28,11 +29,16 @@ func NewService(opts ...Option) *http.Server { promhttp.Handler(), )) - mux.HandleFunc("/healthz", dopts.Health) - mux.HandleFunc("/readyz", dopts.Ready) + if dopts.Health != nil { + mux.Handle("/healthz", dopts.Health) + } + + if dopts.Ready != nil { + mux.Handle("/readyz", dopts.Ready) + } if dopts.ConfigDump != nil { - mux.HandleFunc("/config", dopts.ConfigDump) + mux.Handle("/config", dopts.ConfigDump) } if dopts.Pprof { diff --git a/ocis-pkg/shared/healthchecklist.go b/ocis-pkg/shared/healthchecklist.go deleted file mode 100644 index ce240d7ed38..00000000000 --- a/ocis-pkg/shared/healthchecklist.go +++ /dev/null @@ -1,29 +0,0 @@ -package shared - -import "net" - -// Check is a single health-check -type Check func() error - -// RunChecklist runs all the given checks -func RunChecklist(checks ...Check) error { - for _, c := range checks { - err := c() - if err != nil { - return err - } - } - return nil -} - -// TCPConnect connects to a given tcp endpoint -func TCPConnect(host string) Check { - return func() error { - conn, err := net.Dial("tcp", host) - if err != nil { - return err - } - defer conn.Close() - return nil - } -} diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index af4300a0e8d..2fe02567dd7 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -146,6 +146,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -154,8 +159,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 0acbd873212..d803559649b 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -5,6 +5,8 @@ import ( "fmt" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" @@ -14,7 +16,6 @@ import ( "github.com/owncloud/ocis/v2/services/antivirus/pkg/config" "github.com/owncloud/ocis/v2/services/antivirus/pkg/config/parser" "github.com/owncloud/ocis/v2/services/antivirus/pkg/service" - "github.com/urfave/cli/v2" ) // Server is the entrypoint for the server command. @@ -55,6 +56,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -63,8 +69,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/app-provider/pkg/server/debug/server.go b/services/app-provider/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/app-provider/pkg/server/debug/server.go +++ b/services/app-provider/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/app-registry/pkg/server/debug/server.go b/services/app-registry/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/app-registry/pkg/server/debug/server.go +++ b/services/app-registry/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 93f945e4976..442dbf01fa9 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -7,6 +7,8 @@ import ( "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" @@ -16,7 +18,6 @@ import ( "github.com/owncloud/ocis/v2/services/audit/pkg/logging" svc "github.com/owncloud/ocis/v2/services/audit/pkg/service" "github.com/owncloud/ocis/v2/services/audit/pkg/types" - "github.com/urfave/cli/v2" ) // Server is the entrypoint for the server command. @@ -57,6 +58,11 @@ func Server(cfg *config.Config) *cli.Command { }) { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -65,8 +71,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/auth-app/pkg/server/debug/server.go b/services/auth-app/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/auth-app/pkg/server/debug/server.go +++ b/services/auth-app/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/auth-basic/pkg/server/debug/server.go b/services/auth-basic/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/auth-basic/pkg/server/debug/server.go +++ b/services/auth-basic/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/auth-bearer/pkg/server/debug/server.go b/services/auth-bearer/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/auth-bearer/pkg/server/debug/server.go +++ b/services/auth-bearer/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/auth-machine/pkg/server/debug/server.go b/services/auth-machine/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/auth-machine/pkg/server/debug/server.go +++ b/services/auth-machine/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/auth-service/pkg/server/debug/server.go b/services/auth-service/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/auth-service/pkg/server/debug/server.go +++ b/services/auth-service/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 80261be3d32..0c130019eab 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -8,6 +8,8 @@ import ( "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -19,7 +21,6 @@ import ( "github.com/owncloud/ocis/v2/services/clientlog/pkg/logging" "github.com/owncloud/ocis/v2/services/clientlog/pkg/metrics" "github.com/owncloud/ocis/v2/services/clientlog/pkg/service" - "github.com/urfave/cli/v2" ) // all events we care about @@ -116,6 +117,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -124,8 +130,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/collaboration/pkg/server/debug/server.go b/services/collaboration/pkg/server/debug/server.go index 83e1ed1eaa5..ce5e8f02014 100644 --- a/services/collaboration/pkg/server/debug/server.go +++ b/services/collaboration/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name+"."+options.Config.App.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 1c9146aa756..b098ccb1975 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -7,6 +7,9 @@ import ( "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/cs3org/reva/v2/pkg/store" "github.com/oklog/run" + "github.com/urfave/cli/v2" + microstore "go-micro.dev/v4/store" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" @@ -18,8 +21,6 @@ import ( "github.com/owncloud/ocis/v2/services/eventhistory/pkg/logging" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/metrics" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/server/grpc" - "github.com/urfave/cli/v2" - microstore "go-micro.dev/v4/store" ) // Server is the entrypoint for the server command. @@ -93,6 +94,11 @@ func Server(cfg *config.Config) *cli.Command { }) { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -101,8 +107,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/frontend/pkg/server/debug/server.go b/services/frontend/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/frontend/pkg/server/debug/server.go +++ b/services/frontend/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/gateway/pkg/server/debug/server.go b/services/gateway/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/gateway/pkg/server/debug/server.go +++ b/services/gateway/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/graph/pkg/server/debug/server.go b/services/graph/pkg/server/debug/server.go index 3f715977207..85136a94de8 100644 --- a/services/graph/pkg/server/debug/server.go +++ b/services/graph/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,7 +25,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ), nil } diff --git a/services/groups/pkg/server/debug/server.go b/services/groups/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/groups/pkg/server/debug/server.go +++ b/services/groups/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 1c691b46835..33460df9292 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -14,6 +14,8 @@ import ( "github.com/libregraph/idm/pkg/ldbbolt" "github.com/libregraph/idm/server" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" @@ -24,7 +26,6 @@ import ( "github.com/owncloud/ocis/v2/services/idm/pkg/config" "github.com/owncloud/ocis/v2/services/idm/pkg/config/parser" "github.com/owncloud/ocis/v2/services/idm/pkg/logging" - "github.com/urfave/cli/v2" ) // Server is the entrypoint for the server command. @@ -94,6 +95,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -102,8 +108,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/idm/pkg/server/debug/server.go b/services/idm/pkg/server/debug/server.go index 3f715977207..85136a94de8 100644 --- a/services/idm/pkg/server/debug/server.go +++ b/services/idm/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,7 +25,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ), nil } diff --git a/services/idp/pkg/server/debug/server.go b/services/idp/pkg/server/debug/server.go index 25d175bee85..9d733267855 100644 --- a/services/idp/pkg/server/debug/server.go +++ b/services/idp/pkg/server/debug/server.go @@ -1,22 +1,36 @@ package debug import ( - "io" + "context" "net/http" "net/url" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" - "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" - "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/idp/pkg/config" ) // Server initializes the debug service and server. func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger). + WithCheck("tcp-check", func(ctx context.Context) error { + tcpURL := options.Config.Ldap.URI + u, err := url.Parse(options.Config.Ldap.URI) + if err != nil { + return err + } + if u.Host != "" { + tcpURL = u.Host + } + + return handlers.NewTCPCheck(tcpURL)(ctx) + }), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -25,30 +39,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(health(options.Config, options.Logger)), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ), nil } - -// health implements the health check. -func health(cfg *config.Config, l log.Logger) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - targetHost, err := url.Parse(cfg.Ldap.URI) - if err != nil { - l.Fatal().Err(err).Str("uri", cfg.Ldap.URI).Msg("invalid LDAP URI") - } - err = shared.RunChecklist(shared.TCPConnect(targetHost.Host)) - retVal := http.StatusOK - if err != nil { - l.Error().Err(err).Msg("Healtcheck failed") - retVal = http.StatusInternalServerError - } - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(retVal) - - _, err = io.WriteString(w, http.StatusText(retVal)) - if err != nil { - l.Fatal().Err(err).Msg("Could not write health check body") - } - } -} diff --git a/services/invitations/pkg/server/debug/server.go b/services/invitations/pkg/server/debug/server.go index 4b8e4a29551..e6d7c3b0765 100644 --- a/services/invitations/pkg/server/debug/server.go +++ b/services/invitations/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index 983909d8c67..f0ad160976d 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -7,6 +7,8 @@ import ( "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" @@ -16,7 +18,6 @@ import ( "github.com/owncloud/ocis/v2/services/nats/pkg/config/parser" "github.com/owncloud/ocis/v2/services/nats/pkg/logging" "github.com/owncloud/ocis/v2/services/nats/pkg/server/nats" - "github.com/urfave/cli/v2" ) // Server is the entrypoint for the server command. @@ -37,6 +38,11 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -45,8 +51,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 25cfd126315..45fc693b831 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -10,6 +10,7 @@ import ( "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -58,6 +59,11 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -66,8 +72,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/ocdav/pkg/server/debug/server.go b/services/ocdav/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/ocdav/pkg/server/debug/server.go +++ b/services/ocdav/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/ocm/pkg/server/debug/server.go b/services/ocm/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/ocm/pkg/server/debug/server.go +++ b/services/ocm/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/ocs/pkg/server/debug/server.go b/services/ocs/pkg/server/debug/server.go index 4b8e4a29551..e6d7c3b0765 100644 --- a/services/ocs/pkg/server/debug/server.go +++ b/services/ocs/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 6118381ada0..3a68b35125c 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -121,6 +121,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -129,8 +134,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index 6715a914634..a51289783b1 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -8,6 +8,9 @@ import ( "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/cs3org/reva/v2/pkg/store" "github.com/oklog/run" + "github.com/urfave/cli/v2" + microstore "go-micro.dev/v4/store" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" @@ -16,8 +19,6 @@ import ( "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/service" - "github.com/urfave/cli/v2" - microstore "go-micro.dev/v4/store" ) // Server is the entrypoint for the server command. @@ -86,6 +87,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -94,8 +100,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/proxy/pkg/server/debug/server.go b/services/proxy/pkg/server/debug/server.go index 04d0330485c..f7368549624 100644 --- a/services/proxy/pkg/server/debug/server.go +++ b/services/proxy/pkg/server/debug/server.go @@ -16,6 +16,12 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + var configDumpFunc http.HandlerFunc = configDump(options.Config) return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -24,9 +30,9 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), - debug.ConfigDump(configDump(options.Config)), + debug.Health(checkHandler), + debug.Ready(checkHandler), + debug.ConfigDump(configDumpFunc), ), nil } diff --git a/services/search/pkg/server/debug/server.go b/services/search/pkg/server/debug/server.go index 3f715977207..85136a94de8 100644 --- a/services/search/pkg/server/debug/server.go +++ b/services/search/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,7 +25,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ), nil } diff --git a/services/settings/pkg/server/debug/server.go b/services/settings/pkg/server/debug/server.go index 4b8e4a29551..e6d7c3b0765 100644 --- a/services/settings/pkg/server/debug/server.go +++ b/services/settings/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/sharing/pkg/server/debug/server.go b/services/sharing/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/sharing/pkg/server/debug/server.go +++ b/services/sharing/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index 06491d29062..cbac80f3e2f 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -77,6 +77,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -85,8 +90,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/storage-publiclink/pkg/server/debug/server.go b/services/storage-publiclink/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/storage-publiclink/pkg/server/debug/server.go +++ b/services/storage-publiclink/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/storage-shares/pkg/server/debug/server.go b/services/storage-shares/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/storage-shares/pkg/server/debug/server.go +++ b/services/storage-shares/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/storage-system/pkg/server/debug/server.go b/services/storage-system/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/storage-system/pkg/server/debug/server.go +++ b/services/storage-system/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/storage-users/pkg/server/debug/server.go b/services/storage-users/pkg/server/debug/server.go index 8c5ce23fbc3..13fa273ee55 100644 --- a/services/storage-users/pkg/server/debug/server.go +++ b/services/storage-users/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Context(options.Context), @@ -21,8 +26,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/thumbnails/pkg/server/debug/server.go b/services/thumbnails/pkg/server/debug/server.go index 4b8e4a29551..e6d7c3b0765 100644 --- a/services/thumbnails/pkg/server/debug/server.go +++ b/services/thumbnails/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index 71a52ca7fac..50c134d7de7 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -9,6 +9,9 @@ import ( "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/v2/pkg/store" "github.com/oklog/run" + "github.com/urfave/cli/v2" + microstore "go-micro.dev/v4/store" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -23,8 +26,6 @@ import ( "github.com/owncloud/ocis/v2/services/userlog/pkg/logging" "github.com/owncloud/ocis/v2/services/userlog/pkg/metrics" "github.com/owncloud/ocis/v2/services/userlog/pkg/server/http" - "github.com/urfave/cli/v2" - microstore "go-micro.dev/v4/store" ) // all events we care about @@ -144,6 +145,11 @@ func Server(cfg *config.Config) *cli.Command { } { + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(logger), + ) + server := debug.NewService( debug.Logger(logger), debug.Name(cfg.Service.Name), @@ -152,8 +158,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/users/pkg/server/debug/server.go b/services/users/pkg/server/debug/server.go index 5686ae12648..46264bd66b9 100644 --- a/services/users/pkg/server/debug/server.go +++ b/services/users/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), //debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), //debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), //debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/web/pkg/server/debug/server.go b/services/web/pkg/server/debug/server.go index 3f715977207..85136a94de8 100644 --- a/services/web/pkg/server/debug/server.go +++ b/services/web/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,7 +25,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), ), nil } diff --git a/services/webdav/pkg/server/debug/server.go b/services/webdav/pkg/server/debug/server.go index 4b8e4a29551..e6d7c3b0765 100644 --- a/services/webdav/pkg/server/debug/server.go +++ b/services/webdav/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), diff --git a/services/webfinger/pkg/server/debug/server.go b/services/webfinger/pkg/server/debug/server.go index 4b8e4a29551..e6d7c3b0765 100644 --- a/services/webfinger/pkg/server/debug/server.go +++ b/services/webfinger/pkg/server/debug/server.go @@ -12,6 +12,11 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + return debug.NewService( debug.Logger(options.Logger), debug.Name(options.Config.Service.Name), @@ -20,8 +25,8 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(handlers.Health), - debug.Ready(handlers.Ready), + debug.Health(checkHandler), + debug.Ready(checkHandler), debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins), debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods), debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders), From 26bf6ab796dd4e327ba2a5d86bccc715c44f1168 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 7 Oct 2024 16:55:50 +0200 Subject: [PATCH 03/16] add debug server to activitylog & check web availability Signed-off-by: Christian Richter --- services/activitylog/pkg/command/server.go | 29 ++++------- .../activitylog/pkg/server/debug/option.go | 50 +++++++++++++++++++ .../activitylog/pkg/server/debug/server.go | 40 +++++++++++++++ services/web/pkg/server/debug/server.go | 18 ++++++- 4 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 services/activitylog/pkg/server/debug/option.go create mode 100644 services/activitylog/pkg/server/debug/server.go diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index 2fe02567dd7..d2b4b8c9a45 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -13,9 +13,7 @@ import ( microstore "go-micro.dev/v4/store" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -25,6 +23,7 @@ import ( "github.com/owncloud/ocis/v2/services/activitylog/pkg/config/parser" "github.com/owncloud/ocis/v2/services/activitylog/pkg/logging" "github.com/owncloud/ocis/v2/services/activitylog/pkg/metrics" + "github.com/owncloud/ocis/v2/services/activitylog/pkg/server/debug" "github.com/owncloud/ocis/v2/services/activitylog/pkg/server/http" ) @@ -146,25 +145,19 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/activitylog/pkg/server/debug/option.go b/services/activitylog/pkg/server/debug/option.go new file mode 100644 index 00000000000..3d499becf5f --- /dev/null +++ b/services/activitylog/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/activitylog/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/activitylog/pkg/server/debug/server.go b/services/activitylog/pkg/server/debug/server.go new file mode 100644 index 00000000000..8c9aec90c7c --- /dev/null +++ b/services/activitylog/pkg/server/debug/server.go @@ -0,0 +1,40 @@ +package debug + +import ( + "context" + "fmt" + "net/http" + + "github.com/cs3org/reva/v2/pkg/events/stream" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger).WithCheck("nats reachability", func(ctx context.Context) error { + _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) + if err != nil { + return fmt.Errorf("could not connect to nats server: %v", err) + } + return nil + }), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/web/pkg/server/debug/server.go b/services/web/pkg/server/debug/server.go index 85136a94de8..f5c6bd5a9b8 100644 --- a/services/web/pkg/server/debug/server.go +++ b/services/web/pkg/server/debug/server.go @@ -1,6 +1,9 @@ package debug import ( + "context" + "fmt" + "net" "net/http" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" @@ -14,7 +17,20 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger), + WithLogger(options.Logger).WithCheck("web reachability", func(ctx context.Context) error { + conn, err := net.Dial("tcp", options.Config.HTTP.Addr) + defer func(conn net.Conn) { + err := conn.Close() + if err != nil { + return + } + }(conn) + if err != nil { + return fmt.Errorf("could not connect to web server: %v", err) + } + + return nil + }), ) return debug.NewService( From 1ae1298f50cf1610e962f54d294dcaab8c482396 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 9 Oct 2024 12:22:05 +0200 Subject: [PATCH 04/16] fix debug server in idm Signed-off-by: Christian Richter --- services/idm/pkg/command/server.go | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 33460df9292..19a3f6d9e6d 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -18,14 +18,12 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" - "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/idm" "github.com/owncloud/ocis/v2/services/idm/pkg/config" "github.com/owncloud/ocis/v2/services/idm/pkg/config/parser" "github.com/owncloud/ocis/v2/services/idm/pkg/logging" + "github.com/owncloud/ocis/v2/services/idm/pkg/server/debug" ) // Server is the entrypoint for the server command. @@ -95,25 +93,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } From 32485bab2a3f5b7c8087573738b759977c9f898b Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 9 Oct 2024 12:27:54 +0200 Subject: [PATCH 05/16] fix debug server in antivirus Signed-off-by: Christian Richter --- services/activitylog/pkg/command/server.go | 1 - services/antivirus/pkg/command/server.go | 29 ++++------- services/antivirus/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/antivirus/pkg/server/debug/server.go | 31 ++++++++++++ 4 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 services/antivirus/pkg/server/debug/option.go create mode 100644 services/antivirus/pkg/server/debug/server.go diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index d2b4b8c9a45..9c018ecdbcd 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -150,7 +150,6 @@ func Server(cfg *config.Config) *cli.Command { debug.Context(ctx), debug.Config(cfg), ) - if err != nil { logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") return err diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index d803559649b..d259f0f5e60 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -8,13 +8,11 @@ import ( "github.com/urfave/cli/v2" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" - "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/antivirus/pkg/config" "github.com/owncloud/ocis/v2/services/antivirus/pkg/config/parser" + "github.com/owncloud/ocis/v2/services/antivirus/pkg/server/debug" "github.com/owncloud/ocis/v2/services/antivirus/pkg/service" ) @@ -56,25 +54,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/antivirus/pkg/server/debug/option.go b/services/antivirus/pkg/server/debug/option.go new file mode 100644 index 00000000000..1118208c8e1 --- /dev/null +++ b/services/antivirus/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/antivirus/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/antivirus/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} From c69a08dfbc924e27509fb2dc8e96b26a4f0e5377 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 9 Oct 2024 13:50:33 +0200 Subject: [PATCH 06/16] add checks for antivirus Signed-off-by: Christian Richter --- services/antivirus/pkg/server/debug/server.go | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index 85136a94de8..460bc390a4a 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -1,11 +1,16 @@ package debug import ( + "context" + "fmt" + "net" "net/http" + "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" + "github.com/owncloud/ocis/v2/services/antivirus/pkg/scanners" ) // Server initializes the debug service and server. @@ -14,7 +19,33 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger), + WithLogger(options.Logger). + WithCheck("nats reachability", func(ctx context.Context) error { + _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) + if err != nil { + return fmt.Errorf("could not connect to nats server: %v", err) + } + return nil + }). + WithCheck("antivirus reachability", func(ctx context.Context) error { + cfg := options.Config + switch cfg.Scanner.Type { + default: + // there is not av configured, return no error here + return nil + case "clamav": + _, err := net.Dial("tcp", cfg.Scanner.ClamAV.Socket) + if err != nil { + return fmt.Errorf("could not connect to clamav server: %v", err) + } + case "icap": + _, err := scanners.NewICAP(cfg.Scanner.ICAP.URL, cfg.Scanner.ICAP.Service, cfg.Scanner.ICAP.Timeout) + if err != nil { + return fmt.Errorf("could not connect to icap server: %v", err) + } + } + return nil + }), ) return debug.NewService( From c86cc619c2db2f2c80edd881903fc9e6ee07a5d5 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 10 Oct 2024 11:12:20 +0200 Subject: [PATCH 07/16] restructure check handlers Signed-off-by: Christian Richter --- ocis-pkg/handlers/checker.go | 16 +--------------- ocis-pkg/handlers/checknats.go | 23 +++++++++++++++++++++++ ocis-pkg/handlers/checktcp.go | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 ocis-pkg/handlers/checknats.go create mode 100644 ocis-pkg/handlers/checktcp.go diff --git a/ocis-pkg/handlers/checker.go b/ocis-pkg/handlers/checker.go index 29df6177e37..e0ec1545d26 100644 --- a/ocis-pkg/handlers/checker.go +++ b/ocis-pkg/handlers/checker.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "maps" - "net" "net/http" "golang.org/x/sync/errgroup" @@ -92,7 +91,7 @@ func (h *CheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { g.SetLimit(h.conf.limit) for name, check := range h.conf.checks { - g.Go(func() error { + g.Go(func() error { // https://go.dev/blog/loopvar-preview per iteration scope since go 1.22 if err := check(ctx); err != nil { // since go 1.22 for loops have a per-iteration scope instead of per-loop scope, no need to pin the check... return fmt.Errorf("'%s': %w", name, err) } @@ -114,16 +113,3 @@ func (h *CheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.conf.logger.Panic().Err(err).Msg("failed to write response") } } - -// NewTCPCheck returns a check that connects to a given tcp endpoint. -func NewTCPCheck(address string) func(ctx context.Context) error { - return func(ctx context.Context) error { - conn, err := net.Dial("tcp", address) - if err != nil { - return err - } - defer conn.Close() - - return nil - } -} diff --git a/ocis-pkg/handlers/checknats.go b/ocis-pkg/handlers/checknats.go new file mode 100644 index 00000000000..a8144cb4b95 --- /dev/null +++ b/ocis-pkg/handlers/checknats.go @@ -0,0 +1,23 @@ +package handlers + +import ( + "context" + "fmt" + + "github.com/nats-io/nats.go" +) + +// NewNatsCheck checks the reachability of a nats server. +func NewNatsCheck(natsCluster string, options ...nats.Option) func(context.Context) error { + return func(ctx context.Context) error { + n, err := nats.Connect(natsCluster, options...) + if err != nil { + return fmt.Errorf("could not connect to nats server: %v", err) + } + defer n.Close() + if n.Status() != nats.CONNECTED { + return fmt.Errorf("nats server not connected") + } + return nil + } +} diff --git a/ocis-pkg/handlers/checktcp.go b/ocis-pkg/handlers/checktcp.go new file mode 100644 index 00000000000..90308988cbf --- /dev/null +++ b/ocis-pkg/handlers/checktcp.go @@ -0,0 +1,23 @@ +package handlers + +import ( + "context" + "net" +) + +// NewTCPCheck returns a check that connects to a given tcp endpoint. +func NewTCPCheck(address string) func(ctx context.Context) error { + return func(ctx context.Context) error { + conn, err := net.Dial("tcp", address) + if err != nil { + return err + } + + err = conn.Close() + if err != nil { + return err + } + + return nil + } +} From 7d1a78cf9c7c089d1c2dc08ebe83f45e36a11e18 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 10 Oct 2024 11:12:41 +0200 Subject: [PATCH 08/16] refactor checks for activitylog and antivirus Signed-off-by: Christian Richter --- .../activitylog/pkg/server/debug/server.go | 12 ++------ services/antivirus/pkg/server/debug/server.go | 28 ++++--------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/services/activitylog/pkg/server/debug/server.go b/services/activitylog/pkg/server/debug/server.go index 8c9aec90c7c..c674f3ad8b9 100644 --- a/services/activitylog/pkg/server/debug/server.go +++ b/services/activitylog/pkg/server/debug/server.go @@ -1,11 +1,8 @@ package debug import ( - "context" - "fmt" "net/http" - "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -17,13 +14,8 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger).WithCheck("nats reachability", func(ctx context.Context) error { - _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) - if err != nil { - return fmt.Errorf("could not connect to nats server: %v", err) - } - return nil - }), + WithLogger(options.Logger). + WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)), ) return debug.NewService( diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index 460bc390a4a..b0488e321cf 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -2,15 +2,12 @@ package debug import ( "context" - "fmt" - "net" "net/http" - "github.com/cs3org/reva/v2/pkg/events/stream" + "github.com/dutchcoders/go-clamd" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/antivirus/pkg/scanners" ) // Server initializes the debug service and server. @@ -20,31 +17,18 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). WithLogger(options.Logger). - WithCheck("nats reachability", func(ctx context.Context) error { - _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) - if err != nil { - return fmt.Errorf("could not connect to nats server: %v", err) - } - return nil - }). + WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)). WithCheck("antivirus reachability", func(ctx context.Context) error { cfg := options.Config switch cfg.Scanner.Type { default: - // there is not av configured, return no error here - return nil + // there is not av configured, so we panic + panic("no antivirus configured") case "clamav": - _, err := net.Dial("tcp", cfg.Scanner.ClamAV.Socket) - if err != nil { - return fmt.Errorf("could not connect to clamav server: %v", err) - } + return clamd.NewClamd(cfg.Scanner.ClamAV.Socket).Ping() case "icap": - _, err := scanners.NewICAP(cfg.Scanner.ICAP.URL, cfg.Scanner.ICAP.Service, cfg.Scanner.ICAP.Timeout) - if err != nil { - return fmt.Errorf("could not connect to icap server: %v", err) - } + return handlers.NewTCPCheck(cfg.Scanner.ICAP.URL)(ctx) } - return nil }), ) From 0094d30378f7acf9b710555244fef5aa2250d3be Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 10 Oct 2024 11:57:59 +0200 Subject: [PATCH 09/16] code cleanup & refactoring Signed-off-by: Christian Richter --- services/app-registry/pkg/command/server.go | 1 + services/audit/pkg/command/server.go | 29 ++++------- services/audit/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/audit/pkg/server/debug/server.go | 31 ++++++++++++ services/auth-app/pkg/command/server.go | 1 + services/auth-basic/pkg/command/server.go | 1 + services/auth-bearer/pkg/command/server.go | 1 + services/auth-machine/pkg/command/server.go | 1 + services/auth-service/pkg/command/server.go | 1 + services/clientlog/pkg/command/server.go | 28 ++++------- services/clientlog/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/clientlog/pkg/server/debug/server.go | 31 ++++++++++++ services/eventhistory/pkg/command/server.go | 28 ++++------- .../eventhistory/pkg/server/debug/option.go | 50 +++++++++++++++++++ .../eventhistory/pkg/server/debug/server.go | 31 ++++++++++++ services/frontend/pkg/command/server.go | 1 + services/gateway/pkg/command/server.go | 4 +- services/groups/pkg/command/server.go | 1 + services/idp/pkg/command/server.go | 6 +-- services/invitations/pkg/command/server.go | 7 ++- services/nats/pkg/command/server.go | 29 ++++------- services/nats/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/nats/pkg/server/debug/server.go | 31 ++++++++++++ services/notifications/pkg/command/server.go | 29 ++++------- .../notifications/pkg/server/debug/option.go | 50 +++++++++++++++++++ .../notifications/pkg/server/debug/server.go | 31 ++++++++++++ services/ocm/pkg/command/server.go | 1 + services/policies/pkg/command/server.go | 28 ++++------- services/policies/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/policies/pkg/server/debug/server.go | 31 ++++++++++++ services/postprocessing/pkg/command/server.go | 29 ++++------- .../postprocessing/pkg/server/debug/option.go | 50 +++++++++++++++++++ .../postprocessing/pkg/server/debug/server.go | 31 ++++++++++++ services/proxy/pkg/command/server.go | 6 +-- services/search/pkg/command/server.go | 6 +-- services/settings/pkg/command/server.go | 6 ++- services/sse/pkg/command/server.go | 29 ++++------- services/sse/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/sse/pkg/server/debug/server.go | 31 ++++++++++++ .../storage-publiclink/pkg/command/server.go | 1 + services/storage-shares/pkg/command/server.go | 1 + services/storage-system/pkg/command/server.go | 1 + services/storage-users/pkg/command/server.go | 10 +--- services/thumbnails/pkg/command/server.go | 1 + .../thumbnails/pkg/server/debug/option.go | 10 ++++ services/userlog/pkg/command/server.go | 28 ++++------- services/userlog/pkg/server/debug/option.go | 50 +++++++++++++++++++ services/userlog/pkg/server/debug/server.go | 31 ++++++++++++ services/users/pkg/command/server.go | 1 + services/web/pkg/command/server.go | 6 +-- services/webdav/pkg/command/server.go | 7 ++- services/webfinger/pkg/command/server.go | 7 ++- 52 files changed, 871 insertions(+), 204 deletions(-) create mode 100644 services/audit/pkg/server/debug/option.go create mode 100644 services/audit/pkg/server/debug/server.go create mode 100644 services/clientlog/pkg/server/debug/option.go create mode 100644 services/clientlog/pkg/server/debug/server.go create mode 100644 services/eventhistory/pkg/server/debug/option.go create mode 100644 services/eventhistory/pkg/server/debug/server.go create mode 100644 services/nats/pkg/server/debug/option.go create mode 100644 services/nats/pkg/server/debug/server.go create mode 100644 services/notifications/pkg/server/debug/option.go create mode 100644 services/notifications/pkg/server/debug/server.go create mode 100644 services/policies/pkg/server/debug/option.go create mode 100644 services/policies/pkg/server/debug/server.go create mode 100644 services/postprocessing/pkg/server/debug/option.go create mode 100644 services/postprocessing/pkg/server/debug/server.go create mode 100644 services/sse/pkg/server/debug/option.go create mode 100644 services/sse/pkg/server/debug/server.go create mode 100644 services/userlog/pkg/server/debug/option.go create mode 100644 services/userlog/pkg/server/debug/server.go diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 0a85ce0346a..b37f29a7689 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -73,6 +73,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 442dbf01fa9..84bf206bc9d 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -10,12 +10,10 @@ import ( "github.com/urfave/cli/v2" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" - "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/audit/pkg/config" "github.com/owncloud/ocis/v2/services/audit/pkg/config/parser" "github.com/owncloud/ocis/v2/services/audit/pkg/logging" + "github.com/owncloud/ocis/v2/services/audit/pkg/server/debug" svc "github.com/owncloud/ocis/v2/services/audit/pkg/service" "github.com/owncloud/ocis/v2/services/audit/pkg/types" ) @@ -58,25 +56,18 @@ func Server(cfg *config.Config) *cli.Command { }) { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/audit/pkg/server/debug/option.go b/services/audit/pkg/server/debug/option.go new file mode 100644 index 00000000000..9449006241f --- /dev/null +++ b/services/audit/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/audit/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/audit/pkg/server/debug/server.go b/services/audit/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/audit/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/auth-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index f70aa4e8c95..00b75288776 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -82,6 +82,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index 084fce012ff..475f5333bf0 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -87,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 00652d312f3..76877780e9f 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index d90e68b7630..06a315d1dea 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 2f013c82959..35816e7806b 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -75,6 +75,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 0c130019eab..b2194f792b2 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -11,15 +11,14 @@ import ( "github.com/urfave/cli/v2" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/clientlog/pkg/config" "github.com/owncloud/ocis/v2/services/clientlog/pkg/config/parser" "github.com/owncloud/ocis/v2/services/clientlog/pkg/logging" "github.com/owncloud/ocis/v2/services/clientlog/pkg/metrics" + "github.com/owncloud/ocis/v2/services/clientlog/pkg/server/debug" "github.com/owncloud/ocis/v2/services/clientlog/pkg/service" ) @@ -117,25 +116,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/clientlog/pkg/server/debug/option.go b/services/clientlog/pkg/server/debug/option.go new file mode 100644 index 00000000000..1dafbb244ff --- /dev/null +++ b/services/clientlog/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/clientlog/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/clientlog/pkg/server/debug/server.go b/services/clientlog/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/clientlog/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index b098ccb1975..7107f899756 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -11,8 +11,6 @@ import ( microstore "go-micro.dev/v4/store" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -20,6 +18,7 @@ import ( "github.com/owncloud/ocis/v2/services/eventhistory/pkg/config/parser" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/logging" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/metrics" + "github.com/owncloud/ocis/v2/services/eventhistory/pkg/server/debug" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/server/grpc" ) @@ -94,25 +93,18 @@ func Server(cfg *config.Config) *cli.Command { }) { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/eventhistory/pkg/server/debug/option.go b/services/eventhistory/pkg/server/debug/option.go new file mode 100644 index 00000000000..a3966b315d1 --- /dev/null +++ b/services/eventhistory/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/eventhistory/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/eventhistory/pkg/server/debug/server.go b/services/eventhistory/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/eventhistory/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index cd22a4be7f1..8f936935f34 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -78,6 +78,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index 01b2742599c..bafbf7cd828 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -75,9 +75,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { - logger.Info(). - Str("server", cfg.Service.Name). - Msg("Shutting down debug erver") + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index cdd3db0ec2b..f79bc953e13 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -87,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index 02bf30eaa0f..7f02e1bb2c7 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -94,7 +94,7 @@ func Server(cfg *config.Config) *cli.Command { } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -104,8 +104,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index 0b2b358cda6..24f00038049 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command { } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -97,9 +97,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(err error) { - logger.Error().Err(err) - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index f0ad160976d..c5401b2db98 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -11,12 +11,10 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" - "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/nats/pkg/config" "github.com/owncloud/ocis/v2/services/nats/pkg/config/parser" "github.com/owncloud/ocis/v2/services/nats/pkg/logging" + "github.com/owncloud/ocis/v2/services/nats/pkg/server/debug" "github.com/owncloud/ocis/v2/services/nats/pkg/server/nats" ) @@ -38,25 +36,18 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/nats/pkg/server/debug/option.go b/services/nats/pkg/server/debug/option.go new file mode 100644 index 00000000000..977b85f3b9c --- /dev/null +++ b/services/nats/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/nats/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/nats/pkg/server/debug/server.go b/services/nats/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/nats/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 45fc693b831..8aa1e1bec75 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -12,17 +12,15 @@ import ( "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" - "github.com/owncloud/ocis/v2/ocis-pkg/version" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" "github.com/owncloud/ocis/v2/services/notifications/pkg/channels" "github.com/owncloud/ocis/v2/services/notifications/pkg/config" "github.com/owncloud/ocis/v2/services/notifications/pkg/config/parser" "github.com/owncloud/ocis/v2/services/notifications/pkg/logging" + "github.com/owncloud/ocis/v2/services/notifications/pkg/server/debug" "github.com/owncloud/ocis/v2/services/notifications/pkg/service" ) @@ -59,25 +57,18 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/notifications/pkg/server/debug/option.go b/services/notifications/pkg/server/debug/option.go new file mode 100644 index 00000000000..9ecb9364fef --- /dev/null +++ b/services/notifications/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/notifications/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/notifications/pkg/server/debug/server.go b/services/notifications/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/notifications/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 2e28cccedcd..7e7265b066d 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -75,6 +75,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 3a68b35125c..832909400ea 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -9,9 +9,7 @@ import ( "github.com/urfave/cli/v2" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -19,6 +17,7 @@ import ( "github.com/owncloud/ocis/v2/services/policies/pkg/config" "github.com/owncloud/ocis/v2/services/policies/pkg/config/parser" "github.com/owncloud/ocis/v2/services/policies/pkg/engine/opa" + "github.com/owncloud/ocis/v2/services/policies/pkg/server/debug" svcEvent "github.com/owncloud/ocis/v2/services/policies/pkg/service/event" svcGRPC "github.com/owncloud/ocis/v2/services/policies/pkg/service/grpc" ) @@ -121,25 +120,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/policies/pkg/server/debug/option.go b/services/policies/pkg/server/debug/option.go new file mode 100644 index 00000000000..aaf0a8d7a86 --- /dev/null +++ b/services/policies/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/policies/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/policies/pkg/server/debug/server.go b/services/policies/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/policies/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index a51289783b1..8527b71dc7b 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -11,13 +11,11 @@ import ( "github.com/urfave/cli/v2" microstore "go-micro.dev/v4/store" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" - "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging" + "github.com/owncloud/ocis/v2/services/postprocessing/pkg/server/debug" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/service" ) @@ -87,25 +85,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/postprocessing/pkg/server/debug/option.go b/services/postprocessing/pkg/server/debug/option.go new file mode 100644 index 00000000000..da002867f78 --- /dev/null +++ b/services/postprocessing/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/postprocessing/pkg/server/debug/server.go b/services/postprocessing/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/postprocessing/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index ae17b743a1b..7dd1673be86 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -214,7 +214,7 @@ func Server(cfg *config.Config) *cli.Command { } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -224,8 +224,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index 1e823e42e4e..f098602a67b 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -70,7 +70,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -80,8 +80,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 5b11f00a56e..1e442ab6fd2 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -94,7 +94,11 @@ func Server(cfg *config.Config) *cli.Command { }) // prepare a debug server and add it to the group run. - debugServer, err := debug.Server(debug.Logger(logger), debug.Context(ctx), debug.Config(cfg)) + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) if err != nil { logger.Error().Err(err).Str("server", "debug").Msg("Failed to initialize server") return err diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index cbac80f3e2f..722eb3970db 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -10,13 +10,11 @@ import ( "github.com/urfave/cli/v2" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" - "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/sse/pkg/config" "github.com/owncloud/ocis/v2/services/sse/pkg/config/parser" + "github.com/owncloud/ocis/v2/services/sse/pkg/server/debug" "github.com/owncloud/ocis/v2/services/sse/pkg/server/http" ) @@ -77,25 +75,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/sse/pkg/server/debug/option.go b/services/sse/pkg/server/debug/option.go new file mode 100644 index 00000000000..03d14d82f64 --- /dev/null +++ b/services/sse/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/sse/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/sse/pkg/server/debug/server.go b/services/sse/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/sse/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 184254cb9ff..d15dac8ceca 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index bdeabf0e2d8..41757ff57d9 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 5195280e416..2b50a59a0e9 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index df7fca8a4b6..f88ed590c9b 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -76,15 +76,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(err error) { - logger.Error().Err(err).Str("server", cfg.Service.Name). - Msg("Shutting down debug server") - if err := debugServer.Shutdown(context.Background()); err != nil { - logger.Error(). - Err(err). - Str("server", cfg.Service.Name). - Msg("Error during debug server shutdown") - } - + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index cc671f74f25..4ad5ae0fdd7 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command { server, err := debug.Server( debug.Logger(logger), debug.Config(cfg), + debug.Context(ctx), ) if err != nil { logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") diff --git a/services/thumbnails/pkg/server/debug/option.go b/services/thumbnails/pkg/server/debug/option.go index 534a47f1ccd..fdc0fe6bc8e 100644 --- a/services/thumbnails/pkg/server/debug/option.go +++ b/services/thumbnails/pkg/server/debug/option.go @@ -1,6 +1,8 @@ package debug import ( + "context" + "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config" ) @@ -13,6 +15,7 @@ type Options struct { Name string Address string Logger log.Logger + Context context.Context Config *config.Config } @@ -34,6 +37,13 @@ func Logger(val log.Logger) Option { } } +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + // Config provides a function to set the config option. func Config(val *config.Config) Option { return func(o *Options) { diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index 50c134d7de7..566c5f76e7c 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -13,9 +13,7 @@ import ( microstore "go-micro.dev/v4/store" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/registry" - "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -25,6 +23,7 @@ import ( "github.com/owncloud/ocis/v2/services/userlog/pkg/config/parser" "github.com/owncloud/ocis/v2/services/userlog/pkg/logging" "github.com/owncloud/ocis/v2/services/userlog/pkg/metrics" + "github.com/owncloud/ocis/v2/services/userlog/pkg/server/debug" "github.com/owncloud/ocis/v2/services/userlog/pkg/server/http" ) @@ -145,25 +144,18 @@ func Server(cfg *config.Config) *cli.Command { } { - checkHandler := handlers.NewCheckHandler( - handlers.NewCheckHandlerConfiguration(). - WithLogger(logger), - ) - - server := debug.NewService( + debugServer, err := debug.Server( debug.Logger(logger), - debug.Name(cfg.Service.Name), - debug.Version(version.GetString()), - debug.Address(cfg.Debug.Addr), - debug.Token(cfg.Debug.Token), - debug.Pprof(cfg.Debug.Pprof), - debug.Zpages(cfg.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Context(ctx), + debug.Config(cfg), ) + if err != nil { + logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") + return err + } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/userlog/pkg/server/debug/option.go b/services/userlog/pkg/server/debug/option.go new file mode 100644 index 00000000000..6e3607ac636 --- /dev/null +++ b/services/userlog/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/services/userlog/pkg/config" +) + +// Option defines a single option function. +type Option func(o *Options) + +// Options defines the available options for this package. +type Options struct { + Logger log.Logger + Context context.Context + Config *config.Config +} + +// newOptions initializes the available default options. +func newOptions(opts ...Option) Options { + opt := Options{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// Logger provides a function to set the logger option. +func Logger(val log.Logger) Option { + return func(o *Options) { + o.Logger = val + } +} + +// Context provides a function to set the context option. +func Context(val context.Context) Option { + return func(o *Options) { + o.Context = val + } +} + +// Config provides a function to set the config option. +func Config(val *config.Config) Option { + return func(o *Options) { + o.Config = val + } +} diff --git a/services/userlog/pkg/server/debug/server.go b/services/userlog/pkg/server/debug/server.go new file mode 100644 index 00000000000..85136a94de8 --- /dev/null +++ b/services/userlog/pkg/server/debug/server.go @@ -0,0 +1,31 @@ +package debug + +import ( + "net/http" + + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" + "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" + "github.com/owncloud/ocis/v2/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + checkHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.GetString()), + debug.Address(options.Config.Debug.Addr), + debug.Token(options.Config.Debug.Token), + debug.Pprof(options.Config.Debug.Pprof), + debug.Zpages(options.Config.Debug.Zpages), + debug.Health(checkHandler), + debug.Ready(checkHandler), + ), nil +} diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 95a899873da..aed4caa147c 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -87,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index 5ba91343195..73ceba8cce1 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -93,7 +93,7 @@ func Server(cfg *config.Config) *cli.Command { } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -103,8 +103,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index d7ed386242d..869b80f0ca1 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -93,9 +93,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(err error) { - logger.Error().Err(err) - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(err error) { + _ = debugServer.Shutdown(ctx) cancel() }) } diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index 0ba9cbe1298..0088349687d 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -106,9 +106,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(err error) { - logger.Error().Err(err) - _ = server.Shutdown(ctx) + gr.Add(debugServer.ListenAndServe, func(err error) { + _ = debugServer.Shutdown(ctx) cancel() }) } From 61070e318756bd26a09494d186df1a8daf7d2b19 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 10 Oct 2024 14:10:52 +0200 Subject: [PATCH 10/16] fix sonar cube bugs Signed-off-by: Christian Richter --- ocis-pkg/handlers/checknats.go | 2 +- ocis-pkg/handlers/checktcp.go | 4 ++-- services/idp/pkg/command/server.go | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ocis-pkg/handlers/checknats.go b/ocis-pkg/handlers/checknats.go index a8144cb4b95..7eba98e9067 100644 --- a/ocis-pkg/handlers/checknats.go +++ b/ocis-pkg/handlers/checknats.go @@ -9,7 +9,7 @@ import ( // NewNatsCheck checks the reachability of a nats server. func NewNatsCheck(natsCluster string, options ...nats.Option) func(context.Context) error { - return func(ctx context.Context) error { + return func(_ context.Context) error { n, err := nats.Connect(natsCluster, options...) if err != nil { return fmt.Errorf("could not connect to nats server: %v", err) diff --git a/ocis-pkg/handlers/checktcp.go b/ocis-pkg/handlers/checktcp.go index 90308988cbf..a09e6570cd6 100644 --- a/ocis-pkg/handlers/checktcp.go +++ b/ocis-pkg/handlers/checktcp.go @@ -7,7 +7,7 @@ import ( // NewTCPCheck returns a check that connects to a given tcp endpoint. func NewTCPCheck(address string) func(ctx context.Context) error { - return func(ctx context.Context) error { + return func(_ context.Context) error { conn, err := net.Dial("tcp", address) if err != nil { return err @@ -17,7 +17,7 @@ func NewTCPCheck(address string) func(ctx context.Context) error { if err != nil { return err } - + return nil } } diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index 7f02e1bb2c7..9c12ac619f0 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -36,7 +36,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", Before: func(c *cli.Context) error { - configlog.ReturnFatal(parser.ParseConfig(cfg)) + err := configlog.ReturnFatal(parser.ParseConfig(cfg)) + if err != nil { + return err + } if cfg.IDP.EncryptionSecretFile != "" { if err := ensureEncryptionSecretExists(cfg.IDP.EncryptionSecretFile); err != nil { From 84e024e8f1fa3b39a02ed586ad1e2bf52d71bc48 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 10 Oct 2024 14:12:27 +0200 Subject: [PATCH 11/16] remove nats dependency from activitylog & antivirus Signed-off-by: Christian Richter --- services/activitylog/pkg/server/debug/server.go | 4 +--- services/antivirus/pkg/server/debug/server.go | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/services/activitylog/pkg/server/debug/server.go b/services/activitylog/pkg/server/debug/server.go index c674f3ad8b9..dab0ed9a9f7 100644 --- a/services/activitylog/pkg/server/debug/server.go +++ b/services/activitylog/pkg/server/debug/server.go @@ -14,9 +14,7 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger). - WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)), - ) + WithLogger(options.Logger)) return debug.NewService( debug.Logger(options.Logger), diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index b0488e321cf..7b4ec3c96bb 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -17,7 +17,6 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). WithLogger(options.Logger). - WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)). WithCheck("antivirus reachability", func(ctx context.Context) error { cfg := options.Config switch cfg.Scanner.Type { From 941e688ae67545390934329a951990ea453be818 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Fri, 11 Oct 2024 10:03:56 +0200 Subject: [PATCH 12/16] split health and readiness for activitylog and antivirus Signed-off-by: Christian Richter --- services/activitylog/pkg/server/debug/server.go | 15 +++++++++++---- services/antivirus/pkg/server/debug/server.go | 12 +++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/services/activitylog/pkg/server/debug/server.go b/services/activitylog/pkg/server/debug/server.go index dab0ed9a9f7..09218a407bd 100644 --- a/services/activitylog/pkg/server/debug/server.go +++ b/services/activitylog/pkg/server/debug/server.go @@ -12,9 +12,16 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) - checkHandler := handlers.NewCheckHandler( + healthHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger)) + WithLogger(options.Logger), + ) + + readyHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger). + WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)), + ) return debug.NewService( debug.Logger(options.Logger), @@ -24,7 +31,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Health(healthHandler), + debug.Ready(readyHandler), ), nil } diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index 7b4ec3c96bb..521434f0c2b 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -14,9 +14,15 @@ import ( func Server(opts ...Option) (*http.Server, error) { options := newOptions(opts...) - checkHandler := handlers.NewCheckHandler( + healthHandler := handlers.NewCheckHandler( + handlers.NewCheckHandlerConfiguration(). + WithLogger(options.Logger), + ) + + readyHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). WithLogger(options.Logger). + WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)). WithCheck("antivirus reachability", func(ctx context.Context) error { cfg := options.Config switch cfg.Scanner.Type { @@ -39,7 +45,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Token(options.Config.Debug.Token), debug.Pprof(options.Config.Debug.Pprof), debug.Zpages(options.Config.Debug.Zpages), - debug.Health(checkHandler), - debug.Ready(checkHandler), + debug.Health(healthHandler), + debug.Ready(readyHandler), ), nil } From 6064386787cc55d571cc777b4f04c2d2e4d8a6ca Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 14 Oct 2024 08:22:47 +0200 Subject: [PATCH 13/16] add timeout to tcp checker Signed-off-by: Christian Richter --- ocis-pkg/handlers/checktcp.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocis-pkg/handlers/checktcp.go b/ocis-pkg/handlers/checktcp.go index a09e6570cd6..0db97bfabf8 100644 --- a/ocis-pkg/handlers/checktcp.go +++ b/ocis-pkg/handlers/checktcp.go @@ -3,12 +3,13 @@ package handlers import ( "context" "net" + "time" ) // NewTCPCheck returns a check that connects to a given tcp endpoint. func NewTCPCheck(address string) func(ctx context.Context) error { return func(_ context.Context) error { - conn, err := net.Dial("tcp", address) + conn, err := net.DialTimeout("tcp", address, 3*time.Second) if err != nil { return err } From da29c8e8fda0f73bd21c7386f39bfa07510bcd6b Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 14 Oct 2024 14:57:27 +0200 Subject: [PATCH 14/16] make sonarcloud happy Signed-off-by: Christian Richter --- ocis-pkg/handlers/checker.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ocis-pkg/handlers/checker.go b/ocis-pkg/handlers/checker.go index e0ec1545d26..30d39d320f9 100644 --- a/ocis-pkg/handlers/checker.go +++ b/ocis-pkg/handlers/checker.go @@ -91,9 +91,11 @@ func (h *CheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { g.SetLimit(h.conf.limit) for name, check := range h.conf.checks { + checker := check + checkerName := name g.Go(func() error { // https://go.dev/blog/loopvar-preview per iteration scope since go 1.22 - if err := check(ctx); err != nil { // since go 1.22 for loops have a per-iteration scope instead of per-loop scope, no need to pin the check... - return fmt.Errorf("'%s': %w", name, err) + if err := checker(ctx); err != nil { // since go 1.22 for loops have a per-iteration scope instead of per-loop scope, no need to pin the check... + return fmt.Errorf("'%s': %w", checkerName, err) } return nil From fd4f8ce758e7e8bbe5546a509a95e7a29f88e616 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 14 Oct 2024 16:05:17 +0200 Subject: [PATCH 15/16] incorporate requested changes Signed-off-by: Christian Richter --- ocis-pkg/handlers/checker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocis-pkg/handlers/checker.go b/ocis-pkg/handlers/checker.go index 30d39d320f9..de87bd7f384 100644 --- a/ocis-pkg/handlers/checker.go +++ b/ocis-pkg/handlers/checker.go @@ -108,7 +108,7 @@ func (h *CheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.conf.logger.Error().Err(err).Msg("check failed") } - w.Header().Set("Content-Type", "text/plain") // fixMe: should be application/json!?! + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(status) if _, err := io.WriteString(w, http.StatusText(status)); err != nil { // io.WriteString should not fail, but if it does, we want to know. From 3d94a65db649a3d73e274e547215a209df37c80c Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 14 Oct 2024 16:19:28 +0200 Subject: [PATCH 16/16] replace panic in antivirus by error Signed-off-by: Christian Richter --- services/antivirus/pkg/server/debug/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index 521434f0c2b..73009607de3 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -2,6 +2,7 @@ package debug import ( "context" + "errors" "net/http" "github.com/dutchcoders/go-clamd" @@ -27,8 +28,7 @@ func Server(opts ...Option) (*http.Server, error) { cfg := options.Config switch cfg.Scanner.Type { default: - // there is not av configured, so we panic - panic("no antivirus configured") + return errors.New("no antivirus configured") case "clamav": return clamd.NewClamd(cfg.Scanner.ClamAV.Socket).Ping() case "icap":