-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor AWS Kinesis exporter to allow for extended types of encoding (…
…#3655) * 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. * Adding in trivial tests for the jaeger encoder Adding in tests for the encoder to ensure the expected errors are being raised. * Fixing linting issues * Adding in license to files that are missing it * Fixing typo in godoc * Moving translate package to be internal only. After some discussion on the PR, in order to keep things simple and easy to follow, encoding is moved to be internal/translate. * Fixing left over imports * Addressing original TODO and removing log line. * Fixing imports
- Loading branch information
1 parent
a95cdc0
commit dbfbffc
Showing
5 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
exporter/awskinesisexporter/internal/translate/translate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 translate | ||
|
||
import ( | ||
"errors" | ||
|
||
"go.opentelemetry.io/collector/consumer/pdata" | ||
) | ||
|
||
var ( | ||
// ErrUnsupportedEncodedType is used when the encoder type does not support the type of encoding | ||
ErrUnsupportedEncodedType = errors.New("unsupported type to encode") | ||
) | ||
|
||
// ExportWriter wraps the kinesis exporter and transforms the data into | ||
// the desired output format. | ||
type ExportWriter interface { | ||
WriteMetrics(md pdata.Metrics) error | ||
|
||
WriteTraces(td pdata.Traces) error | ||
|
||
WriteLogs(ld pdata.Logs) error | ||
} |
57 changes: 57 additions & 0 deletions
57
exporter/awskinesisexporter/internal/translate/translate_jaeger.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 translate | ||
|
||
import ( | ||
awskinesis "github.com/signalfx/opencensus-go-exporter-kinesis" | ||
"go.opentelemetry.io/collector/consumer/consumererror" | ||
"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 _ ExportWriter = (*jaeger)(nil) | ||
|
||
func JaegerExporter(kinesis *awskinesis.Exporter) ExportWriter { | ||
return &jaeger{kinesis: kinesis} | ||
} | ||
|
||
func (j *jaeger) WriteTraces(td pdata.Traces) error { | ||
traces, err := jaegertranslator.InternalTracesToJaegerProto(td) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var errs []error | ||
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 { | ||
errs = append(errs, err) | ||
} | ||
} | ||
} | ||
|
||
return consumererror.Combine(errs) | ||
} | ||
|
||
func (j *jaeger) WriteMetrics(_ pdata.Metrics) error { return ErrUnsupportedEncodedType } | ||
func (j *jaeger) WriteLogs(_ pdata.Logs) error { return ErrUnsupportedEncodedType } |
42 changes: 42 additions & 0 deletions
42
exporter/awskinesisexporter/internal/translate/translate_jaeger_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 translate_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/consumer/pdata" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/internal/translate" | ||
) | ||
|
||
func TestEncodingTraceData(t *testing.T) { | ||
t.Parallel() | ||
|
||
assert.NoError(t, translate.JaegerExporter(nil).WriteTraces(pdata.NewTraces()), "Must not error when processing spans") | ||
} | ||
|
||
func TestEncodingMetricData(t *testing.T) { | ||
t.Parallel() | ||
|
||
assert.Error(t, translate.JaegerExporter(nil).WriteMetrics(pdata.NewMetrics()), "Must error when trying to encode unsupported type") | ||
} | ||
|
||
func TestEncodingLogData(t *testing.T) { | ||
t.Parallel() | ||
|
||
assert.Error(t, translate.JaegerExporter(nil).WriteLogs(pdata.NewLogs()), "Must error when trying to encode unsupported type") | ||
} |