-
Notifications
You must be signed in to change notification settings - Fork 513
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
Correct trace name resolution #541
Changes from 3 commits
76aa568
2e5d770
e968cdb
5c633c2
08d8dbb
5793005
52e3794
c914bcf
a6f67ba
270a762
75552d8
3944f05
f65375f
98b7eb7
bfbce5b
9aa5b4b
0c49d43
8d3eb81
3b2cbae
cd8d04c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Copyright (c) 2018 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. | ||
|
||
import { getTraceName } from './trace-viewer'; | ||
|
||
describe('getTraceName', () => { | ||
const firstSpanId = 'firstSpanId'; | ||
const secondSpanId = 'secondSpanId'; | ||
const thirdSpanId = 'thirdSpanId'; | ||
const remoteSpanId = 'remoteSpanId'; | ||
|
||
const serviceName = 'serviceName'; | ||
const operationName = 'operationName'; | ||
|
||
const spansWithNoRoots = [ | ||
swapster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
spanID: firstSpanId, | ||
startTime: 1583758690000, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend defining a constant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, fixed. |
||
references: [ | ||
{ | ||
spanID: secondSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
{ | ||
spanID: secondSpanId, | ||
startTime: 1583758680000, | ||
references: [ | ||
{ | ||
spanID: thirdSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
{ | ||
spanID: thirdSpanId, | ||
startTime: 1583758670000, | ||
references: [ | ||
{ | ||
spanID: firstSpanId, | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
]; | ||
const spansWithMultipleRoots = [ | ||
{ | ||
spanID: firstSpanId, | ||
startTime: 1583758690000, | ||
references: [ | ||
{ | ||
spanID: thirdSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
{ | ||
spanID: secondSpanId, // root span | ||
startTime: 1583758680000, | ||
}, | ||
{ | ||
spanID: thirdSpanId, // root span | ||
startTime: 1583758670000, | ||
operationName, | ||
process: { | ||
serviceName, | ||
}, | ||
references: [ | ||
{ | ||
spanID: remoteSpanId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this looks more like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, its' better, fixed. |
||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
]; | ||
const spansWithOneRootWithRemoteRef = [ | ||
{ | ||
spanID: firstSpanId, | ||
startTime: 1583758690000, | ||
references: [ | ||
{ | ||
spanID: secondSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
{ | ||
spanID: secondSpanId, | ||
startTime: 1583758680000, | ||
references: [ | ||
{ | ||
spanID: thirdSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
{ | ||
spanID: thirdSpanId, // root span | ||
swapster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
startTime: 1583758670000, | ||
operationName, | ||
process: { | ||
serviceName, | ||
}, | ||
references: [ | ||
{ | ||
spanID: remoteSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
]; | ||
const spansWithOneRootWithNoRefs = [ | ||
{ | ||
spanID: firstSpanId, | ||
startTime: 1583758690000, | ||
references: [ | ||
{ | ||
spanID: thirdSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
{ | ||
spanID: secondSpanId, // root span | ||
startTime: 1583758680000, | ||
operationName, | ||
process: { | ||
serviceName, | ||
}, | ||
}, | ||
{ | ||
spanID: thirdSpanId, | ||
startTime: 1583758670000, | ||
references: [ | ||
{ | ||
spanID: secondSpanId, | ||
refType: 'CHILD_OF', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const fullTraceName = `${serviceName}: ${operationName}`; | ||
|
||
it('returns an empty string if given spans with no root among them', () => { | ||
expect(getTraceName(spansWithNoRoots)).toEqual(''); | ||
}); | ||
|
||
it('returns an id of root span with the earliest startTime', () => { | ||
expect(getTraceName(spansWithMultipleRoots)).toEqual(fullTraceName); | ||
}); | ||
|
||
it('returns an id of root span with remote ref', () => { | ||
expect(getTraceName(spansWithOneRootWithRemoteRef)).toEqual(fullTraceName); | ||
}); | ||
|
||
it('returns an id of root span with no refs', () => { | ||
expect(getTraceName(spansWithOneRootWithNoRefs)).toEqual(fullTraceName); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,22 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Span } from '../types/trace'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function getTraceName(spans) { | ||
const span = spans.filter(sp => !sp.references || !sp.references.length)[0]; | ||
return span ? `${span.process.serviceName}: ${span.operationName}` : ''; | ||
export function getTraceName(spans: Span[]) { | ||
const allSpanIDs = spans.map(sp => sp.spanID); | ||
const rootSpan = spans | ||
.filter(sp => { | ||
if (!sp.references || !sp.references.length) { | ||
return true; | ||
} | ||
const parentIDs = sp.references.filter(r => r.refType === 'CHILD_OF').map(r => r.spanID); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if you dropped filters for CHILD_OF? It's possible to have an async trace using FOLLOWS_FROM. I don't think the algorithm is actually sensitive to the type of reference. If anything, I would filter on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. Did I understand correctly, P. S. "I didn't find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// no parent from trace | ||
return !parentIDs.some(pID => allSpanIDs.includes(pID)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just didn't think about it. But yeap, dictionary makes sense here. |
||
}) | ||
.sort((sp1, sp2) => sp1.startTime - sp2.startTime)[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is correct, as it does not give preference to the true root span (that one that has NO parent). It's only correct in the absence of clock skews. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return rootSpan ? `${rootSpan.process.serviceName}: ${rootSpan.operationName}` : ''; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
"src/api/jaeger.js", | ||
"src/components/SearchTracePage/SearchResults/ResultItem.markers.js", | ||
"src/model/order-by.js", | ||
"src/model/trace-viewer.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the tsx file be added to some other linter config, or will it be automatically linted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will be linted since this config file inherits another config with include option. |
||
"src/selectors/process.js", | ||
"src/selectors/span.js", | ||
"src/selectors/trace.js", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed