From 76088d2034be81e15bbe9ba760f295ebe002910f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Franke?= Date: Fri, 21 Jul 2023 12:34:09 +0200 Subject: [PATCH] Convert storage-publiclink to service tracing This converts the storage-publiclink service to the service tracing methods. --- .../storage-publiclink/pkg/command/server.go | 6 +++--- .../storage-publiclink/pkg/config/config.go | 6 ------ .../storage-publiclink/pkg/config/tracing.go | 21 +++++++++++++++++++ .../pkg/revaconfig/config.go | 7 ------- .../storage-publiclink/pkg/tracing/tracing.go | 18 ---------------- 5 files changed, 24 insertions(+), 34 deletions(-) create mode 100644 services/storage-publiclink/pkg/config/tracing.go delete mode 100644 services/storage-publiclink/pkg/tracing/tracing.go diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 9eb75d21d..42a8cbf81 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -12,13 +12,13 @@ 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-publiclink/pkg/config" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config/parser" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/logging" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/revaconfig" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/server/debug" - "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/tracing" "github.com/urfave/cli/v2" ) @@ -33,7 +33,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) + tracingProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } @@ -50,6 +50,7 @@ func Server(cfg *config.Config) *cli.Command { runtime.RunWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), + runtime.WithTraceProvider(tracingProvider), ) return nil @@ -67,7 +68,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-publiclink/pkg/config/config.go b/services/storage-publiclink/pkg/config/config.go index 965b916ee..572b650a5 100644 --- a/services/storage-publiclink/pkg/config/config.go +++ b/services/storage-publiclink/pkg/config/config.go @@ -25,12 +25,6 @@ type Config struct { Supervised bool `yaml:"-"` Context context.Context `yaml:"-"` } -type Tracing struct { - Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_PUBLICLINK_TRACING_ENABLED" desc:"Activates tracing."` - Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_PUBLICLINK_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_PUBLICLINK_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` - Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_PUBLICLINK_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;STORAGE_PUBLICLINK_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'."` diff --git a/services/storage-publiclink/pkg/config/tracing.go b/services/storage-publiclink/pkg/config/tracing.go new file mode 100644 index 000000000..6f3ea817c --- /dev/null +++ b/services/storage-publiclink/pkg/config/tracing.go @@ -0,0 +1,21 @@ +package config + +import "github.com/owncloud/ocis/v2/ocis-pkg/tracing" + +// Tracing defines the tracing config. +type Tracing struct { + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_PUBLICLINK_TRACING_ENABLED" desc:"Activates tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_PUBLICLINK_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_PUBLICLINK_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_PUBLICLINK_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-publiclink/pkg/revaconfig/config.go b/services/storage-publiclink/pkg/revaconfig/config.go index f4819236c..2b63e5d9e 100644 --- a/services/storage-publiclink/pkg/revaconfig/config.go +++ b/services/storage-publiclink/pkg/revaconfig/config.go @@ -7,13 +7,6 @@ import ( // StoragePublicLinkConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service. func StoragePublicLinkConfigFromStruct(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, - }, "shared": map[string]interface{}{ "jwt_secret": cfg.TokenManager.JWTSecret, "gatewaysvc": cfg.Reva.Address, diff --git a/services/storage-publiclink/pkg/tracing/tracing.go b/services/storage-publiclink/pkg/tracing/tracing.go deleted file mode 100644 index 56551e597..000000000 --- a/services/storage-publiclink/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-publiclink/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 -}