From 5b70d46213c6b97102c1ce5fcb3c27ffcb1bed96 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 11:10:33 +0100 Subject: [PATCH] remove build flags, add debug server to accounts --- accounts/pkg/command/server.go | 13 +++++ accounts/pkg/config/debug.go | 1 - accounts/pkg/config/defaultconfig.go | 6 +++ accounts/pkg/server/debug/option.go | 50 ++++++++++++++++++ accounts/pkg/server/debug/server.go | 63 +++++++++++++++++++++++ glauth/pkg/server/debug/server.go | 6 +-- graph-explorer/pkg/server/debug/server.go | 14 +++-- graph/pkg/server/debug/server.go | 14 +++-- idp/pkg/server/debug/server.go | 12 +++-- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/graph.go | 3 -- ocis/pkg/command/graphexplorer.go | 3 -- ocis/pkg/command/root.go | 16 +++++- ocis/pkg/command/server.go | 1 + ocis/pkg/command/storageauthmachine.go | 3 -- ocis/pkg/command/store.go | 2 + ocs/pkg/server/debug/server.go | 12 +++-- proxy/pkg/server/debug/server.go | 12 +++-- settings/pkg/server/debug/server.go | 18 +++++-- storage/pkg/server/debug/server.go | 14 +++-- store/pkg/server/debug/server.go | 16 ++++-- thumbnails/pkg/server/debug/server.go | 16 +++++- web/pkg/server/debug/server.go | 14 +++-- webdav/pkg/server/debug/server.go | 12 +++-- 24 files changed, 260 insertions(+), 63 deletions(-) create mode 100644 accounts/pkg/server/debug/option.go create mode 100644 accounts/pkg/server/debug/server.go diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 44feb3ffe6..d0cd905a05 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -7,6 +7,7 @@ import ( "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/logging" "github.com/owncloud/ocis/accounts/pkg/metrics" + "github.com/owncloud/ocis/accounts/pkg/server/debug" "github.com/owncloud/ocis/accounts/pkg/server/grpc" "github.com/owncloud/ocis/accounts/pkg/server/http" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" @@ -75,6 +76,18 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) + // prepare a debug server and add it to the group run. + 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 + } + + gr.Add(debugServer.ListenAndServe, func(_ error) { + _ = debugServer.Shutdown(ctx) + cancel() + }) + return gr.Run() }, } diff --git a/accounts/pkg/config/debug.go b/accounts/pkg/config/debug.go index c95ef3a266..539b8fabab 100644 --- a/accounts/pkg/config/debug.go +++ b/accounts/pkg/config/debug.go @@ -1,6 +1,5 @@ package config -//TODO: use debug config // Debug defines the available debug configuration. type Debug struct { Addr string `ocisConfig:"addr" env:"ACCOUNTS_DEBUG_ADDR"` diff --git a/accounts/pkg/config/defaultconfig.go b/accounts/pkg/config/defaultconfig.go index 5b027a5459..2c69305bb9 100644 --- a/accounts/pkg/config/defaultconfig.go +++ b/accounts/pkg/config/defaultconfig.go @@ -8,6 +8,12 @@ import ( func DefaultConfig() *Config { return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9182", + Token: "", + Pprof: false, + Zpages: false, + }, HTTP: HTTP{ Addr: "127.0.0.1:9181", Namespace: "com.owncloud.web", diff --git a/accounts/pkg/server/debug/option.go b/accounts/pkg/server/debug/option.go new file mode 100644 index 0000000000..0fd139d248 --- /dev/null +++ b/accounts/pkg/server/debug/option.go @@ -0,0 +1,50 @@ +package debug + +import ( + "context" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" +) + +// 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/accounts/pkg/server/debug/server.go b/accounts/pkg/server/debug/server.go new file mode 100644 index 0000000000..cabc144644 --- /dev/null +++ b/accounts/pkg/server/debug/server.go @@ -0,0 +1,63 @@ +package debug + +import ( + "io" + "net/http" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/service/debug" + "github.com/owncloud/ocis/ocis-pkg/version" +) + +// Server initializes the debug service and server. +func Server(opts ...Option) (*http.Server, error) { + options := newOptions(opts...) + + return debug.NewService( + debug.Logger(options.Logger), + debug.Name(options.Config.Service.Name), + debug.Version(version.String), + 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(health(options.Config)), + debug.Ready(ready(options.Config)), + 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/glauth/pkg/server/debug/server.go b/glauth/pkg/server/debug/server.go index d6373ba1ec..5cc9fab7b3 100644 --- a/glauth/pkg/server/debug/server.go +++ b/glauth/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("glauth"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,7 +32,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // 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. @@ -48,7 +48,7 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // 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. diff --git a/graph-explorer/pkg/server/debug/server.go b/graph-explorer/pkg/server/debug/server.go index 5717db3c7c..1165097394 100644 --- a/graph-explorer/pkg/server/debug/server.go +++ b/graph-explorer/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("graph-explorer"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -46,9 +48,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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/graph/pkg/server/debug/server.go b/graph/pkg/server/debug/server.go index fe979c8ee2..240b1f9362 100644 --- a/graph/pkg/server/debug/server.go +++ b/graph/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("graph"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -46,9 +48,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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/idp/pkg/server/debug/server.go b/idp/pkg/server/debug/server.go index f05038d95a..bdfe920837 100644 --- a/idp/pkg/server/debug/server.go +++ b/idp/pkg/server/debug/server.go @@ -31,9 +31,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -45,9 +47,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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/config/config.go b/ocis-pkg/config/config.go index d0cd0e1d2d..1f3e3c0d2c 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -45,7 +45,7 @@ type Config struct { *shared.Commons `ocisConfig:"shared"` Tracing shared.Tracing `ocisConfig:"tracing"` - Log shared.Log `ocisConfig:"log"` + Log *shared.Log `ocisConfig:"log"` Mode Mode // DEPRECATED File string diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 1b1ae5553d..ecc94826ca 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index e4dc82e024..7833206b91 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 034061824b..51ff2189ba 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -5,8 +5,8 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/config" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" @@ -57,11 +57,23 @@ func Execute() error { // ParseConfig loads ocis configuration. func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs("ocis", cfg) + _, err := config.BindSourcesToStructs("ocis", cfg) if err != nil { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &shared.Log{} + } + // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index c9262144d5..67cde41954 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -18,6 +18,7 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { + // what to do //cfg.Commons = &shared.Commons{ // Log: &cfg.Log, //} diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 9498c7a017..18b9d8a183 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -1,6 +1,3 @@ -//go:build !simple -// +build !simple - package command import ( diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 5629abac37..cec0e2e028 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -23,11 +23,13 @@ func StoreCommand(cfg *config.Config) *cli.Command { return err } + // TODO: what to do //globalLog = cfg.Log return nil }, Action: func(c *cli.Context) error { + // TODO: what to do // if accounts logging is empty in ocis.yaml //if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { // // we can safely inherit the global logging values. diff --git a/ocs/pkg/server/debug/server.go b/ocs/pkg/server/debug/server.go index 7c704840e0..214c4a9c19 100644 --- a/ocs/pkg/server/debug/server.go +++ b/ocs/pkg/server/debug/server.go @@ -35,9 +35,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -49,9 +51,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index b4106f2a8c..5c4b380462 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -33,9 +33,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -47,9 +49,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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/settings/pkg/server/debug/server.go b/settings/pkg/server/debug/server.go index 36bf1411ea..81f41de18b 100644 --- a/settings/pkg/server/debug/server.go +++ b/settings/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("settings"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -36,9 +36,13 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, 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) + } } } @@ -48,8 +52,12 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, 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/storage/pkg/server/debug/server.go b/storage/pkg/server/debug/server.go index 4a3fa24b3a..29ea57b0a7 100644 --- a/storage/pkg/server/debug/server.go +++ b/storage/pkg/server/debug/server.go @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -46,10 +48,12 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } -} +} \ No newline at end of file diff --git a/store/pkg/server/debug/server.go b/store/pkg/server/debug/server.go index e3812b25df..975974c5cc 100644 --- a/store/pkg/server/debug/server.go +++ b/store/pkg/server/debug/server.go @@ -31,9 +31,13 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, 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) + } } } @@ -43,8 +47,12 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) + _, 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/thumbnails/pkg/server/debug/server.go b/thumbnails/pkg/server/debug/server.go index b78261d5fe..24fdee22c1 100644 --- a/thumbnails/pkg/server/debug/server.go +++ b/thumbnails/pkg/server/debug/server.go @@ -25,21 +25,33 @@ func Server(opts ...Option) (*http.Server, error) { ), 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) - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + + // 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) - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + + // 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/web/pkg/server/debug/server.go b/web/pkg/server/debug/server.go index 43c45036bd..d4d7e302e6 100644 --- a/web/pkg/server/debug/server.go +++ b/web/pkg/server/debug/server.go @@ -15,7 +15,7 @@ func Server(opts ...Option) (*http.Server, error) { return debug.NewService( debug.Logger(options.Logger), - debug.Name("web"), + debug.Name(options.Config.Service.Name), debug.Version(version.String), debug.Address(options.Config.Debug.Addr), debug.Token(options.Config.Debug.Token), @@ -32,9 +32,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -46,9 +48,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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/webdav/pkg/server/debug/server.go b/webdav/pkg/server/debug/server.go index f79a0538f8..ad9568b604 100644 --- a/webdav/pkg/server/debug/server.go +++ b/webdav/pkg/server/debug/server.go @@ -35,9 +35,11 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } } @@ -49,9 +51,11 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - // TODO(tboerger): check if services are up and running + // TODO: check if services are up and running - if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + _, 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) } }