Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt OpenTelemetry #2372

Merged
merged 37 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0e59776
remove tracing from ocis/ocis
refs Aug 6, 2021
6b1c8d1
add otel dependencies
refs Aug 6, 2021
8e5ef03
run go mod tidy
refs Aug 6, 2021
93f1338
add OCIS_TRACING_* flags to all extensions
refs Aug 6, 2021
9f50776
enable traces in proxy
refs Aug 6, 2021
9f96321
add tracing middleware to proxy middleware chain
refs Aug 6, 2021
feed3e5
add tracing middleware to ocs middleware chain
refs Aug 6, 2021
8301a7e
propagate trace from ocs to proxy
refs Aug 6, 2021
33b1524
Merge branch 'master' into remake-traces
refs Aug 6, 2021
2bdd07e
add test spans
refs Aug 6, 2021
43a97f6
remove redundant middleware
refs Aug 9, 2021
0eb403d
replace go.opencensus.io with opentelemetry
refs Aug 9, 2021
500a77f
Merge branch 'master' into remake-traces
refs Aug 9, 2021
45f29fd
replace go.opencensus.io with opentelemetry in idp
refs Aug 9, 2021
f5c3b49
replace go.opencensus.io with opentelemetry in store
refs Aug 9, 2021
2a60b6b
replace go.opencensus.io with opentelemetry in thumbnails
refs Aug 9, 2021
fe530e9
prevent having a nil traceprovider
refs Aug 9, 2021
ac087d0
replace opencensus everywhere
refs Aug 9, 2021
4a81795
fix middleware chain
refs Aug 9, 2021
6fc2b75
add tracing utils to ocis-pkg
refs Aug 9, 2021
b13863b
refactor traceprovider initialization
refs Aug 9, 2021
ad994de
more refactoring
refs Aug 9, 2021
1ed38e1
guard against unconfigured tracer
refs Aug 9, 2021
8a80b99
safer code
refs Aug 9, 2021
778ad71
config: add reva required config
refs Aug 12, 2021
8499187
add x-request-id to proxy root span
refs Aug 12, 2021
85848f1
Merge branch 'master' into remake-traces
refs Aug 12, 2021
6403e5c
go mod: tidy
refs Aug 12, 2021
e62a9b6
Merge branch 'master' into remake-traces
refs Aug 13, 2021
aac45a4
Merge branch 'master' into remake-traces
refs Aug 17, 2021
50381b2
remove deprecated config option
refs Aug 17, 2021
21e6aab
deps: update reva
refs Aug 17, 2021
a7d89c7
Merge branch 'master' into remake-traces
refs Aug 18, 2021
1dd4644
fix requestid
refs Aug 18, 2021
0f0d305
linter: fix var name
refs Aug 18, 2021
06fda51
Update proxy/pkg/middleware/accesslog.go
refs Aug 18, 2021
46f0d6f
remove dead code
refs Aug 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion accounts/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Server(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
err := tracing.Configure(cfg, logger)
err := tracing.Configure(cfg)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions accounts/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",
EnvVars: []string{"ACCOUNTS_TRACING_ENABLED"},
EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"},
Destination: &cfg.Tracing.Enabled,
},
&cli.StringFlag{
Name: "tracing-type",
Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"),
Usage: "Tracing backend type",
EnvVars: []string{"ACCOUNTS_TRACING_TYPE"},
EnvVars: []string{"ACCOUNTS_TRACING_TYPE", "OCIS_TRACING_TYPE"},
Destination: &cfg.Tracing.Type,
},
&cli.StringFlag{
Name: "tracing-endpoint",
Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""),
Usage: "Endpoint for the agent",
EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT"},
EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"},
Destination: &cfg.Tracing.Endpoint,
},
&cli.StringFlag{
Name: "tracing-collector",
Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""),
Usage: "Endpoint for the collector",
EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR"},
EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"},
Destination: &cfg.Tracing.Collector,
},
&cli.StringFlag{
Expand Down
1 change: 1 addition & 0 deletions accounts/pkg/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func Server(opts ...Option) http.Service {

mux.Use(chimiddleware.RealIP)
mux.Use(chimiddleware.RequestID)
mux.Use(middleware.TraceContext)
mux.Use(middleware.NoCache)
mux.Use(middleware.Cors)
mux.Use(middleware.Secure)
Expand Down
50 changes: 47 additions & 3 deletions accounts/pkg/service/v0/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (
"strconv"
"time"

"github.com/owncloud/ocis/ocis-pkg/sync"
"golang.org/x/crypto/bcrypt"
"go.opentelemetry.io/otel/trace"

"github.com/owncloud/ocis/ocis-pkg/log"
"go.opentelemetry.io/otel/attribute"

merrors "github.com/asim/go-micro/v3/errors"
"github.com/asim/go-micro/v3/metadata"
Expand All @@ -24,11 +23,15 @@ import (
fieldmask_utils "github.com/mennanov/fieldmask-utils"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/accounts/pkg/storage"
accTracing "github.com/owncloud/ocis/accounts/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/middleware"
"github.com/owncloud/ocis/ocis-pkg/roles"
"github.com/owncloud/ocis/ocis-pkg/sync"
settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
settings_svc "github.com/owncloud/ocis/settings/pkg/service/v0"
"github.com/rs/zerolog"
"golang.org/x/crypto/bcrypt"
"google.golang.org/genproto/protobuf/field_mask"
p "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -124,6 +127,15 @@ func (s Service) getInMemoryServiceUser() proto.Account {
// ListAccounts implements the AccountsServiceHandler interface
// the query contains account properties
func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest, out *proto.ListAccountsResponse) (err error) {
var span trace.Span
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.ListAccounts")
defer span.End()

span.SetAttributes(
attribute.KeyValue{Key: "page_size", Value: attribute.Int64Value(int64(in.PageSize))},
attribute.KeyValue{Key: "page_token", Value: attribute.StringValue(in.PageToken)},
)

hasSelf := s.hasSelfManagementPermissions(ctx)
hasManagement := s.hasAccountManagementPermissions(ctx)
if !hasSelf && !hasManagement {
Expand Down Expand Up @@ -269,6 +281,15 @@ func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]strin

// GetAccount implements the AccountsServiceHandler interface
func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, out *proto.Account) (err error) {
var span trace.Span

ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.GetAccount")
defer span.End()

span.SetAttributes(
attribute.KeyValue{Key: "account_id", Value: attribute.StringValue(in.Id)},
)

hasSelf := s.hasSelfManagementPermissions(ctx)
hasManagement := s.hasAccountManagementPermissions(ctx)
if !hasSelf && !hasManagement {
Expand Down Expand Up @@ -317,6 +338,15 @@ func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, ou

// CreateAccount implements the AccountsServiceHandler interface
func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountRequest, out *proto.Account) (err error) {
var span trace.Span

ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.CreateAccount")
defer span.End()

span.SetAttributes(
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
)

if !s.hasAccountManagementPermissions(ctx) {
return merrors.Forbidden(s.id, "no permission for CreateAccount")
}
Expand Down Expand Up @@ -449,6 +479,15 @@ func (s Service) rollbackCreateAccount(ctx context.Context, acc *proto.Account)
// read only fields are ignored
// TODO how can we unset specific values? using the update mask
func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountRequest, out *proto.Account) (err error) {
var span trace.Span

ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.UpdateAccount")
defer span.End()

span.SetAttributes(
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
)

hasSelf := s.hasSelfManagementPermissions(ctx)
hasManagement := s.hasAccountManagementPermissions(ctx)
if !hasSelf && !hasManagement {
Expand Down Expand Up @@ -615,6 +654,11 @@ var updatableAccountPaths = map[string]struct{}{

// DeleteAccount implements the AccountsServiceHandler interface
func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountRequest, out *empty.Empty) (err error) {
var span trace.Span

ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.DeleteAccount")
defer span.End()

if !s.hasAccountManagementPermissions(ctx) {
return merrors.Forbidden(s.id, "no permission for DeleteAccount")
}
Expand Down
76 changes: 0 additions & 76 deletions accounts/pkg/service/v0/tracing.go

This file was deleted.

93 changes: 12 additions & 81 deletions accounts/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
@@ -1,90 +1,21 @@
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"
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
"go.opentelemetry.io/otel/trace"
)

var (
// TraceProvider is the global trace provider for the proxy service.
TraceProvider = trace.NewNoopTracerProvider()
)

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")
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
}

return nil
}
2 changes: 1 addition & 1 deletion glauth/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

if err := tracing.Configure(cfg, logger); err != nil {
if err := tracing.Configure(cfg); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions glauth/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",
EnvVars: []string{"GLAUTH_TRACING_ENABLED"},
EnvVars: []string{"GLAUTH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"},
Destination: &cfg.Tracing.Enabled,
},
&cli.StringFlag{
Name: "tracing-type",
Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"),
Usage: "Tracing backend type",
EnvVars: []string{"GLAUTH_TRACING_TYPE"},
EnvVars: []string{"GLAUTH_TRACING_TYPE", "OCIS_TRACING_TYPE"},
Destination: &cfg.Tracing.Type,
},
&cli.StringFlag{
Name: "tracing-endpoint",
Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""),
Usage: "Endpoint for the agent",
EnvVars: []string{"GLAUTH_TRACING_ENDPOINT"},
EnvVars: []string{"GLAUTH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"},
Destination: &cfg.Tracing.Endpoint,
},
&cli.StringFlag{
Name: "tracing-collector",
Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""),
Usage: "Endpoint for the collector",
EnvVars: []string{"GLAUTH_TRACING_COLLECTOR"},
EnvVars: []string{"GLAUTH_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"},
Destination: &cfg.Tracing.Collector,
},
&cli.StringFlag{
Expand Down
Loading