Skip to content

Commit

Permalink
Merge pull request #2457 from owncloud/fix-2453
Browse files Browse the repository at this point in the history
  • Loading branch information
refs authored Sep 3, 2021
2 parents dff0ea4 + 8ba432e commit 859aab8
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 37 deletions.
6 changes: 4 additions & 2 deletions accounts/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "accounts"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "accounts", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions glauth/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "glauth"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "glauth", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/owncloud/ocis
go 1.16

require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1 // indirect
github.com/CiscoM31/godata v1.0.4
github.com/GeertJohan/yubigo v0.0.0-20190917122436-175bc097e60e
github.com/asim/go-micro/plugins/client/grpc/v3 v3.0.0-20210812172626-c7195aae9817
Expand All @@ -20,11 +21,12 @@ require (
github.com/blevesearch/bleve/v2 v2.1.0
github.com/coreos/go-oidc/v3 v3.0.0
github.com/cs3org/go-cs3apis v0.0.0-20210812121411-f18cf19614e8
github.com/cs3org/reva v1.12.1-0.20210901093814-b54f42d242fd
github.com/cs3org/reva v1.12.1-0.20210903075054-73f10ed5ab21
github.com/disintegration/imaging v1.6.2
github.com/glauth/glauth v1.1.3-0.20210729125545-b9aecdfcac31
github.com/go-chi/chi/v5 v5.0.3
github.com/go-chi/render v1.0.1
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-logr/logr v0.4.0
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/gofrs/uuid v4.0.0+incompatible
Expand All @@ -34,6 +36,7 @@ require (
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/iancoleman/strcase v0.2.0
github.com/justinas/alice v1.2.0
github.com/libregraph/lico v0.34.1-0.20210803054646-b584e0372224
Expand All @@ -60,6 +63,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.22.0
go.opentelemetry.io/otel v1.0.0-RC2
go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC2
go.opentelemetry.io/otel/metric v0.20.0 // indirect
go.opentelemetry.io/otel/sdk v1.0.0-RC2
go.opentelemetry.io/otel/trace v1.0.0-RC2
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
Expand Down
120 changes: 117 additions & 3 deletions go.sum

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions graph-explorer/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "graph-explorer"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "graph-explorer", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions graph/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "graph"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "graph", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions idp/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "idp"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "idp", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
62 changes: 53 additions & 9 deletions ocis-pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tracing

import (
"fmt"
"net/url"
"strings"

"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/propagation"
Expand All @@ -17,18 +19,36 @@ var Propagator = propagation.NewCompositeTextMapPropagator(
)

// GetTraceProvider returns a configured open-telemetry trace provider.
func GetTraceProvider(collectorEndpoint, traceType, serviceName string) (*sdktrace.TracerProvider, error) {
func GetTraceProvider(agentEndpoint, collectorEndpoint, serviceName, traceType string) (*sdktrace.TracerProvider, error) {
switch t := traceType; t {
case "jaeger":
if collectorEndpoint == "" {
return sdktrace.NewTracerProvider(), nil
}

exp, err := jaeger.New(
jaeger.WithCollectorEndpoint(
jaeger.WithEndpoint(collectorEndpoint),
),
var (
exp *jaeger.Exporter
err error
)

if agentEndpoint != "" {
var agentHost string
var agentPort string

agentHost, agentPort, err = parseAgentConfig(agentEndpoint)
if err != nil {
return nil, err
}

exp, err = jaeger.New(
jaeger.WithAgentEndpoint(
jaeger.WithAgentHost(agentHost),
jaeger.WithAgentPort(agentPort),
),
)
} else if collectorEndpoint != "" {
exp, err = jaeger.New(
jaeger.WithCollectorEndpoint(
jaeger.WithEndpoint(collectorEndpoint),
),
)
}
if err != nil {
return nil, err
}
Expand All @@ -49,3 +69,27 @@ func GetTraceProvider(collectorEndpoint, traceType, serviceName string) (*sdktra
return nil, fmt.Errorf("invalid trace configuration")
}
}

func parseAgentConfig(ae string) (string, string, error) {
u, err := url.Parse(ae)
// as per url.go:
// [...] Trying to parse a hostname and path
// without a scheme is invalid but may not necessarily return an
// error, due to parsing ambiguities.
if err == nil && u.Hostname() != "" && u.Port() != "" {
return u.Hostname(), u.Port(), nil
}

p := strings.Split(ae, ":")
if len(p) != 2 {
return "", "", fmt.Errorf(fmt.Sprintf("invalid agent endpoint `%s`. expected format: `hostname:port`", ae))
}

switch {
case p[0] == "" && p[1] == "": // case ae = ":"
return "", "", fmt.Errorf(fmt.Sprintf("invalid agent endpoint `%s`. expected format: `hostname:port`", ae))
case p[0] == "":
return "", "", fmt.Errorf(fmt.Sprintf("invalid agent endpoint `%s`. expected format: `hostname:port`", ae))
}
return p[0], p[1], nil
}
77 changes: 77 additions & 0 deletions ocis-pkg/tracing/tracing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package tracing

import "testing"

func Test_parseAgentConfig(t *testing.T) {
type args struct {
ae string
}
tests := []struct {
name string
args args
want string
want1 string
wantErr bool
}{
{
name: "docker-style config",
args: args{
ae: "docker-jaeger:6666",
},
want: "docker-jaeger",
want1: "6666",
wantErr: false,
},
{
name: "agent in an url config",
args: args{
ae: "https://example-agent.com:6666",
},
want: "example-agent.com",
want1: "6666",
wantErr: false,
},
{
name: "agent as ipv4",
args: args{
ae: "127.0.0.1:6666",
},
want: "127.0.0.1",
want1: "6666",
wantErr: false,
},
{
name: "no hostname config should error",
args: args{
ae: ":6666",
},
want: "",
want1: "",
wantErr: true,
},
{
name: "no hostname nor port but separator should error",
args: args{
ae: ":",
},
want: "",
want1: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := parseAgentConfig(tt.args.ae)
if (err != nil) != tt.wantErr {
t.Errorf("parseAgentConfig() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("parseAgentConfig() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("parseAgentConfig() got1 = %v, want %v", got1, tt.want1)
}
})
}
}
6 changes: 4 additions & 2 deletions ocs/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "ocs"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "ocs", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions proxy/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "proxy"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "proxy", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions settings/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "settings"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "settings", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions store/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "store"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "store", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions thumbnails/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "thumbnails"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "thumbnails", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions web/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "web"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "web", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions webdav/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var (

func Configure(cfg *config.Config) error {
var err error
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Collector, cfg.Tracing.Type, "webdav"); err != nil {
return err
if cfg.Tracing.Enabled {
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "webdav", cfg.Tracing.Type); err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 859aab8

Please sign in to comment.