From 858ddfbc07399f92696dadc7c0ca63a0bcffb57b Mon Sep 17 00:00:00 2001 From: Sean ZO Marciniak Date: Thu, 20 May 2021 10:21:33 +1000 Subject: [PATCH 1/5] Adding support for future dynmaic encoding In order to make the transition from only jaeger traces to otlp data being written to kinesis, we've split up our approach and made sure it does not introduce breaking changes. --- .../awskinesisexporter/encoding/encoder.go | 21 ++++++++++ .../encoding/encoder_jaeger.go | 42 +++++++++++++++++++ exporter/awskinesisexporter/exporter.go | 26 +++--------- exporter/awskinesisexporter/factory.go | 7 +++- 4 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 exporter/awskinesisexporter/encoding/encoder.go create mode 100644 exporter/awskinesisexporter/encoding/encoder_jaeger.go diff --git a/exporter/awskinesisexporter/encoding/encoder.go b/exporter/awskinesisexporter/encoding/encoder.go new file mode 100644 index 000000000000..42f8a33769f2 --- /dev/null +++ b/exporter/awskinesisexporter/encoding/encoder.go @@ -0,0 +1,21 @@ +package encoding + +import ( + "errors" + + "go.opentelemetry.io/collector/consumer/pdata" +) + +var ( + ErrUnsupportedEncodedType = errors.New("unsupport type to encode") +) + +// Encoder allows for the internal types to be converted to an consumable +// exported type which is written to the kinesis stream +type Encoder interface { + EncodeMetrics(md pdata.Metrics) error + + EncodeTraces(td pdata.Traces) error + + EncodeLogs(ld pdata.Logs) error +} diff --git a/exporter/awskinesisexporter/encoding/encoder_jaeger.go b/exporter/awskinesisexporter/encoding/encoder_jaeger.go new file mode 100644 index 000000000000..4b87e1f53e1d --- /dev/null +++ b/exporter/awskinesisexporter/encoding/encoder_jaeger.go @@ -0,0 +1,42 @@ +package encoding + +import ( + awskinesis "github.com/signalfx/opencensus-go-exporter-kinesis" + "go.opentelemetry.io/collector/consumer/pdata" + jaegertranslator "go.opentelemetry.io/collector/translator/trace/jaeger" +) + +type jaeger struct { + kinesis *awskinesis.Exporter +} + +// Ensure the jaeger encoder meets the interface at compile time. +var _ Encoder = (*jaeger)(nil) + +func Jaeger(kinesis *awskinesis.Exporter) Encoder { + return &jaeger{kinesis: kinesis} +} + +func (j *jaeger) EncodeTraces(td pdata.Traces) error { + traces, err := jaegertranslator.InternalTracesToJaegerProto(td) + if err != nil { + return err + } + + for _, trace := range traces { + for _, span := range trace.GetSpans() { + if span.Process == nil { + span.Process = trace.Process + } + if err := j.kinesis.ExportSpan(span); err != nil { + return err + } + } + } + + return nil +} + +func (j *jaeger) EncodeMetrics(_ pdata.Metrics) error { return ErrUnsupportedEncodedType } + +func (j *jaeger) EncodeLogs(_ pdata.Logs) error { return ErrUnsupportedEncodedType } diff --git a/exporter/awskinesisexporter/exporter.go b/exporter/awskinesisexporter/exporter.go index 26cbd69ab1de..7129136d6b6c 100644 --- a/exporter/awskinesisexporter/exporter.go +++ b/exporter/awskinesisexporter/exporter.go @@ -20,15 +20,16 @@ import ( awskinesis "github.com/signalfx/opencensus-go-exporter-kinesis" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" - jaegertranslator "go.opentelemetry.io/collector/translator/trace/jaeger" "go.uber.org/zap" + + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/encoding" ) // Exporter implements an OpenTelemetry trace exporter that exports all spans to AWS Kinesis type Exporter struct { awskinesis *awskinesis.Exporter + encoder encoding.Encoder logger *zap.Logger } @@ -55,24 +56,9 @@ func (e Exporter) Shutdown(context.Context) error { // ConsumeTraces receives a span batch and exports it to AWS Kinesis func (e Exporter) ConsumeTraces(_ context.Context, td pdata.Traces) error { - pBatches, err := jaegertranslator.InternalTracesToJaegerProto(td) + err := e.encoder.EncodeTraces(td) if err != nil { - e.logger.Error("error translating span batch", zap.Error(err)) - return consumererror.Permanent(err) - } - // TODO: Use a multi error type - var exportErr error - for _, pBatch := range pBatches { - for _, span := range pBatch.GetSpans() { - if span.Process == nil { - span.Process = pBatch.Process - } - err := e.awskinesis.ExportSpan(span) - if err != nil { - e.logger.Error("error exporting span to awskinesis", zap.Error(err)) - exportErr = err - } - } + e.logger.Error("Unable to write jaeger traces to kinesis", zap.Error(err)) } - return exportErr + return err } diff --git a/exporter/awskinesisexporter/factory.go b/exporter/awskinesisexporter/factory.go index e281e0a8bb92..6d453410299e 100644 --- a/exporter/awskinesisexporter/factory.go +++ b/exporter/awskinesisexporter/factory.go @@ -17,6 +17,7 @@ package awskinesisexporter import ( "context" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/encoding" awskinesis "github.com/signalfx/opencensus-go-exporter-kinesis" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" @@ -93,5 +94,9 @@ func createTracesExporter( return nil, err } - return Exporter{k, params.Logger}, nil + return Exporter{ + awskinesis: k, + encoder: encoding.Jaeger(k), + logger: params.Logger, + }, nil } From 08f90802f73ec10f0e83bb5af48f90735473fded Mon Sep 17 00:00:00 2001 From: Sean ZO Marciniak Date: Thu, 20 May 2021 10:49:11 +1000 Subject: [PATCH 2/5] Adding in trivial tests for the jaeger encoder Adding in tests for the encoder to ensure the expected errors are being raised. --- .../awskinesisexporter/encoding/encoder.go | 2 +- .../encoding/encoder_jaeger.go | 3 +- .../encoding/encoder_jaeger_test.go | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 exporter/awskinesisexporter/encoding/encoder_jaeger_test.go diff --git a/exporter/awskinesisexporter/encoding/encoder.go b/exporter/awskinesisexporter/encoding/encoder.go index 42f8a33769f2..72130c0b6ec3 100644 --- a/exporter/awskinesisexporter/encoding/encoder.go +++ b/exporter/awskinesisexporter/encoding/encoder.go @@ -7,7 +7,7 @@ import ( ) var ( - ErrUnsupportedEncodedType = errors.New("unsupport type to encode") + ErrUnsupportedEncodedType = errors.New("unsupported type to encode") ) // Encoder allows for the internal types to be converted to an consumable diff --git a/exporter/awskinesisexporter/encoding/encoder_jaeger.go b/exporter/awskinesisexporter/encoding/encoder_jaeger.go index 4b87e1f53e1d..f26d3a234c65 100644 --- a/exporter/awskinesisexporter/encoding/encoder_jaeger.go +++ b/exporter/awskinesisexporter/encoding/encoder_jaeger.go @@ -38,5 +38,4 @@ func (j *jaeger) EncodeTraces(td pdata.Traces) error { } func (j *jaeger) EncodeMetrics(_ pdata.Metrics) error { return ErrUnsupportedEncodedType } - -func (j *jaeger) EncodeLogs(_ pdata.Logs) error { return ErrUnsupportedEncodedType } +func (j *jaeger) EncodeLogs(_ pdata.Logs) error { return ErrUnsupportedEncodedType } diff --git a/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go b/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go new file mode 100644 index 000000000000..8929f798d637 --- /dev/null +++ b/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go @@ -0,0 +1,28 @@ +package encoding_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/consumer/pdata" + + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/encoding" +) + +func TestEncodingTraceData(t *testing.T) { + t.Parallel() + + assert.NoError(t, encoding.Jaeger(nil).EncodeTraces(pdata.NewTraces()), "Must not error when processing spans") +} + +func TestEncodingMetricData(t *testing.T) { + t.Parallel() + + assert.Error(t, encoding.Jaeger(nil).EncodeMetrics(pdata.NewMetrics()), "Must error when trying to encode unsupported type") +} + +func TestEncodingLogData(t *testing.T) { + t.Parallel() + + assert.Error(t, encoding.Jaeger(nil).EncodeLogs(pdata.NewLogs()), "Must error when trying to encode unsupported type") +} From bae33b661cebe131f32ccdfc6cd0e1eb86f0daf7 Mon Sep 17 00:00:00 2001 From: Sean ZO Marciniak Date: Thu, 20 May 2021 17:35:08 +1000 Subject: [PATCH 3/5] Fixing linting issues --- exporter/awskinesisexporter/encoding/encoder.go | 1 + exporter/awskinesisexporter/factory.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/exporter/awskinesisexporter/encoding/encoder.go b/exporter/awskinesisexporter/encoding/encoder.go index 72130c0b6ec3..d0cb783fa4be 100644 --- a/exporter/awskinesisexporter/encoding/encoder.go +++ b/exporter/awskinesisexporter/encoding/encoder.go @@ -7,6 +7,7 @@ import ( ) var ( + // ErrUnsupportedEncodedType is used when the encoder type does not the type of encoding ErrUnsupportedEncodedType = errors.New("unsupported type to encode") ) diff --git a/exporter/awskinesisexporter/factory.go b/exporter/awskinesisexporter/factory.go index 6d453410299e..7654bcd594da 100644 --- a/exporter/awskinesisexporter/factory.go +++ b/exporter/awskinesisexporter/factory.go @@ -17,11 +17,12 @@ package awskinesisexporter import ( "context" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/encoding" awskinesis "github.com/signalfx/opencensus-go-exporter-kinesis" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/exporter/exporterhelper" + + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/encoding" ) const ( From 87ba534e835518718e303f29e32cbce45bc33ab1 Mon Sep 17 00:00:00 2001 From: Sean ZO Marciniak Date: Thu, 20 May 2021 19:16:40 +1000 Subject: [PATCH 4/5] Adding in license to files that are missing it --- exporter/awskinesisexporter/encoding/encoder.go | 14 ++++++++++++++ .../awskinesisexporter/encoding/encoder_jaeger.go | 14 ++++++++++++++ .../encoding/encoder_jaeger_test.go | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/exporter/awskinesisexporter/encoding/encoder.go b/exporter/awskinesisexporter/encoding/encoder.go index d0cb783fa4be..e975b1d0ab95 100644 --- a/exporter/awskinesisexporter/encoding/encoder.go +++ b/exporter/awskinesisexporter/encoding/encoder.go @@ -1,3 +1,17 @@ +// Copyright OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package encoding import ( diff --git a/exporter/awskinesisexporter/encoding/encoder_jaeger.go b/exporter/awskinesisexporter/encoding/encoder_jaeger.go index f26d3a234c65..bda0813a54ce 100644 --- a/exporter/awskinesisexporter/encoding/encoder_jaeger.go +++ b/exporter/awskinesisexporter/encoding/encoder_jaeger.go @@ -1,3 +1,17 @@ +// Copyright OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package encoding import ( diff --git a/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go b/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go index 8929f798d637..e710c7e72cd3 100644 --- a/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go +++ b/exporter/awskinesisexporter/encoding/encoder_jaeger_test.go @@ -1,3 +1,17 @@ +// Copyright OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package encoding_test import ( From d139b4b29adbed4b6542bb5480c511af2cfab56c Mon Sep 17 00:00:00 2001 From: Sean ZO Marciniak Date: Wed, 26 May 2021 22:44:08 +1000 Subject: [PATCH 5/5] Fixing typo in godoc --- exporter/awskinesisexporter/encoding/encoder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/awskinesisexporter/encoding/encoder.go b/exporter/awskinesisexporter/encoding/encoder.go index e975b1d0ab95..0da50a73a53c 100644 --- a/exporter/awskinesisexporter/encoding/encoder.go +++ b/exporter/awskinesisexporter/encoding/encoder.go @@ -21,7 +21,7 @@ import ( ) var ( - // ErrUnsupportedEncodedType is used when the encoder type does not the type of encoding + // ErrUnsupportedEncodedType is used when the encoder type does not support the type of encoding ErrUnsupportedEncodedType = errors.New("unsupported type to encode") )