-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As demonstrated in https://github.com/jaegertracing/jaeger-ui/issues/966, jaeger-ui expects the first reference to be of `CHILD_OF` type to properly render the tree. This new adjuster achieves exactly that.
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// 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 adjuster | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
// SortReferences returns an Adjuster that puts CHILD_OF references first. | ||
// This is necessary to match jaeger-ui expectations: | ||
// * https://github.com/jaegertracing/jaeger-ui/issues/966 | ||
func SortReferences() Adjuster { | ||
return Func(func(trace *model.Trace) (*model.Trace, error) { | ||
for _, span := range trace.Spans { | ||
sort.SliceStable(span.References, func(i, j int) bool { | ||
iType := span.References[i].GetRefType() | ||
jType := span.References[j].GetRefType() | ||
return iType == model.SpanRefType_CHILD_OF && jType == model.SpanRefType_FOLLOWS_FROM | ||
}) | ||
} | ||
return trace, nil | ||
}) | ||
} |
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,90 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// 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 adjuster | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
func TestSortReferences(t *testing.T) { | ||
testCases := []struct { | ||
incoming []model.SpanRefType | ||
expected []model.SpanRefType | ||
}{ | ||
{ | ||
incoming: []model.SpanRefType{}, | ||
expected: []model.SpanRefType{}, | ||
}, | ||
{ | ||
incoming: []model.SpanRefType{model.ChildOf}, | ||
expected: []model.SpanRefType{model.ChildOf}, | ||
}, | ||
{ | ||
incoming: []model.SpanRefType{model.FollowsFrom}, | ||
expected: []model.SpanRefType{model.FollowsFrom}, | ||
}, | ||
{ | ||
incoming: []model.SpanRefType{model.ChildOf, model.FollowsFrom}, | ||
expected: []model.SpanRefType{model.ChildOf, model.FollowsFrom}, | ||
}, | ||
{ | ||
incoming: []model.SpanRefType{model.FollowsFrom, model.ChildOf}, | ||
expected: []model.SpanRefType{model.ChildOf, model.FollowsFrom}, | ||
}, | ||
{ | ||
incoming: []model.SpanRefType{model.FollowsFrom, model.ChildOf, model.FollowsFrom}, | ||
expected: []model.SpanRefType{model.ChildOf, model.FollowsFrom, model.FollowsFrom}, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
trace := &model.Trace{ | ||
Spans: []*model.Span{ | ||
{ | ||
References: makeReferences(testCase.incoming), | ||
}, | ||
}, | ||
} | ||
trace, err := SortReferences().Adjust(trace) | ||
assert.NoError(t, err) | ||
assert.Equal(t, testCase.expected, extractReferenceTypes(trace.Spans[0].References)) | ||
} | ||
} | ||
|
||
func makeReferences(types []model.SpanRefType) []model.SpanRef { | ||
references := make([]model.SpanRef, len(types)) | ||
|
||
for i, refType := range types { | ||
references[i] = model.SpanRef{ | ||
RefType: refType, | ||
} | ||
} | ||
|
||
return references | ||
} | ||
|
||
func extractReferenceTypes(references []model.SpanRef) []model.SpanRefType { | ||
types := make([]model.SpanRefType, len(references)) | ||
|
||
for i, reference := range references { | ||
types[i] = reference.RefType | ||
} | ||
|
||
return types | ||
} |