From e1fb4c315b8c80a6fd1006a11a9f162d66b61455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Franke?= Date: Fri, 14 Jul 2023 13:22:04 +0200 Subject: [PATCH] Change gateway service to use service traceprovider (#6799) This changes the gateway service to use the service traceprovider. --- services/gateway/pkg/command/server.go | 6 +++--- services/gateway/pkg/config/config.go | 14 ++++---------- services/gateway/pkg/config/tracing.go | 21 +++++++++++++++++++++ services/gateway/pkg/tracing/tracing.go | 18 ------------------ 4 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 services/gateway/pkg/config/tracing.go delete mode 100644 services/gateway/pkg/tracing/tracing.go diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index 37c34c976d..3d7229acb0 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -11,13 +11,13 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" + "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/gateway/pkg/config" "github.com/owncloud/ocis/v2/services/gateway/pkg/config/parser" "github.com/owncloud/ocis/v2/services/gateway/pkg/logging" "github.com/owncloud/ocis/v2/services/gateway/pkg/revaconfig" "github.com/owncloud/ocis/v2/services/gateway/pkg/server/debug" - "github.com/owncloud/ocis/v2/services/gateway/pkg/tracing" "github.com/urfave/cli/v2" ) @@ -32,7 +32,7 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - err := tracing.Configure(cfg, logger) + traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } @@ -49,6 +49,7 @@ func Server(cfg *config.Config) *cli.Command { runtime.RunWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), + runtime.WithTraceProvider(traceProvider), ) return nil @@ -66,7 +67,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/gateway/pkg/config/config.go b/services/gateway/pkg/config/config.go index d51b0008a1..606263c892 100644 --- a/services/gateway/pkg/config/config.go +++ b/services/gateway/pkg/config/config.go @@ -43,17 +43,11 @@ type Config struct { StorageSharesEndpoint string `yaml:"storage_shares_endpoint" env:"GATEWAY_STORAGE_SHARES_ENDPOINT" desc:"The STORAGE SHARES API endpoint."` AppRegistryEndpoint string `yaml:"app_registry_endpoint" env:"GATEWAY_APP_REGISTRY_ENDPOINT" desc:"The APP REGISTRY API endpoint."` - StorageRegistry StorageRegistry `yaml:"storage_registry"` //TODO: should we even support switching this? + StorageRegistry StorageRegistry `yaml:"storage_registry"` // TODO: should we even support switching this? Supervised bool `yaml:"-"` Context context.Context `yaml:"-"` } -type Tracing struct { - Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;GATEWAY_TRACING_ENABLED" desc:"Activates tracing."` - Type string `yaml:"type" env:"OCIS_TRACING_TYPE;GATEWAY_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;GATEWAY_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` - Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;GATEWAY_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."` -} type Log struct { Level string `yaml:"level" env:"OCIS_LOG_LEVEL;GATEWAY_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'."` @@ -81,9 +75,9 @@ type GRPCConfig struct { } type StorageRegistry struct { - Driver string `yaml:"driver"` //TODO: configure via env? - Rules []string `yaml:"rules"` //TODO: configure via env? - JSON string `yaml:"json"` //TODO: configure via env? + Driver string `yaml:"driver"` // TODO: configure via env? + Rules []string `yaml:"rules"` // TODO: configure via env? + JSON string `yaml:"json"` // TODO: configure via env? StorageUsersMountID string `yaml:"storage_users_mount_id" env:"GATEWAY_STORAGE_USERS_MOUNT_ID" desc:"Mount ID of this storage. Admins can set the ID for the storage in this config option manually which is then used to reference the storage. Any reasonable long string is possible, preferably this would be an UUIDv4 format."` } diff --git a/services/gateway/pkg/config/tracing.go b/services/gateway/pkg/config/tracing.go new file mode 100644 index 0000000000..de33a127d4 --- /dev/null +++ b/services/gateway/pkg/config/tracing.go @@ -0,0 +1,21 @@ +package config + +import "github.com/owncloud/ocis/v2/ocis-pkg/tracing" + +// Tracing defines the configuration options for tracing. +type Tracing struct { + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;GATEWAY_TRACING_ENABLED" desc:"Activates tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;GATEWAY_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;GATEWAY_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;GATEWAY_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."` +} + +// Convert Tracing to the tracing package's Config struct. +func (t Tracing) Convert() tracing.Config { + return tracing.Config{ + Enabled: t.Enabled, + Type: t.Type, + Endpoint: t.Endpoint, + Collector: t.Collector, + } +} diff --git a/services/gateway/pkg/tracing/tracing.go b/services/gateway/pkg/tracing/tracing.go deleted file mode 100644 index 82af583167..0000000000 --- a/services/gateway/pkg/tracing/tracing.go +++ /dev/null @@ -1,18 +0,0 @@ -package tracing - -import ( - "github.com/owncloud/ocis/v2/ocis-pkg/log" - "github.com/owncloud/ocis/v2/ocis-pkg/tracing" - "github.com/owncloud/ocis/v2/services/gateway/pkg/config" - "go.opentelemetry.io/otel/trace" -) - -var ( - // TraceProvider is the global trace provider for the service. - TraceProvider = trace.NewNoopTracerProvider() -) - -func Configure(cfg *config.Config, logger log.Logger) error { - tracing.Configure(cfg.Tracing.Enabled, cfg.Tracing.Type, logger) - return nil -}