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

fix null pointer in jaeger-spark-dependencies #2327

Merged
merged 1 commit into from
Jul 7, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const (
)

var (
errZeroTraceID = errors.New("traceID is zero")
errZeroSpanID = errors.New("spanID is zero")
errZeroTraceID = errors.New("traceID is zero")
errZeroSpanID = errors.New("spanID is zero")
emptyLogList = []dbmodel.Log{}
emptyReferenceList = []dbmodel.Reference{}
emptyTagList = []dbmodel.KeyValue{}
)

// Translator configures translator
Expand Down Expand Up @@ -134,7 +137,7 @@ func toTime(nano pdata.TimestampUnixNano) time.Time {
func references(links pdata.SpanLinkSlice, parentSpanID pdata.SpanID, traceID dbmodel.TraceID) ([]dbmodel.Reference, error) {
parentSpanIDSet := len(parentSpanID.Bytes()) != 0
if !parentSpanIDSet && links.Len() == 0 {
return nil, nil
return emptyReferenceList, nil
}

refsCount := links.Len()
Expand Down Expand Up @@ -265,11 +268,9 @@ func (c *Translator) tags(span pdata.Span) ([]dbmodel.KeyValue, map[string]inter
tagsCount++
}
}

if tagsCount == 0 {
return nil, nil
return emptyTagList, nil
}

tags := make([]dbmodel.KeyValue, 0, tagsCount)
var tagMap map[string]interface{}
if spanKindTagFound {
Expand Down Expand Up @@ -365,7 +366,7 @@ func getTagFromStatusMsg(statusMsg string) (dbmodel.KeyValue, bool) {

func logs(events pdata.SpanEventSlice) []dbmodel.Log {
if events.Len() == 0 {
return nil
return emptyLogList
}
logs := make([]dbmodel.Log, 0, events.Len())
for i := 0; i < events.Len(); i++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,33 @@ func TestConvertSpan(t *testing.T) {
}, spans[0])
}

func TestSpanEmptyRef(t *testing.T) {
traces := traces("myservice")
span := addSpan(traces, "root", traceID, spanID)
span.SetStartTime(pdata.TimestampUnixNano(1000000))
span.SetEndTime(pdata.TimestampUnixNano(2000000))

c := &Translator{}
spans, err := c.ConvertSpans(traces)
require.NoError(t, err)
assert.Equal(t, 1, len(spans))
assert.Equal(t, &dbmodel.Span{
TraceID: "30313233343536373839616263646566",
SpanID: "3031323334353637",
StartTime: 1000,
Duration: 1000,
OperationName: "root",
StartTimeMillis: 1,
Tags: []dbmodel.KeyValue{}, // should not be nil
Logs: []dbmodel.Log{}, // should not be nil
References: []dbmodel.Reference{}, // should not be nil
Process: dbmodel.Process{
ServiceName: "myservice",
Tags: nil,
},
}, spans[0])
}

func TestEmpty(t *testing.T) {
c := &Translator{}
spans, err := c.ConvertSpans(pdata.NewTraces())
Expand Down