Merge pull request #1819 from owncloud/refactor-extensions

This commit is contained in:
Alex Unger
2021-03-26 13:01:35 +01:00
committed by GitHub
37 changed files with 2294 additions and 2567 deletions
+24 -98
View File
@@ -3,25 +3,18 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/flagset" "github.com/owncloud/ocis/accounts/pkg/flagset"
"github.com/owncloud/ocis/accounts/pkg/metrics" "github.com/owncloud/ocis/accounts/pkg/metrics"
"github.com/owncloud/ocis/accounts/pkg/server/grpc" "github.com/owncloud/ocis/accounts/pkg/server/grpc"
"github.com/owncloud/ocis/accounts/pkg/server/http" "github.com/owncloud/ocis/accounts/pkg/server/http"
svc "github.com/owncloud/ocis/accounts/pkg/service/v0" svc "github.com/owncloud/ocis/accounts/pkg/service/v0"
"go.opencensus.io/stats/view" "github.com/owncloud/ocis/accounts/pkg/tracing"
"go.opencensus.io/trace"
) )
// Server is the entry point for the server command. // Server is the entry point for the server command.
@@ -47,87 +40,13 @@ func Server(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { err := tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil { if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter) gr := run.Group{}
view.RegisterExporter(exporter) ctx, cancel := defineContext(cfg)
case "jaeger": mtrcs := metrics.New()
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) {
if cfg.Context == nil {
return context.WithCancel(context.Background())
}
return context.WithCancel(cfg.Context)
}()
mtrcs = metrics.New()
)
defer cancel() defer cancel()
@@ -139,37 +58,33 @@ func Server(cfg *config.Config) *cli.Command {
return err return err
} }
{ httpServer := http.Server(
server := http.Server( http.Config(cfg),
http.Logger(logger), http.Logger(logger),
http.Name(cfg.Server.Name), http.Name(cfg.Server.Name),
http.Context(ctx), http.Context(ctx),
http.Config(cfg),
http.Metrics(mtrcs), http.Metrics(mtrcs),
http.Handler(handler), http.Handler(handler),
) )
gr.Add(server.Run, func(_ error) { gr.Add(httpServer.Run, func(_ error) {
logger.Info().Str("server", "http").Msg("Shutting down server") logger.Info().Str("server", "http").Msg("shutting down server")
cancel() cancel()
}) })
}
{ grpcServer := grpc.Server(
server := grpc.Server( grpc.Config(cfg),
grpc.Logger(logger), grpc.Logger(logger),
grpc.Name(cfg.Server.Name), grpc.Name(cfg.Server.Name),
grpc.Context(ctx), grpc.Context(ctx),
grpc.Config(cfg),
grpc.Metrics(mtrcs), grpc.Metrics(mtrcs),
grpc.Handler(handler), grpc.Handler(handler),
) )
gr.Add(server.Run, func(_ error) { gr.Add(grpcServer.Run, func(_ error) {
logger.Info().Str("server", "grpc").Msg("Shutting down server") logger.Info().Str("server", "grpc").Msg("shutting down server")
cancel() cancel()
}) })
}
if !cfg.Supervised { if !cfg.Supervised {
sync.Trap(&gr, cancel) sync.Trap(&gr, cancel)
@@ -179,3 +94,14 @@ func Server(cfg *config.Config) *cli.Command {
}, },
} }
} }
// defineContext sets the context for the extension. If there is a context configured it will create a new child from it,
// if not, it will create a root context that can be cancelled.
func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) {
return func() (context.Context, context.CancelFunc) {
if cfg.Context == nil {
return context.WithCancel(context.Background())
}
return context.WithCancel(cfg.Context)
}()
}
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+5
View File
@@ -0,0 +1,5 @@
Enhancement: Tracing Refactor
Centralize tracing handling per extension.
https://github.com/owncloud/ocis/pull/1819
+9 -105
View File
@@ -3,32 +3,20 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/glauth/pkg/metrics"
"github.com/owncloud/ocis/glauth/pkg/crypto"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
glauthcfg "github.com/glauth/glauth/pkg/config" glauthcfg "github.com/glauth/glauth/pkg/config"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/glauth/pkg/config" "github.com/owncloud/ocis/glauth/pkg/config"
"github.com/owncloud/ocis/glauth/pkg/crypto"
"github.com/owncloud/ocis/glauth/pkg/flagset" "github.com/owncloud/ocis/glauth/pkg/flagset"
"github.com/owncloud/ocis/glauth/pkg/metrics"
"github.com/owncloud/ocis/glauth/pkg/server/debug" "github.com/owncloud/ocis/glauth/pkg/server/debug"
"github.com/owncloud/ocis/glauth/pkg/server/glauth" "github.com/owncloud/ocis/glauth/pkg/server/glauth"
"go.opencensus.io/stats/view" "github.com/owncloud/ocis/glauth/pkg/tracing"
"go.opencensus.io/trace" "github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/ocis-pkg/sync"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -53,102 +41,18 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter) gr := run.Group{}
view.RegisterExporter(exporter) ctx, cancel := func() (context.Context, context.CancelFunc) {
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) {
if cfg.Context == nil { if cfg.Context == nil {
return context.WithCancel(context.Background()) return context.WithCancel(context.Background())
} }
return context.WithCancel(cfg.Context) return context.WithCancel(cfg.Context)
}() }()
metrics = metrics.New() metrics := metrics.New()
)
defer cancel() defer cancel()
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/glauth/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+2 -91
View File
@@ -3,23 +3,16 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/graph-explorer/pkg/config" "github.com/owncloud/ocis/graph-explorer/pkg/config"
"github.com/owncloud/ocis/graph-explorer/pkg/flagset" "github.com/owncloud/ocis/graph-explorer/pkg/flagset"
"github.com/owncloud/ocis/graph-explorer/pkg/metrics" "github.com/owncloud/ocis/graph-explorer/pkg/metrics"
"github.com/owncloud/ocis/graph-explorer/pkg/server/debug" "github.com/owncloud/ocis/graph-explorer/pkg/server/debug"
"github.com/owncloud/ocis/graph-explorer/pkg/server/http" "github.com/owncloud/ocis/graph-explorer/pkg/server/http"
"github.com/owncloud/ocis/graph-explorer/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -45,89 +38,7 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
ServiceName: cfg.Tracing.Service,
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/graph-explorer/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+5 -94
View File
@@ -3,23 +3,16 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/graph/pkg/config" "github.com/owncloud/ocis/graph/pkg/config"
"github.com/owncloud/ocis/graph/pkg/flagset" "github.com/owncloud/ocis/graph/pkg/flagset"
"github.com/owncloud/ocis/graph/pkg/metrics" "github.com/owncloud/ocis/graph/pkg/metrics"
"github.com/owncloud/ocis/graph/pkg/server/debug" "github.com/owncloud/ocis/graph/pkg/server/debug"
"github.com/owncloud/ocis/graph/pkg/server/http" "github.com/owncloud/ocis/graph/pkg/server/http"
"github.com/owncloud/ocis/graph/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -45,100 +38,18 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter) gr := run.Group{}
view.RegisterExporter(exporter) ctx, cancel := func() (context.Context, context.CancelFunc) {
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
ServiceName: cfg.Tracing.Service,
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) {
if cfg.Context == nil { if cfg.Context == nil {
return context.WithCancel(context.Background()) return context.WithCancel(context.Background())
} }
return context.WithCancel(cfg.Context) return context.WithCancel(cfg.Context)
}() }()
mtrcs = metrics.New() mtrcs := metrics.New()
)
defer cancel() defer cancel()
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/graph/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+3 -99
View File
@@ -3,24 +3,16 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/idp/pkg/flagset" "github.com/owncloud/ocis/idp/pkg/flagset"
"github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/metrics"
"github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/debug"
"github.com/owncloud/ocis/idp/pkg/server/http" "github.com/owncloud/ocis/idp/pkg/server/http"
"go.opencensus.io/stats/view" "github.com/owncloud/ocis/idp/pkg/tracing"
"go.opencensus.io/trace" "github.com/owncloud/ocis/ocis-pkg/sync"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -58,95 +50,7 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
logger.Info().
Str("collector", cfg.Tracing.Collector).
Msg("Trace collector added")
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+3 -95
View File
@@ -3,24 +3,18 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/owncloud/ocis/ocs/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocs/pkg/config" "github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocs/pkg/flagset" "github.com/owncloud/ocis/ocs/pkg/flagset"
"github.com/owncloud/ocis/ocs/pkg/metrics" "github.com/owncloud/ocis/ocs/pkg/metrics"
"github.com/owncloud/ocis/ocs/pkg/server/debug" "github.com/owncloud/ocis/ocs/pkg/server/debug"
"github.com/owncloud/ocis/ocs/pkg/server/http" "github.com/owncloud/ocis/ocs/pkg/server/http"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -44,96 +38,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
logger.Info().
Str("collector", cfg.Tracing.Collector).
Msg("Trace collector added")
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) { ctx, cancel = func() (context.Context, context.CancelFunc) {
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocs/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+3 -89
View File
@@ -3,24 +3,18 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/owncloud/ocis/onlyoffice/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/onlyoffice/pkg/config" "github.com/owncloud/ocis/onlyoffice/pkg/config"
"github.com/owncloud/ocis/onlyoffice/pkg/flagset" "github.com/owncloud/ocis/onlyoffice/pkg/flagset"
"github.com/owncloud/ocis/onlyoffice/pkg/metrics" "github.com/owncloud/ocis/onlyoffice/pkg/metrics"
"github.com/owncloud/ocis/onlyoffice/pkg/server/debug" "github.com/owncloud/ocis/onlyoffice/pkg/server/debug"
"github.com/owncloud/ocis/onlyoffice/pkg/server/http" "github.com/owncloud/ocis/onlyoffice/pkg/server/http"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -44,90 +38,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
ServiceName: cfg.Tracing.Service,
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) { ctx, cancel = func() (context.Context, context.CancelFunc) {
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/onlyoffice/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+4 -94
View File
@@ -8,23 +8,15 @@ import (
"strings" "strings"
"time" "time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/proxy/pkg/user/backend"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/coreos/go-oidc" "github.com/coreos/go-oidc"
"github.com/justinas/alice" "github.com/justinas/alice"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
acc "github.com/owncloud/ocis/accounts/pkg/proto/v0" acc "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/conversions" "github.com/owncloud/ocis/ocis-pkg/conversions"
"github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/service/grpc" "github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/proxy/pkg/config" "github.com/owncloud/ocis/proxy/pkg/config"
"github.com/owncloud/ocis/proxy/pkg/cs3" "github.com/owncloud/ocis/proxy/pkg/cs3"
"github.com/owncloud/ocis/proxy/pkg/flagset" "github.com/owncloud/ocis/proxy/pkg/flagset"
@@ -33,10 +25,10 @@ import (
"github.com/owncloud/ocis/proxy/pkg/proxy" "github.com/owncloud/ocis/proxy/pkg/proxy"
"github.com/owncloud/ocis/proxy/pkg/server/debug" "github.com/owncloud/ocis/proxy/pkg/server/debug"
proxyHTTP "github.com/owncloud/ocis/proxy/pkg/server/http" proxyHTTP "github.com/owncloud/ocis/proxy/pkg/server/http"
"github.com/owncloud/ocis/proxy/pkg/tracing"
"github.com/owncloud/ocis/proxy/pkg/user/backend"
settings "github.com/owncloud/ocis/settings/pkg/proto/v0" settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
storepb "github.com/owncloud/ocis/store/pkg/proto/v0" storepb "github.com/owncloud/ocis/store/pkg/proto/v0"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@@ -66,92 +58,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
m = metrics.New() m = metrics.New()
) )
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/proxy/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+47 -81
View File
@@ -16,6 +16,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -32,55 +33,62 @@ func AuthBasic(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
tracing.Configure(cfg, logger)
if cfg.Tracing.Enabled { gr := run.Group{}
switch t := cfg.Tracing.Type; t { ctx, cancel := context.WithCancel(context.Background())
case "agent":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel() defer cancel()
// precreate folders // pre-create folders
if cfg.Reva.AuthProvider.Driver == "json" && cfg.Reva.AuthProvider.JSON != "" { if cfg.Reva.AuthProvider.Driver == "json" && cfg.Reva.AuthProvider.JSON != "" {
if err := os.MkdirAll(filepath.Dir(cfg.Reva.AuthProvider.JSON), os.FileMode(0700)); err != nil { if err := os.MkdirAll(filepath.Dir(cfg.Reva.AuthProvider.JSON), os.FileMode(0700)); err != nil {
return err return err
} }
} }
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
rcfg := authBasicConfigFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(rcfg, pidFile, runtime.WithLogger(&logger.Logger))
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.AuthBasic.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// authBasicConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func authBasicConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.AuthBasic.MaxCPUs, "max_cpus": cfg.Reva.AuthBasic.MaxCPUs,
@@ -125,49 +133,7 @@ func AuthBasic(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.AuthBasic.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// AuthBasicSutureService allows for the storage-authbasic command to be embedded and supervised by a suture supervisor tree. // AuthBasicSutureService allows for the storage-authbasic command to be embedded and supervised by a suture supervisor tree.
+49 -81
View File
@@ -15,6 +15,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -31,49 +32,59 @@ func AuthBearer(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
tracing.Configure(cfg, logger)
if cfg.Tracing.Enabled { gr := run.Group{}
switch t := cfg.Tracing.Type; t { ctx, cancel := context.WithCancel(context.Background())
case "agent":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel() defer cancel()
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
rcfg := authBearerConfigFromStruct(c, cfg)
rcfg := map[string]interface{}{ gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.AuthBearer.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", "debug").Msg("failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// authBearerConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func authBearerConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
return map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.AuthBearer.MaxCPUs, "max_cpus": cfg.Reva.AuthBearer.MaxCPUs,
"tracing_enabled": cfg.Tracing.Enabled, "tracing_enabled": cfg.Tracing.Enabled,
@@ -105,49 +116,6 @@ func AuthBearer(cfg *config.Config) *cli.Command {
}, },
}, },
} }
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.AuthBearer.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// AuthBearerSutureService allows for the storage-gateway command to be embedded and supervised by a suture supervisor tree. // AuthBearerSutureService allows for the storage-gateway command to be embedded and supervised by a suture supervisor tree.
+51 -83
View File
@@ -8,17 +8,17 @@ import (
"path" "path"
"strings" "strings"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/cs3org/reva/cmd/revad/runtime" "github.com/cs3org/reva/cmd/revad/runtime"
"github.com/gofrs/uuid" "github.com/gofrs/uuid"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/conversions" "github.com/owncloud/ocis/ocis-pkg/conversions"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -36,43 +36,14 @@ func Frontend(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger": gr := run.Group{}
logger.Info(). ctx, cancel := context.WithCancel(context.Background())
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New() //metrics = metrics.New()
)
defer cancel() defer cancel()
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
@@ -97,11 +68,55 @@ func Frontend(cfg *config.Config) *cli.Command {
"resumable": "1.0.0", "resumable": "1.0.0",
"extension": "creation,creation-with-upload", "extension": "creation,creation-with-upload",
"http_method_override": cfg.Reva.UploadHTTPMethodOverride, "http_method_override": cfg.Reva.UploadHTTPMethodOverride,
"max_chunk_size": int(cfg.Reva.UploadMaxChunkSize), "max_chunk_size": cfg.Reva.UploadMaxChunkSize,
} }
} }
rcfg := map[string]interface{}{ revaCfg := frontendConfigFromStruct(c, cfg, filesCfg)
gr.Add(func() error {
runtime.RunWithOptions(revaCfg, pidFile, runtime.WithLogger(&logger.Logger))
return nil
}, func(_ error) {
logger.Info().Str("server", c.Command.Name).Msg("Shutting down server")
cancel()
})
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Frontend.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().
Err(err).
Str("server", "debug").
Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.Frontend.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// frontendConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func frontendConfigFromStruct(c *cli.Context, cfg *config.Config, filesCfg map[string]interface{}) map[string]interface{} {
return map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.Users.MaxCPUs, "max_cpus": cfg.Reva.Users.MaxCPUs,
"tracing_enabled": cfg.Tracing.Enabled, "tracing_enabled": cfg.Tracing.Enabled,
@@ -229,53 +244,6 @@ func Frontend(cfg *config.Config) *cli.Command {
}, },
}, },
} }
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Frontend.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().
Err(err).
Str("server", "debug").
Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.Frontend.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// loadUserAgent reads the user-agent-whitelist-lock-in, since it is a string flag, and attempts to construct a map of // loadUserAgent reads the user-agent-whitelist-lock-in, since it is a string flag, and attempts to construct a map of
+63 -95
View File
@@ -7,6 +7,8 @@ import (
"path" "path"
"strings" "strings"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/cs3org/reva/cmd/revad/runtime" "github.com/cs3org/reva/cmd/revad/runtime"
@@ -39,48 +41,69 @@ func Gateway(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
tracing.Configure(cfg, logger)
if cfg.Tracing.Enabled { gr := run.Group{}
switch t := cfg.Tracing.Type; t { ctx, cancel := context.WithCancel(context.Background())
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel()
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
rcfg := gatewayConfigFromStruct(c, cfg)
defer cancel()
gr.Add(func() error {
err := external.RegisterGRPCEndpoint(
ctx,
"com.owncloud.storage",
uuid.String(),
cfg.Reva.Gateway.GRPCAddr,
logger,
)
if err != nil {
return err
}
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Gateway.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// gatewayConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.Users.MaxCPUs, "max_cpus": cfg.Reva.Users.MaxCPUs,
@@ -146,62 +169,7 @@ func Gateway(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
err := external.RegisterGRPCEndpoint(
ctx,
"com.owncloud.storage",
uuid.String(),
cfg.Reva.Gateway.GRPCAddr,
logger,
)
if err != nil {
return err
}
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Gateway.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
func rules(cfg *config.Config) map[string]interface{} { func rules(cfg *config.Config) map[string]interface{} {
+53 -82
View File
@@ -7,6 +7,8 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/cs3org/reva/cmd/revad/runtime" "github.com/cs3org/reva/cmd/revad/runtime"
@@ -33,55 +35,67 @@ func Groups(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
tracing.Configure(cfg, logger)
gr := run.Group{}
ctx, cancel := context.WithCancel(context.Background())
if cfg.Tracing.Enabled { // pre-create folders
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel()
// precreate folders
if cfg.Reva.Groups.Driver == "json" && cfg.Reva.Groups.JSON != "" { if cfg.Reva.Groups.Driver == "json" && cfg.Reva.Groups.JSON != "" {
if err := os.MkdirAll(filepath.Dir(cfg.Reva.Groups.JSON), os.FileMode(0700)); err != nil { if err := os.MkdirAll(filepath.Dir(cfg.Reva.Groups.JSON), os.FileMode(0700)); err != nil {
return err return err
} }
} }
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
defer cancel()
rcfg := map[string]interface{}{ rcfg := groupsConfigFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Users.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// groupsConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func groupsConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
return map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.Groups.MaxCPUs, "max_cpus": cfg.Reva.Groups.MaxCPUs,
"tracing_enabled": cfg.Tracing.Enabled, "tracing_enabled": cfg.Tracing.Enabled,
@@ -140,49 +154,6 @@ func Groups(cfg *config.Config) *cli.Command {
}, },
}, },
} }
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Users.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// GroupsProvider allows for the storage-groupsprovider command to be embedded and supervised by a suture supervisor tree. // GroupsProvider allows for the storage-groupsprovider command to be embedded and supervised by a suture supervisor tree.
+51 -81
View File
@@ -7,6 +7,8 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/cs3org/reva/cmd/revad/runtime" "github.com/cs3org/reva/cmd/revad/runtime"
@@ -34,39 +36,10 @@ func Sharing(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger": gr := run.Group{}
logger.Info(). ctx, cancel := context.WithCancel(context.Background())
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel() defer cancel()
@@ -82,11 +55,54 @@ func Sharing(cfg *config.Config) *cli.Command {
} }
} }
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
rcfg := sharingConfigFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debug, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Sharing.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(debug.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// sharingConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func sharingConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.Sharing.MaxCPUs, "max_cpus": cfg.Reva.Sharing.MaxCPUs,
@@ -129,53 +145,7 @@ func Sharing(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Sharing.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().
Err(err).
Str("server", c.Command.Name+"-debug").
Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// SharingSutureService allows for the storage-sharing command to be embedded and supervised by a suture supervisor tree. // SharingSutureService allows for the storage-sharing command to be embedded and supervised by a suture supervisor tree.
+50 -77
View File
@@ -16,6 +16,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -33,43 +34,12 @@ func StorageHome(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
gr := run.Group{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
@@ -81,6 +51,51 @@ func StorageHome(cfg *config.Config) *cli.Command {
cfg.Reva.Storages.OwnCloud.EnableHome = true cfg.Reva.Storages.OwnCloud.EnableHome = true
cfg.Reva.Storages.S3.EnableHome = true cfg.Reva.Storages.S3.EnableHome = true
} }
rcfg := storageHomeConfigFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StorageHome.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// storageHomeConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func storageHomeConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.StorageHome.MaxCPUs, "max_cpus": cfg.Reva.StorageHome.MaxCPUs,
@@ -125,49 +140,7 @@ func StorageHome(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StorageHome.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// StorageHomeSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree. // StorageHomeSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree.
+68 -94
View File
@@ -17,6 +17,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/service/external" "github.com/owncloud/ocis/storage/pkg/service/external"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -43,49 +44,19 @@ func StorageMetadata(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger": gr := run.Group{}
logger.Info(). ctx, cancel := func() (context.Context, context.CancelFunc) {
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) {
if cfg.Reva.StorageMetadata.Context == nil { if cfg.Reva.StorageMetadata.Context == nil {
return context.WithCancel(context.Background()) return context.WithCancel(context.Background())
} }
return context.WithCancel(cfg.Reva.StorageMetadata.Context) return context.WithCancel(cfg.Reva.StorageMetadata.Context)
}() }()
)
defer cancel() defer cancel()
{ pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid")
uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
// Disable home because the metadata is stored independently // Disable home because the metadata is stored independently
// of the user. This also means that a valid-token without any user-id // of the user. This also means that a valid-token without any user-id
@@ -96,6 +67,68 @@ func StorageMetadata(cfg *config.Config) *cli.Command {
cfg.Reva.Storages.OwnCloud.EnableHome = false cfg.Reva.Storages.OwnCloud.EnableHome = false
cfg.Reva.Storages.S3.EnableHome = false cfg.Reva.Storages.S3.EnableHome = false
rcfg := storageMetadataFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StorageMetadata.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().
Err(err).
Str("server", c.Command.Name+"-debug").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return debugServer.ListenAndServe()
}, func(_ error) {
_ = debugServer.Shutdown(ctx)
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
if err := external.RegisterGRPCEndpoint(
ctx,
"com.owncloud.storage.metadata",
uuid.Must(uuid.NewV4()).String(),
cfg.Reva.StorageMetadata.GRPCAddr,
logger,
); err != nil {
logger.Fatal().Err(err).Msg("failed to register the grpc endpoint")
}
return gr.Run()
},
}
}
// storageMetadataFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func storageMetadataFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.StorageMetadata.MaxCPUs, "max_cpus": cfg.Reva.StorageMetadata.MaxCPUs,
@@ -140,66 +173,7 @@ func StorageMetadata(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StorageMetadata.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().
Err(err).
Str("server", c.Command.Name+"-debug").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.ListenAndServe()
}, func(_ error) {
_ = server.Shutdown(ctx)
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
if err := external.RegisterGRPCEndpoint(
ctx,
"com.owncloud.storage.metadata",
uuid.Must(uuid.NewV4()).String(),
cfg.Reva.StorageMetadata.GRPCAddr,
logger,
); err != nil {
logger.Fatal().Err(err).Msg("failed to register the grpc endpoint")
}
return gr.Run()
},
}
} }
// SutureService allows for the storage-metadata command to be embedded and supervised by a suture supervisor tree. // SutureService allows for the storage-metadata command to be embedded and supervised by a suture supervisor tree.
+50 -81
View File
@@ -15,6 +15,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -27,47 +28,57 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
Category: "Extensions", Category: "Extensions",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
tracing.Configure(cfg, logger)
if cfg.Tracing.Enabled { gr := run.Group{}
switch t := cfg.Tracing.Type; t { ctx, cancel := context.WithCancel(context.Background())
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel() defer cancel()
{ pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid")
uuid := uuid.Must(uuid.NewV4()) rcfg := storagePublicLinkConfigFromStruct(c, cfg)
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StoragePublicLink.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// storagePublicLinkConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func storagePublicLinkConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.StoragePublicLink.MaxCPUs, "max_cpus": cfg.Reva.StoragePublicLink.MaxCPUs,
@@ -102,49 +113,7 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StoragePublicLink.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// StoragePublicLinkSutureService allows for the storage-public-link command to be embedded and supervised by a suture supervisor tree. // StoragePublicLinkSutureService allows for the storage-public-link command to be embedded and supervised by a suture supervisor tree.
+50 -76
View File
@@ -15,6 +15,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -32,43 +33,13 @@ func StorageUsers(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
case "jaeger": gr := run.Group{}
logger.Info(). ctx, cancel := context.WithCancel(context.Background())
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Storage only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel() defer cancel()
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
@@ -80,6 +51,51 @@ func StorageUsers(cfg *config.Config) *cli.Command {
cfg.Reva.Storages.OwnCloud.EnableHome = true cfg.Reva.Storages.OwnCloud.EnableHome = true
cfg.Reva.Storages.S3.EnableHome = true cfg.Reva.Storages.S3.EnableHome = true
} }
rcfg := storageUsersConfigFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StorageUsers.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// storageUsersConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func storageUsersConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.StorageUsers.MaxCPUs, "max_cpus": cfg.Reva.StorageUsers.MaxCPUs,
@@ -124,49 +140,7 @@ func StorageUsers(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.StorageUsers.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// StorageUsersSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree. // StorageUsersSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree.
+50 -76
View File
@@ -16,6 +16,7 @@ import (
"github.com/owncloud/ocis/storage/pkg/config" "github.com/owncloud/ocis/storage/pkg/config"
"github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/flagset"
"github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/server/debug"
"github.com/owncloud/ocis/storage/pkg/tracing"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
) )
@@ -33,39 +34,10 @@ func Users(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { tracing.Configure(cfg, logger)
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger": gr := run.Group{}
logger.Info(). ctx, cancel := context.WithCancel(context.Background())
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
//metrics = metrics.New()
)
defer cancel() defer cancel()
@@ -76,10 +48,54 @@ func Users(cfg *config.Config) *cli.Command {
} }
} }
{
uuid := uuid.Must(uuid.NewV4()) uuid := uuid.Must(uuid.NewV4())
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
rcfg := usersConfigFromStruct(c, cfg)
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
debugServer, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Users.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
cancel()
})
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
}
// usersConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func usersConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
rcfg := map[string]interface{}{ rcfg := map[string]interface{}{
"core": map[string]interface{}{ "core": map[string]interface{}{
"max_cpus": cfg.Reva.Users.MaxCPUs, "max_cpus": cfg.Reva.Users.MaxCPUs,
@@ -140,49 +156,7 @@ func Users(cfg *config.Config) *cli.Command {
}, },
}, },
} }
return rcfg
gr.Add(func() error {
runtime.RunWithOptions(
rcfg,
pidFile,
runtime.WithLogger(&logger.Logger),
)
return nil
}, func(_ error) {
logger.Info().
Str("server", c.Command.Name).
Msg("Shutting down server")
cancel()
})
}
{
server, err := debug.Server(
debug.Name(c.Command.Name+"-debug"),
debug.Addr(cfg.Reva.Users.DebugAddr),
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
cancel()
})
}
if !cfg.Reva.StorageMetadata.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()
},
}
} }
// UsersProviderService allows for the storage-userprovider command to be embedded and supervised by a suture supervisor tree. // UsersProviderService allows for the storage-userprovider command to be embedded and supervised by a suture supervisor tree.
+38
View File
@@ -0,0 +1,38 @@
package tracing
import (
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/storage/pkg/config"
)
// Configure for Reva serves only as informational / instructive log messages. Tracing config will be delegated directly
// to Reva services.
func Configure(cfg *config.Config, logger log.Logger) {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", t).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", t).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
}
+3 -92
View File
@@ -2,25 +2,18 @@ package command
import ( import (
"context" "context"
"time"
"github.com/owncloud/ocis/store/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/store/pkg/config" "github.com/owncloud/ocis/store/pkg/config"
"github.com/owncloud/ocis/store/pkg/flagset" "github.com/owncloud/ocis/store/pkg/flagset"
"github.com/owncloud/ocis/store/pkg/metrics" "github.com/owncloud/ocis/store/pkg/metrics"
"github.com/owncloud/ocis/store/pkg/server/debug" "github.com/owncloud/ocis/store/pkg/server/debug"
"github.com/owncloud/ocis/store/pkg/server/grpc" "github.com/owncloud/ocis/store/pkg/server/grpc"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -42,92 +35,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) { ctx, cancel = func() (context.Context, context.CancelFunc) {
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/store/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+3 -93
View File
@@ -3,24 +3,16 @@ package command
import ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go" "github.com/owncloud/ocis/ocis-pkg/sync"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/flagset" "github.com/owncloud/ocis/thumbnails/pkg/flagset"
"github.com/owncloud/ocis/thumbnails/pkg/metrics" "github.com/owncloud/ocis/thumbnails/pkg/metrics"
"github.com/owncloud/ocis/thumbnails/pkg/server/debug" "github.com/owncloud/ocis/thumbnails/pkg/server/debug"
"github.com/owncloud/ocis/thumbnails/pkg/server/grpc" "github.com/owncloud/ocis/thumbnails/pkg/server/grpc"
"go.opencensus.io/stats/view" "github.com/owncloud/ocis/thumbnails/pkg/tracing"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -41,92 +33,10 @@ func Server(cfg *config.Config) *cli.Command {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) { ctx, cancel = func() (context.Context, context.CancelFunc) {
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+3 -93
View File
@@ -5,24 +5,16 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"strings" "strings"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go" "github.com/owncloud/ocis/ocis-pkg/sync"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/web/pkg/config" "github.com/owncloud/ocis/web/pkg/config"
"github.com/owncloud/ocis/web/pkg/flagset" "github.com/owncloud/ocis/web/pkg/flagset"
"github.com/owncloud/ocis/web/pkg/metrics" "github.com/owncloud/ocis/web/pkg/metrics"
"github.com/owncloud/ocis/web/pkg/server/debug" "github.com/owncloud/ocis/web/pkg/server/debug"
"github.com/owncloud/ocis/web/pkg/server/http" "github.com/owncloud/ocis/web/pkg/server/http"
"go.opencensus.io/stats/view" "github.com/owncloud/ocis/web/pkg/tracing"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -55,92 +47,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
// actually read the contents of the config file and override defaults // actually read the contents of the config file and override defaults
if cfg.File != "" { if cfg.File != "" {
contents, err := ioutil.ReadFile(cfg.File) contents, err := ioutil.ReadFile(cfg.File)
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/web/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}
+3 -93
View File
@@ -3,24 +3,16 @@ package command
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
"github.com/oklog/run" "github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go" "github.com/owncloud/ocis/ocis-pkg/sync"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/webdav/pkg/config" "github.com/owncloud/ocis/webdav/pkg/config"
"github.com/owncloud/ocis/webdav/pkg/flagset" "github.com/owncloud/ocis/webdav/pkg/flagset"
"github.com/owncloud/ocis/webdav/pkg/metrics" "github.com/owncloud/ocis/webdav/pkg/metrics"
"github.com/owncloud/ocis/webdav/pkg/server/debug" "github.com/owncloud/ocis/webdav/pkg/server/debug"
"github.com/owncloud/ocis/webdav/pkg/server/http" "github.com/owncloud/ocis/webdav/pkg/server/http"
"go.opencensus.io/stats/view" "github.com/owncloud/ocis/webdav/pkg/tracing"
"go.opencensus.io/trace"
) )
// Server is the entrypoint for the server command. // Server is the entrypoint for the server command.
@@ -44,92 +36,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
logger := NewLogger(cfg) logger := NewLogger(cfg)
if cfg.Tracing.Enabled { if err := tracing.Configure(cfg, logger); err != nil {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err return err
} }
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var ( var (
gr = run.Group{} gr = run.Group{}
ctx, cancel = func() (context.Context, context.CancelFunc) { ctx, cancel = func() (context.Context, context.CancelFunc) {
+90
View File
@@ -0,0 +1,90 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/webdav/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}