mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo/Jaeger: Prevent error when spans are missing (#33880)
This commit is contained in:
@@ -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] },
|
||||
],
|
||||
});
|
||||
|
||||
@@ -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[] } } = {};
|
||||
|
||||
Reference in New Issue
Block a user