Tempo/Jaeger: Prevent error when spans are missing (#33880)

This commit is contained in:
Andrej Ocenas
2021-05-11 09:59:06 +02:00
committed by GitHub
parent 60cf0c8338
commit 7c5d3435f9
4 changed files with 82 additions and 4 deletions

View File

@@ -49,6 +49,13 @@ describe('createGraphFrames', () => {
color: 1.000007560204647,
});
});
it('handles missing spans', async () => {
const frames = createGraphFrames(missingSpanResponse);
expect(frames.length).toBe(2);
expect(frames[0].length).toBe(2);
expect(frames[1].length).toBe(0);
});
});
const singleSpanResponse = new MutableDataFrame({
@@ -62,3 +69,15 @@ const singleSpanResponse = new MutableDataFrame({
{ name: 'duration', values: [14.984] },
],
});
const missingSpanResponse = new MutableDataFrame({
fields: [
{ name: 'traceID', values: ['04450900759028499335', '04450900759028499335'] },
{ name: 'spanID', values: ['1', '2'] },
{ name: 'parentSpanID', values: ['', '3'] },
{ name: 'operationName', values: ['store.validateQueryTimeRange', 'store.validateQueryTimeRange'] },
{ name: 'serviceName', values: ['loki-all', 'loki-all'] },
{ name: 'startTime', values: [1619712655875.4539, 1619712655880.4539] },
{ name: 'duration', values: [14.984, 4.984] },
],
});

View File

@@ -96,7 +96,8 @@ function convertTraceToGraph(data: DataFrame): { nodes: Node[]; edges: Edge[] }
[Fields.color]: selfDuration / traceDuration,
});
if (row.parentSpanID) {
// Sometimes some span can be missing. Don't add edges for those.
if (row.parentSpanID && spanMap[row.parentSpanID].span) {
edges.push({
[Fields.id]: row.parentSpanID + '--' + row.spanID,
[Fields.target]: row.spanID,
@@ -136,7 +137,8 @@ function findTraceDuration(view: DataFrameView<Row>): number {
}
/**
* Returns a map of the spans with children array for easier processing.
* Returns a map of the spans with children array for easier processing. It will also contain empty spans in case
* span is missing but other spans are it's children.
*/
function makeSpanMap(view: DataFrameView<Row>): { [id: string]: { span: Row; children: string[] } } {
const spanMap: { [id: string]: { span?: Row; children: string[] } } = {};