Convert search service to use service tracing.
This converts the search service to use the service tracer. It also initialises the grpc service with a trace provider.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/config"
|
"github.com/owncloud/ocis/v2/services/search/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/search/pkg/config/parser"
|
||||||
@@ -14,7 +15,6 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/search/pkg/metrics"
|
"github.com/owncloud/ocis/v2/services/search/pkg/metrics"
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/server/debug"
|
"github.com/owncloud/ocis/v2/services/search/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/server/grpc"
|
"github.com/owncloud/ocis/v2/services/search/pkg/server/grpc"
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/tracing"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,11 +29,15 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||||
err := tracing.Configure(cfg)
|
traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ogrpc.Configure(append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(tracing.TraceProvider))...)
|
err = ogrpc.Configure(
|
||||||
|
append(ogrpc.GetClientOptions(cfg.GRPCClientTLS),
|
||||||
|
ogrpc.WithTraceProvider(traceProvider),
|
||||||
|
)...,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -57,6 +61,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
grpc.Context(ctx),
|
grpc.Context(ctx),
|
||||||
grpc.Metrics(mtrcs),
|
grpc.Metrics(mtrcs),
|
||||||
grpc.JWTSecret(cfg.TokenManager.JWTSecret),
|
grpc.JWTSecret(cfg.TokenManager.JWTSecret),
|
||||||
|
grpc.TraceProvider(traceProvider),
|
||||||
)
|
)
|
||||||
defer teardown()
|
defer teardown()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
|
|
||||||
// Tracing defines the available tracing configuration.
|
// Tracing defines the available tracing configuration.
|
||||||
type Tracing struct {
|
type Tracing struct {
|
||||||
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;SEARCH_TRACING_ENABLED" desc:"Activates tracing."`
|
Enabled bool `ocisConfig:"enabled" env:"OCIS_TRACING_ENABLED;SEARCH_TRACING_ENABLED" desc:"Activates tracing."`
|
||||||
@@ -7,3 +9,13 @@ type Tracing struct {
|
|||||||
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SEARCH_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."`
|
Endpoint string `ocisConfig:"endpoint" env:"OCIS_TRACING_ENDPOINT;SEARCH_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."`
|
||||||
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SEARCH_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."`
|
Collector string `ocisConfig:"collector" env:"OCIS_TRACING_COLLECTOR;SEARCH_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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/search/pkg/metrics"
|
"github.com/owncloud/ocis/v2/services/search/pkg/metrics"
|
||||||
svc "github.com/owncloud/ocis/v2/services/search/pkg/service/grpc/v0"
|
svc "github.com/owncloud/ocis/v2/services/search/pkg/service/grpc/v0"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option defines a single option function.
|
// Option defines a single option function.
|
||||||
@@ -15,14 +16,15 @@ type Option func(o *Options)
|
|||||||
|
|
||||||
// Options defines the available options for this package.
|
// Options defines the available options for this package.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Name string
|
Name string
|
||||||
Logger log.Logger
|
Logger log.Logger
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
Metrics *metrics.Metrics
|
Metrics *metrics.Metrics
|
||||||
Flags []cli.Flag
|
Flags []cli.Flag
|
||||||
Handler *svc.Service
|
Handler *svc.Service
|
||||||
JWTSecret string
|
JWTSecret string
|
||||||
|
TraceProvider trace.TracerProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// newOptions initializes the available default options.
|
// newOptions initializes the available default options.
|
||||||
@@ -91,3 +93,10 @@ func JWTSecret(val string) Option {
|
|||||||
o.JWTSecret = val
|
o.JWTSecret = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TraceProvider provides a function to set the trace provider option.
|
||||||
|
func TraceProvider(val trace.TracerProvider) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.TraceProvider = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func Server(opts ...Option) (grpc.Service, func(), error) {
|
|||||||
grpc.Logger(options.Logger),
|
grpc.Logger(options.Logger),
|
||||||
grpc.Flags(options.Flags...),
|
grpc.Flags(options.Flags...),
|
||||||
grpc.Version(version.GetString()),
|
grpc.Version(version.GetString()),
|
||||||
|
grpc.TraceProvider(options.TraceProvider),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
options.Logger.Fatal().Err(err).Msg("Error creating search service")
|
options.Logger.Fatal().Err(err).Msg("Error creating search service")
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package tracing
|
|
||||||
|
|
||||||
import (
|
|
||||||
pkgtrace "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/config"
|
|
||||||
"go.opentelemetry.io/otel/trace"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// TraceProvider is the global trace provider for the proxy service.
|
|
||||||
TraceProvider = trace.NewNoopTracerProvider()
|
|
||||||
)
|
|
||||||
|
|
||||||
func Configure(cfg *config.Config) error {
|
|
||||||
var err error
|
|
||||||
if cfg.Tracing.Enabled {
|
|
||||||
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user