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

[exporter/tanzuobservability] Unexport private funcs and types #4306

Merged
merged 1 commit into from Jul 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions exporter/tanzuobservabilityexporter/exporter.go
Expand Up @@ -101,7 +101,7 @@ func (e *tracesExporter) pushTraceData(ctx context.Context, td pdata.Traces) err
resource := rspans.Resource()
for j := 0; j < rspans.InstrumentationLibrarySpans().Len(); j++ {
ispans := rspans.InstrumentationLibrarySpans().At(j)
transform := newTraceTransformer(resource, e.cfg)
transform := newTraceTransformer(resource)
for k := 0; k < ispans.Spans().Len(); k++ {
select {
case <-ctx.Done():
Expand All @@ -113,7 +113,7 @@ func (e *tracesExporter) pushTraceData(ctx context.Context, td pdata.Traces) err
continue
}

if err := e.RecordSpan(transformedSpan); err != nil {
if err := e.recordSpan(transformedSpan); err != nil {
errs = append(errs, err)
continue
}
Expand All @@ -125,12 +125,7 @@ func (e *tracesExporter) pushTraceData(ctx context.Context, td pdata.Traces) err
return consumererror.Combine(errs)
}

func (e *tracesExporter) Shutdown(_ context.Context) error {
e.sender.Close()
return nil
}

func (e *tracesExporter) RecordSpan(span Span) error {
func (e *tracesExporter) recordSpan(span span) error {
var parents []string
if span.ParentSpanID != uuid.Nil {
parents = []string{span.ParentSpanID.String()}
Expand All @@ -155,6 +150,11 @@ func (e *tracesExporter) RecordSpan(span Span) error {
return e.sender.Flush()
}

func (e *tracesExporter) shutdown(_ context.Context) error {
e.sender.Close()
return nil
}

func mapToSpanTags(tags map[string]string) []senders.SpanTag {
var spanTags []senders.SpanTag
for k, v := range tags {
Expand Down
20 changes: 10 additions & 10 deletions exporter/tanzuobservabilityexporter/exporter_test.go
Expand Up @@ -46,15 +46,15 @@ func TestSpansRequireTraceAndSpanIDs(t *testing.T) {
func TestExportTraceDataMinimum(t *testing.T) {
// <operationName> source=<source> <spanTags> <start_milliseconds> <duration_milliseconds>
// getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459 spanId=0313bafe-9457-11e8-9eb6-529269fb1459 parent=2f64e538-9457-11e8-9eb6-529269fb1459 application=Wavefront service=auth cluster=us-west-2 shard=secondary http.method=GET 1552949776000 343
span := createSpan(
minSpan := createSpan(
"root",
pdata.NewTraceID([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}),
pdata.NewSpanID([8]byte{9, 9, 9, 9, 9, 9, 9, 9}),
pdata.SpanID{},
)
traces := constructTraces([]pdata.Span{span})
traces := constructTraces([]pdata.Span{minSpan})

expected := []*Span{{
expected := []*span{{
Name: "root",
TraceID: uuid.MustParse("01010101-0101-0101-0101-010101010101"),
SpanID: uuid.MustParse("00000000-0000-0000-0909-090909090909"),
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestExportTraceDataFullTrace(t *testing.T) {
resourceAttrs.InsertString(conventions.AttributeServiceName, "test-service")
resourceAttrs.CopyTo(traces.ResourceSpans().At(0).Resource().Attributes())

expected := []*Span{
expected := []*span{
{
Name: "root",
SpanID: uuid.MustParse("00000000000000000000000000000001"),
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestExportTraceDataFullTrace(t *testing.T) {
validateTraces(t, expected, traces)
}

func validateTraces(t *testing.T, expected []*Span, traces pdata.Traces) {
func validateTraces(t *testing.T, expected []*span, traces pdata.Traces) {
actual, err := consumeTraces(traces)
require.NoError(t, err)
require.Equal(t, len(expected), len(actual))
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestExportTraceDataRespectsContext(t *testing.T) {
cfg,
componenttest.NewNopExporterCreateSettings(),
exp.pushTraceData,
exporterhelper.WithShutdown(exp.Shutdown),
exporterhelper.WithShutdown(exp.shutdown),
)
require.NoError(t, err)

Expand Down Expand Up @@ -243,7 +243,7 @@ func constructTraces(spans []pdata.Span) pdata.Traces {
return traces
}

func consumeTraces(ptrace pdata.Traces) ([]*Span, error) {
func consumeTraces(ptrace pdata.Traces) ([]*span, error) {
ctx := context.Background()
sender := &mockSender{}

Expand All @@ -257,7 +257,7 @@ func consumeTraces(ptrace pdata.Traces) ([]*Span, error) {
cfg,
componenttest.NewNopExporterCreateSettings(),
exp.pushTraceData,
exporterhelper.WithShutdown(exp.Shutdown),
exporterhelper.WithShutdown(exp.shutdown),
)

if err != nil {
Expand All @@ -274,7 +274,7 @@ func consumeTraces(ptrace pdata.Traces) ([]*Span, error) {

// implements the spanSender interface
type mockSender struct {
spans []*Span
spans []*span
}

func (m *mockSender) SendSpan(
Expand All @@ -293,7 +293,7 @@ func (m *mockSender) SendSpan(
for _, pair := range spanTags {
tags[pair.Key] = pair.Value
}
span := &Span{
span := &span{
Name: name,
TraceID: uuid.MustParse(traceID),
SpanID: uuid.MustParse(spanID),
Expand Down
8 changes: 4 additions & 4 deletions exporter/tanzuobservabilityexporter/factory.go
Expand Up @@ -30,7 +30,7 @@ func NewFactory() component.ExporterFactory {
return exporterhelper.NewFactory(
exporterType,
createDefaultConfig,
exporterhelper.WithTraces(createTraceExporter),
exporterhelper.WithTraces(createTracesExporter),
)
}

Expand All @@ -44,9 +44,9 @@ func createDefaultConfig() config.Exporter {
}
}

// createTraceExporter implements exporterhelper.CreateTracesExporter and creates
// createTracesExporter implements exporterhelper.CreateTracesExporter and creates
// an exporter for traces using this configuration
func createTraceExporter(
func createTracesExporter(
_ context.Context,
set component.ExporterCreateSettings,
cfg config.Exporter,
Expand All @@ -60,6 +60,6 @@ func createTraceExporter(
cfg,
set,
exp.pushTraceData,
exporterhelper.WithShutdown(exp.Shutdown),
exporterhelper.WithShutdown(exp.shutdown),
)
}
10 changes: 5 additions & 5 deletions exporter/tanzuobservabilityexporter/factory_test.go
Expand Up @@ -65,14 +65,14 @@ func TestCreateExporter(t *testing.T) {
cfg := defaultConfig.(*Config)
params := componenttest.NewNopExporterCreateSettings()

te, err := createTraceExporter(context.Background(), params, cfg)
te, err := createTracesExporter(context.Background(), params, cfg)
assert.Nil(t, err)
assert.NotNil(t, te, "failed to create trace exporter")
}

func TestCreateTraceExporterNilConfigError(t *testing.T) {
params := componenttest.NewNopExporterCreateSettings()
_, err := createTraceExporter(context.Background(), params, nil)
_, err := createTracesExporter(context.Background(), params, nil)
assert.Error(t, err)
}

Expand All @@ -81,7 +81,7 @@ func TestCreateTraceExporterInvalidEndpointError(t *testing.T) {
defaultConfig := createDefaultConfig()
cfg := defaultConfig.(*Config)
cfg.Traces.Endpoint = "http:#$%^&#$%&#"
_, err := createTraceExporter(context.Background(), params, cfg)
_, err := createTracesExporter(context.Background(), params, cfg)
assert.Error(t, err)
}

Expand All @@ -90,7 +90,7 @@ func TestCreateTraceExporterMissingPortError(t *testing.T) {
defaultConfig := createDefaultConfig()
cfg := defaultConfig.(*Config)
cfg.Traces.Endpoint = "http://localhost"
_, err := createTraceExporter(context.Background(), params, cfg)
_, err := createTracesExporter(context.Background(), params, cfg)
assert.Error(t, err)
}

Expand All @@ -99,6 +99,6 @@ func TestCreateTraceExporterInvalidPortError(t *testing.T) {
defaultConfig := createDefaultConfig()
cfg := defaultConfig.(*Config)
cfg.Traces.Endpoint = "http://localhost:c42a"
_, err := createTraceExporter(context.Background(), params, cfg)
_, err := createTracesExporter(context.Background(), params, cfg)
assert.Error(t, err)
}
20 changes: 9 additions & 11 deletions exporter/tanzuobservabilityexporter/transformer.go
Expand Up @@ -27,14 +27,12 @@ import (
)

type traceTransformer struct {
ResourceAttributes pdata.AttributeMap
Config *Config
resAttrs pdata.AttributeMap
}

func newTraceTransformer(resource pdata.Resource, cfg *Config) *traceTransformer {
func newTraceTransformer(resource pdata.Resource) *traceTransformer {
t := &traceTransformer{
ResourceAttributes: resource.Attributes(),
Config: cfg,
resAttrs: resource.Attributes(),
}
return t
}
Expand All @@ -44,7 +42,7 @@ var (
errInvalidTraceID = errors.New("TraceID is invalid")
)

type Span struct {
type span struct {
Name string
TraceID uuid.UUID
SpanID uuid.UUID
Expand All @@ -55,20 +53,20 @@ type Span struct {
SpanLogs []senders.SpanLog
}

func (t *traceTransformer) Span(orig pdata.Span) (Span, error) {
func (t *traceTransformer) Span(orig pdata.Span) (span, error) {
traceID, err := traceIDtoUUID(orig.TraceID())
if err != nil {
return Span{}, errInvalidTraceID
return span{}, errInvalidTraceID
}

spanID, err := spanIDtoUUID(orig.SpanID())
if err != nil {
return Span{}, errInvalidSpanID
return span{}, errInvalidSpanID
}

startMillis, durationMillis := calculateTimes(orig)

tags := attributesToTags(t.ResourceAttributes, orig.Attributes())
tags := attributesToTags(t.resAttrs, orig.Attributes())
t.setRequiredTags(tags)

tags[labelSpanKind] = spanKind(orig)
Expand All @@ -82,7 +80,7 @@ func (t *traceTransformer) Span(orig pdata.Span) (Span, error) {
tags[tracetranslator.TagW3CTraceState] = string(orig.TraceState())
}

return Span{
return span{
Name: orig.Name(),
TraceID: traceID,
SpanID: spanID,
Expand Down
5 changes: 2 additions & 3 deletions exporter/tanzuobservabilityexporter/transformer_test.go
Expand Up @@ -251,10 +251,9 @@ func spanWithTraceState(state pdata.TraceState) pdata.Span {
return span
}

func transformerFromAttributes(att pdata.AttributeMap) *traceTransformer {
func transformerFromAttributes(attrs pdata.AttributeMap) *traceTransformer {
return &traceTransformer{
ResourceAttributes: att,
Config: createDefaultConfig().(*Config),
resAttrs: attrs,
}
}

Expand Down