From cd2f7e2e9f17912eb12cb30c0a82edeba783e756 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 2 May 2023 15:41:54 +0200 Subject: [PATCH] add debug to userlog Signed-off-by: Christian Richter --- changelog/unreleased/add-debug-to-userlog.md | 6 ++++++ docs/services/general-info/port-ranges.md | 2 +- services/userlog/pkg/command/server.go | 21 +++++++++++++++++++ services/userlog/pkg/config/config.go | 13 ++++++++++-- .../pkg/config/defaults/defaultconfig.go | 18 ++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/add-debug-to-userlog.md diff --git a/changelog/unreleased/add-debug-to-userlog.md b/changelog/unreleased/add-debug-to-userlog.md new file mode 100644 index 00000000000..0c7d8c92403 --- /dev/null +++ b/changelog/unreleased/add-debug-to-userlog.md @@ -0,0 +1,6 @@ +Enhancement: Add debug server to userlog + +We added a debug server to userlog. + +https://github.com/owncloud/ocis/pull/6202 +https://github.com/owncloud/ocis/issues/5002 \ No newline at end of file diff --git a/docs/services/general-info/port-ranges.md b/docs/services/general-info/port-ranges.md index a9daef8b34d..1e182013060 100644 --- a/docs/services/general-info/port-ranges.md +++ b/docs/services/general-info/port-ranges.md @@ -52,7 +52,7 @@ We also suggest to use the last port in your extensions' range as a debug/metric | 9195-9199 | FREE | | 9200-9204 | [proxy]({{< ref "../proxy/_index.md" >}}) | | 9205-9209 | [proxy]({{< ref "../proxy/_index.md" >}}) | -| 9210-9214 | FREE | +| 9210-9214 | [userlog]{{< ref "../userlog/_index.md" >}} | | 9215-9219 | [storage-system]({{< ref "../storage-system/_index.md" >}}) | | 9220-9224 | [search]({{< ref "../search/_index.md" >}}) | | 9225-9229 | FREE | diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index af3b4de34c8..c814b322c19 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -10,6 +10,8 @@ import ( "github.com/cs3org/reva/v2/pkg/store" "github.com/oklog/run" "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/version" ehsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0" @@ -129,6 +131,25 @@ func Server(cfg *config.Config) *cli.Command { }) } + { + server := debug.NewService( + 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(handlers.Health), + debug.Ready(handlers.Ready), + ) + + gr.Add(server.ListenAndServe, func(_ error) { + _ = server.Shutdown(ctx) + cancel() + }) + } + return gr.Run() }, } diff --git a/services/userlog/pkg/config/config.go b/services/userlog/pkg/config/config.go index 2ae478908da..ba4bee1762d 100644 --- a/services/userlog/pkg/config/config.go +++ b/services/userlog/pkg/config/config.go @@ -13,8 +13,9 @@ type Config struct { Service Service `yaml:"-"` - Log *Log `yaml:"log"` - Debug Debug `yaml:"debug"` + Tracing *Tracing `yaml:"tracing"` + Log *Log `yaml:"log"` + Debug Debug `yaml:"debug"` HTTP HTTP `yaml:"http"` GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"` @@ -70,3 +71,11 @@ type HTTP struct { type TokenManager struct { JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET;USERLOG_JWT_SECRET" desc:"The secret to mint and validate jwt tokens."` } + +// Tracing defines the available tracing configuration. +type Tracing struct { + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;USERLOG_TRACING_ENABLED" desc:"Activates tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;USERLOG_TRACING_TYPE" desc:"The type of tracing. Defaults to \"\", which is the same as \"jaeger\". Allowed tracing types are \"jaeger\" and \"\" as of now."` + Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;USERLOG_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;USERLOG_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."` +} diff --git a/services/userlog/pkg/config/defaults/defaultconfig.go b/services/userlog/pkg/config/defaults/defaultconfig.go index 65d28e6115f..dfb412a1d56 100644 --- a/services/userlog/pkg/config/defaults/defaultconfig.go +++ b/services/userlog/pkg/config/defaults/defaultconfig.go @@ -20,6 +20,12 @@ func FullDefaultConfig() *config.Config { // DefaultConfig return the default configuration func DefaultConfig() *config.Config { return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9210", + Token: "", + Pprof: false, + Zpages: false, + }, Service: config.Service{ Name: "userlog", }, @@ -82,6 +88,18 @@ func EnsureDefaults(cfg *config.Config) { if cfg.Commons != nil { cfg.HTTP.TLS = cfg.Commons.HTTPServiceTLS } + + // provide with defaults for shared tracing, since we need a valid destination address for "envdecode". + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } } // Sanitize sanitizes the config