refactor proxy tracing config
This commit is contained in:
@@ -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,90 +58,8 @@ 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 {
|
return err
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user