Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Add opentelemetry instrumentation #502

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions cmd/controller/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"

"golang.org/x/sync/errgroup"

"k8s.io/client-go/rest"
Expand Down Expand Up @@ -119,6 +126,46 @@ func executeRootCmd(baseCtx context.Context, cfg *config2.Config) error {
labeled.SetMetricKeys(keys...)
}

// TODO - add opentelemetry exporter
f, err := os.Create("traces.txt")
if err != nil {
return err
}

telemetryExporter, err := stdouttrace.New(
stdouttrace.WithWriter(f),
stdouttrace.WithPrettyPrint(), // Use human-readable output.
stdouttrace.WithoutTimestamps(), // Do not print timestamps for the demo.
)
if err != nil {
return err
}

telemetryResource, _ := resource.Merge(
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("flytepropeller"), // TODO get these values from flytestdlib
semconv.ServiceVersionKey.String("v0.1.0"),
attribute.String("environment", "demo"),
),
)

tracerProvider := trace.NewTracerProvider(
trace.WithBatcher(telemetryExporter),
trace.WithResource(telemetryResource),
)

defer func() error {
if err := tracerProvider.Shutdown(context.Background()); err != nil {
logger.Fatalf(ctx, "failed to shutdown opentelemtry trace provider with err '%v'", err)
return err
}
return nil
}()

otel.SetTracerProvider(tracerProvider)

// Add the propeller subscope because the MetricsPrefix only has "flyte:" to get uniform collection of metrics.
propellerScope := promutils.NewScope(cfg.MetricsPrefix).NewSubScope("propeller").NewSubScope(cfg.LimitNamespace)
limitNamespace := ""
Expand Down
13 changes: 12 additions & 1 deletion events/admin_eventsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import (
"github.com/flyteorg/flytestdlib/fastcheck"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flytestdlib/promutils"
"github.com/flyteorg/flytestdlib/telemetryutils"
"github.com/golang/protobuf/proto"
"golang.org/x/time/rate"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"

"google.golang.org/grpc"
)

type adminEventSink struct {
Expand Down Expand Up @@ -126,7 +131,13 @@ func IDFromMessage(message proto.Message) ([]byte, error) {

func initializeAdminClientFromConfig(ctx context.Context) (client service.AdminServiceClient, err error) {
cfg := admin2.GetConfig(ctx)
clients, err := admin2.NewClientsetBuilder().WithConfig(cfg).Build(ctx)
tracerProvider := telemetryutils.GetTracerProvider("admin-client")
opt := grpc.WithUnaryInterceptor(
otelgrpc.UnaryClientInterceptor(
otelgrpc.WithTracerProvider(tracerProvider),
),
)
clients, err := admin2.NewClientsetBuilder().WithDialOptions(opt).WithConfig(cfg).Build(ctx)
if err != nil {
return nil, fmt.Errorf("failed to initialize clientset. Error: %w", err)
}
Expand Down
35 changes: 22 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.2
github.com/stretchr/testify v1.8.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.32.0
go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.11.1
go.opentelemetry.io/otel/sdk v1.11.1
go.opentelemetry.io/otel/trace v1.11.1
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
google.golang.org/grpc v1.46.0
google.golang.org/protobuf v1.28.0
Expand All @@ -43,12 +48,12 @@ require (
cloud.google.com/go/compute v1.6.1 // indirect
cloud.google.com/go/iam v0.3.0 // indirect
cloud.google.com/go/storage v1.22.0 // indirect
github.com/Azure/azure-sdk-for-go v62.3.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 // indirect
github.com/Azure/azure-sdk-for-go v63.4.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.25 // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
Expand All @@ -74,18 +79,19 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/flyteorg/stow v0.3.4 // indirect
github.com/flyteorg/stow v0.3.6 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.3.0 // indirect
github.com/googleapis/go-type-adapters v1.0.0 // indirect
Expand Down Expand Up @@ -118,13 +124,14 @@ require (
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.11.0 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.11.1 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
Expand All @@ -146,3 +153,5 @@ require (
)

replace github.com/aws/amazon-sagemaker-operator-for-k8s => github.com/aws/amazon-sagemaker-operator-for-k8s v1.0.1-0.20210303003444-0fb33b1fd49d

replace github.com/flyteorg/flytestdlib => ../flytestdlib
Loading