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

Migrate jaeger to otel API #7547

Merged
merged 1 commit into from
Mar 12, 2024
Merged
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
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
github.com/sigstore/sigstore/pkg/signature/kms/gcp v1.8.1
github.com/sigstore/sigstore/pkg/signature/kms/hashivault v1.8.1
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
Expand Down Expand Up @@ -92,6 +92,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/kms v1.27.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.6 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
Expand All @@ -107,7 +108,7 @@ require (
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
Expand All @@ -133,7 +134,9 @@ require (
github.com/zeebo/errs v1.3.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.1 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 32 additions & 9 deletions pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ package tracing

import (
"context"
"encoding/base64"
"fmt"
"net/url"

"github.com/tektoncd/pipeline/pkg/apis/config"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
"go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
Expand All @@ -35,15 +39,14 @@ import (
)

type tracerProvider struct {
embedded.TracerProvider

service string
provider trace.TracerProvider
cfg *config.Tracing
username string
password string
logger *zap.SugaredLogger
// (#7464)noop.TracerProvider is added to implement embedded.TracerProvider
// for bumping to go.opentelemetry.io/otel/trace/v1.21.0.TracerProvider
noop.TracerProvider
}

func init() {
Expand Down Expand Up @@ -150,12 +153,32 @@ func createTracerProvider(service string, cfg *config.Tracing, user, pass string
if !cfg.Enabled {
return noop.NewTracerProvider(), nil
}
u, err := url.Parse(cfg.Endpoint)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jaeger exporter expected a complete URL path like http://website.com:port/path, while otlp exporter accepts host and path as separate arguments. This URL parsing is added to ensure that user experience has not changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmjayadeep question: why do we need the additional configuration and the config-tracing configmap when it seems like otel can be configured with env vars (https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp#pkg-overview)?

Should we just have one way to configure tracing? (the env vars seem to support more options too e.g. client certs etc. vs the config map which only supports basic auth)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dibyom, we have used env vars initially. Then we decided to move to configmap to make it consistent with how other configurations are managed in the project. Also, env variables requires the user to restart the controller when the configuration needs to be changed.
Env variables are still supported. We can also add more parameters in the configmap as needed.

if err != nil {
return nil, err
}

opts := []otlptracehttp.Option{
otlptracehttp.WithEndpoint(u.Host),
otlptracehttp.WithURLPath(u.Path),
}

if u.Scheme == "http" {
opts = append(opts, otlptracehttp.WithInsecure())
}

if user != "" && pass != "" {
creds := fmt.Sprintf("%s:%s", user, pass)
enc := base64.StdEncoding.EncodeToString([]byte(creds))
o := otlptracehttp.WithHeaders(map[string]string{
"Authorization": fmt.Sprintf("Basic %s", enc),
})
opts = append(opts, o)
}
Comment on lines +170 to +177
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an option to have a user with empty password?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I found during testing with jaeger and nginx is that if the username or password is configured to be empty, the server just ignores the whole authorization header. So no need to pass the header in code.


ctx := context.Background()
exp, err := otlptracehttp.New(ctx, opts...)

exp, err := jaeger.New(jaeger.WithCollectorEndpoint(
jaeger.WithEndpoint(cfg.Endpoint),
jaeger.WithUsername(user),
jaeger.WithPassword(pass),
))
if err != nil {
return nil, err
}
Expand Down
25 changes: 25 additions & 0 deletions vendor/github.com/cenkalti/backoff/v4/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/cenkalti/backoff/v4/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions vendor/github.com/cenkalti/backoff/v4/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions vendor/github.com/cenkalti/backoff/v4/backoff.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions vendor/github.com/cenkalti/backoff/v4/context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading