From 063b05140f43f6933fd5675aa9424383429ebd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Franke?= Date: Fri, 28 Jul 2023 11:25:43 +0200 Subject: [PATCH] Convert storage-users to use service tracing. This converts the storage users service to use the service tracing provider. --- services/storage-users/pkg/command/server.go | 6 +++--- services/storage-users/pkg/config/config.go | 16 ++++---------- services/storage-users/pkg/config/tracing.go | 21 +++++++++++++++++++ .../storage-users/pkg/revaconfig/config.go | 5 ----- services/storage-users/pkg/tracing/tracing.go | 18 ---------------- 5 files changed, 28 insertions(+), 38 deletions(-) create mode 100644 services/storage-users/pkg/config/tracing.go delete mode 100644 services/storage-users/pkg/tracing/tracing.go diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index d7fa6b9863..abd06ac172 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -13,6 +13,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/sync" + "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/storage-users/pkg/config" "github.com/owncloud/ocis/v2/services/storage-users/pkg/config/parser" @@ -20,7 +21,6 @@ import ( "github.com/owncloud/ocis/v2/services/storage-users/pkg/logging" "github.com/owncloud/ocis/v2/services/storage-users/pkg/revaconfig" "github.com/owncloud/ocis/v2/services/storage-users/pkg/server/debug" - "github.com/owncloud/ocis/v2/services/storage-users/pkg/tracing" "github.com/urfave/cli/v2" ) @@ -35,7 +35,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 } @@ -52,6 +52,7 @@ func Server(cfg *config.Config) *cli.Command { runtime.RunWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), + runtime.WithTraceProvider(traceProvider), ) return nil @@ -69,7 +70,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/storage-users/pkg/config/config.go b/services/storage-users/pkg/config/config.go index cec4dcdf34..7c738792bf 100644 --- a/services/storage-users/pkg/config/config.go +++ b/services/storage-users/pkg/config/config.go @@ -43,14 +43,6 @@ type Config struct { Context context.Context `yaml:"-"` } -// Tracing configures the tracing -type Tracing struct { - Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_USERS_TRACING_ENABLED" desc:"Activates tracing."` - Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_USERS_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;STORAGE_USERS_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` - Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_USERS_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."` -} - // Log configures the logging type Log struct { Level string `yaml:"level" env:"OCIS_LOG_LEVEL;STORAGE_USERS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'."` @@ -139,7 +131,7 @@ type S3NGDriver struct { // GeneralSpaceAliasTemplate contains the template used to construct // the general space alias, eg: `{{.SpaceType}}/{{.SpaceName | replace " " "-" | lower}}` GeneralSpaceAliasTemplate string `yaml:"generalspacealias_template" env:"STORAGE_USERS_S3NG_GENERAL_SPACE_ALIAS_TEMPLATE" desc:"Template string to construct general space aliases."` - //ShareFolder defines the name of the folder jailing all shares + // ShareFolder defines the name of the folder jailing all shares ShareFolder string `yaml:"share_folder" env:"STORAGE_USERS_S3NG_SHARE_FOLDER" desc:"Name of the folder jailing all shares."` MaxAcquireLockCycles int `yaml:"max_acquire_lock_cycles" env:"STORAGE_USERS_S3NG_MAX_ACQUIRE_LOCK_CYCLES" desc:"When trying to lock files, ocis will try this amount of times to acquire the lock before failing. After each try it will wait for an increasing amount of time. Values of 0 or below will be ignored and the default value of 20 will be used."` LockCycleDurationFactor int `yaml:"lock_cycle_duration_factor" env:"STORAGE_USERS_S3NG_LOCK_CYCLE_DURATION_FACTOR" desc:"When trying to lock files, ocis will multiply the cycle with this factor and use it as a millisecond timeout. Values of 0 or below will be ignored and the default value of 30 will be used."` @@ -150,7 +142,7 @@ type S3NGDriver struct { type OwnCloudSQLDriver struct { // Root is the absolute path to the location of the data Root string `yaml:"root" env:"STORAGE_USERS_OWNCLOUDSQL_DATADIR" desc:"The directory where the filesystem storage will store SQL migration data. If not defined, the root directory derives from $OCIS_BASE_DATA_PATH:/storage/owncloud."` - //ShareFolder defines the name of the folder jailing all shares + // ShareFolder defines the name of the folder jailing all shares ShareFolder string `yaml:"share_folder" env:"STORAGE_USERS_OWNCLOUDSQL_SHARE_FOLDER" desc:"Name of the folder jailing all shares."` UserLayout string `yaml:"user_layout" env:"STORAGE_USERS_OWNCLOUDSQL_LAYOUT" desc:"Path layout to use to navigate into a users folder in an owncloud data directory"` UploadInfoDir string `yaml:"upload_info_dir" env:"STORAGE_USERS_OWNCLOUDSQL_UPLOADINFO_DIR" desc:"The directory where the filesystem will store uploads temporarily. If not defined, the root directory derives from $OCIS_BASE_DATA_PATH:/storage/uploadinfo."` @@ -251,7 +243,7 @@ type EOSDriver struct { UseKeytab bool `yaml:"user_keytab"` // gateway service to use for uid lookups GatewaySVC string `yaml:"gateway_svc"` - //ShareFolder defines the name of the folder jailing all shares + // ShareFolder defines the name of the folder jailing all shares ShareFolder string `yaml:"share_folder"` GRPCURI string UserLayout string @@ -261,7 +253,7 @@ type EOSDriver struct { type LocalDriver struct { // Root is the absolute path to the location of the data Root string `yaml:"root"` - //ShareFolder defines the name of the folder jailing all shares + // ShareFolder defines the name of the folder jailing all shares ShareFolder string `yaml:"share_folder"` UserLayout string `yaml:"user_layout"` } diff --git a/services/storage-users/pkg/config/tracing.go b/services/storage-users/pkg/config/tracing.go new file mode 100644 index 0000000000..0e8d152301 --- /dev/null +++ b/services/storage-users/pkg/config/tracing.go @@ -0,0 +1,21 @@ +package config + +import "github.com/owncloud/ocis/v2/ocis-pkg/tracing" + +// Tracing configures the tracing +type Tracing struct { + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_USERS_TRACING_ENABLED" desc:"Activates tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_USERS_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;STORAGE_USERS_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_USERS_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/storage-users/pkg/revaconfig/config.go b/services/storage-users/pkg/revaconfig/config.go index 851a38569a..dd4980bb4f 100644 --- a/services/storage-users/pkg/revaconfig/config.go +++ b/services/storage-users/pkg/revaconfig/config.go @@ -11,11 +11,6 @@ import ( func StorageUsersConfigFromStruct(cfg *config.Config) map[string]interface{} { rcfg := map[string]interface{}{ "core": map[string]interface{}{ - "tracing_enabled": cfg.Tracing.Enabled, - "tracing_exporter": cfg.Tracing.Type, - "tracing_endpoint": cfg.Tracing.Endpoint, - "tracing_collector": cfg.Tracing.Collector, - "tracing_service_name": cfg.Service.Name, "graceful_shutdown_timeout": cfg.GracefulShutdownTimeout, }, "shared": map[string]interface{}{ diff --git a/services/storage-users/pkg/tracing/tracing.go b/services/storage-users/pkg/tracing/tracing.go deleted file mode 100644 index 8a9fca7123..0000000000 --- a/services/storage-users/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/storage-users/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 -}