From af0917736f39d0884347cb7e98fdb42dff18745b Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 3 Nov 2023 10:38:13 -0700 Subject: [PATCH] [chore] update testbed to embed jaeger exporter (#28880) Rather than importing a deprecated module, this embeds the contents of that module in the testbed. Part of #28647 Signed-off-by: Alex Boten --- cmd/oteltestbedcol/builder-config.yaml | 1 - cmd/oteltestbedcol/components.go | 2 - cmd/oteltestbedcol/go.mod | 1 - cmd/oteltestbedcol/go.sum | 2 - testbed/datasenders/jaeger.go | 147 +++++++++++++++++++++++-- testbed/go.mod | 5 +- testbed/go.sum | 2 - 7 files changed, 137 insertions(+), 23 deletions(-) diff --git a/cmd/oteltestbedcol/builder-config.yaml b/cmd/oteltestbedcol/builder-config.yaml index 5dbb3584d10d..351b43f8160a 100644 --- a/cmd/oteltestbedcol/builder-config.yaml +++ b/cmd/oteltestbedcol/builder-config.yaml @@ -18,7 +18,6 @@ exporters: - gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.88.1-0.20231026220224-6405e152a2d9 - gomod: go.opentelemetry.io/collector/exporter/otlphttpexporter v0.88.1-0.20231026220224-6405e152a2d9 - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter v0.88.0 - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0 - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter v0.88.0 - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.88.0 - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter v0.88.0 diff --git a/cmd/oteltestbedcol/components.go b/cmd/oteltestbedcol/components.go index 2a262be988de..fe3453ea9c6f 100644 --- a/cmd/oteltestbedcol/components.go +++ b/cmd/oteltestbedcol/components.go @@ -20,7 +20,6 @@ import ( otlpreceiver "go.opentelemetry.io/collector/receiver/otlpreceiver" carbonexporter "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter" - jaegerexporter "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter" opencensusexporter "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter" prometheusexporter "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter" sapmexporter "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter" @@ -86,7 +85,6 @@ func components() (otelcol.Factories, error) { otlpexporter.NewFactory(), otlphttpexporter.NewFactory(), carbonexporter.NewFactory(), - jaegerexporter.NewFactory(), opencensusexporter.NewFactory(), prometheusexporter.NewFactory(), sapmexporter.NewFactory(), diff --git a/cmd/oteltestbedcol/go.mod b/cmd/oteltestbedcol/go.mod index fe123143331e..0fef7baa228f 100644 --- a/cmd/oteltestbedcol/go.mod +++ b/cmd/oteltestbedcol/go.mod @@ -6,7 +6,6 @@ go 1.20 require ( github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter v0.88.0 - github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter v0.88.0 diff --git a/cmd/oteltestbedcol/go.sum b/cmd/oteltestbedcol/go.sum index 0f188e7b81aa..c5e8ba02d382 100644 --- a/cmd/oteltestbedcol/go.sum +++ b/cmd/oteltestbedcol/go.sum @@ -485,8 +485,6 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0 h1:NyqJDAgm3VC1UNrTW0gv2auQoTlaCEcit5c0On0oYG4= -github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0/go.mod h1:F8TX5dXc8VcF789x8UAu1fIWta16sGZMxhfGLNes+L8= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI= diff --git a/testbed/datasenders/jaeger.go b/testbed/datasenders/jaeger.go index 2c07aca4df8e..c904f8859163 100644 --- a/testbed/datasenders/jaeger.go +++ b/testbed/datasenders/jaeger.go @@ -5,15 +5,28 @@ package datasenders // import "github.com/open-telemetry/opentelemetry-collector import ( "context" + "errors" "fmt" + "sync" + "time" + jaegerproto "github.com/jaegertracing/jaeger/proto-gen/api_v2" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/exporter/exportertest" + "go.opentelemetry.io/collector/pdata/ptrace" "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed" ) @@ -35,20 +48,10 @@ func NewJaegerGRPCDataSender(host string, port int) testbed.TraceDataSender { } func (je *jaegerGRPCDataSender) Start() error { - factory := jaegerexporter.NewFactory() - cfg := factory.CreateDefaultConfig().(*jaegerexporter.Config) - // Disable retries, we should push data and if error just log it. - cfg.RetrySettings.Enabled = false - // Disable sending queue, we should push data from the caller goroutine. - cfg.QueueSettings.Enabled = false - cfg.Endpoint = je.GetEndpoint().String() - cfg.TLSSetting = configtls.TLSClientSetting{ - Insecure: true, - } params := exportertest.NewNopCreateSettings() params.Logger = zap.L() - exp, err := factory.CreateTracesExporter(context.Background(), params, cfg) + exp, err := je.newTracesExporter(params) if err != nil { return err } @@ -68,3 +71,123 @@ func (je *jaegerGRPCDataSender) GenConfigYAMLStr() string { func (je *jaegerGRPCDataSender) ProtocolName() string { return "jaeger" } + +// Config defines configuration for Jaeger gRPC exporter. +type jaegerConfig struct { + exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. + exporterhelper.QueueSettings `mapstructure:"sending_queue"` + exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` + + configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. +} + +var _ component.Config = (*jaegerConfig)(nil) + +// Validate checks if the exporter configuration is valid +func (cfg *jaegerConfig) Validate() error { + if cfg.Endpoint == "" { + return errors.New("must have a non-empty \"endpoint\"") + } + return nil +} + +// newTracesExporter returns a new Jaeger gRPC exporter. +// The exporter name is the name to be used in the observability of the exporter. +// The collectorEndpoint should be of the form "hostname:14250" (a gRPC target). +func (je *jaegerGRPCDataSender) newTracesExporter(set exporter.CreateSettings) (exporter.Traces, error) { + cfg := jaegerConfig{} + cfg.Endpoint = je.GetEndpoint().String() + cfg.TLSSetting = configtls.TLSClientSetting{ + Insecure: true, + } + + s := &protoGRPCSender{ + name: set.ID.String(), + settings: set.TelemetrySettings, + metadata: metadata.New(nil), + waitForReady: cfg.WaitForReady, + connStateReporterInterval: time.Second, + stopCh: make(chan struct{}), + clientSettings: &cfg.GRPCClientSettings, + } + + return exporterhelper.NewTracesExporter( + context.TODO(), set, cfg, s.pushTraces, + exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}), + exporterhelper.WithStart(s.start), + exporterhelper.WithShutdown(s.shutdown), + ) +} + +// protoGRPCSender forwards spans encoded in the jaeger proto +// format, to a grpc server. +type protoGRPCSender struct { + name string + settings component.TelemetrySettings + client jaegerproto.CollectorServiceClient + metadata metadata.MD + waitForReady bool + + conn stateReporter + connStateReporterInterval time.Duration + + stopCh chan struct{} + stopped bool + stopLock sync.Mutex + clientSettings *configgrpc.GRPCClientSettings +} + +type stateReporter interface { + GetState() connectivity.State +} + +func (s *protoGRPCSender) pushTraces( + ctx context.Context, + td ptrace.Traces, +) error { + + batches, err := jaeger.ProtoFromTraces(td) + if err != nil { + return consumererror.NewPermanent(fmt.Errorf("failed to push trace data via Jaeger exporter: %w", err)) + } + + if s.metadata.Len() > 0 { + ctx = metadata.NewOutgoingContext(ctx, s.metadata) + } + + for _, batch := range batches { + _, err = s.client.PostSpans( + ctx, + &jaegerproto.PostSpansRequest{Batch: *batch}, grpc.WaitForReady(s.waitForReady)) + + if err != nil { + s.settings.Logger.Debug("failed to push trace data to Jaeger", zap.Error(err)) + return fmt.Errorf("failed to push trace data via Jaeger exporter: %w", err) + } + } + + return nil +} + +func (s *protoGRPCSender) shutdown(context.Context) error { + s.stopLock.Lock() + s.stopped = true + s.stopLock.Unlock() + close(s.stopCh) + return nil +} + +func (s *protoGRPCSender) start(ctx context.Context, host component.Host) error { + if s.clientSettings == nil { + return fmt.Errorf("client settings not found") + } + conn, err := s.clientSettings.ToClientConn(ctx, host, s.settings) + if err != nil { + return err + } + + s.client = jaegerproto.NewCollectorServiceClient(conn) + s.conn = conn + + return nil +} diff --git a/testbed/go.mod b/testbed/go.mod index 94e81561bc0d..d2dd3bcf905d 100644 --- a/testbed/go.mod +++ b/testbed/go.mod @@ -4,8 +4,8 @@ go 1.20 require ( github.com/fluent/fluent-logger-golang v1.9.0 + github.com/jaegertracing/jaeger v1.48.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter v0.88.0 - github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter v0.88.0 @@ -17,6 +17,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.0.0-00010101000000-000000000000 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.88.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.88.0 @@ -153,7 +154,6 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect github.com/ionos-cloud/sdk-go/v6 v6.1.8 // indirect - github.com/jaegertracing/jaeger v1.48.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect @@ -187,7 +187,6 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.88.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.88.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.88.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.88.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.88.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.88.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/signalfx v0.88.0 // indirect diff --git a/testbed/go.sum b/testbed/go.sum index d3533037df61..7dcfc5630f52 100644 --- a/testbed/go.sum +++ b/testbed/go.sum @@ -491,8 +491,6 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0 h1:NyqJDAgm3VC1UNrTW0gv2auQoTlaCEcit5c0On0oYG4= -github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.85.0/go.mod h1:F8TX5dXc8VcF789x8UAu1fIWta16sGZMxhfGLNes+L8= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=