diff --git a/public/app/plugins/datasource/tempo/graphTransform.test.ts b/public/app/plugins/datasource/tempo/graphTransform.test.ts index e6acd91ddd1..efebee60cd6 100644 --- a/public/app/plugins/datasource/tempo/graphTransform.test.ts +++ b/public/app/plugins/datasource/tempo/graphTransform.test.ts @@ -80,6 +80,27 @@ it('assigns correct field type even if values are numbers', async () => { ]); }); +it('do not fail on response with empty list', async () => { + const range = { + from: dateTime('2000-01-01T00:00:00'), + to: dateTime('2000-01-01T00:01:00'), + }; + const { nodes } = mapPromMetricsToServiceMap([], { + ...range, + raw: range, + }); + + expect(nodes.fields).toMatchObject([ + { name: 'id', values: [], type: FieldType.string }, + { name: 'title', values: [], type: FieldType.string }, + { name: 'subtitle', type: FieldType.string, values: [] }, + { name: 'mainstat', values: [], type: FieldType.number }, + { name: 'secondarystat', values: [], type: FieldType.number }, + { name: 'arc__success', values: [], type: FieldType.number }, + { name: 'arc__failed', values: [], type: FieldType.number }, + ]); +}); + describe('mapPromMetricsToServiceMap', () => { it('transforms prom metrics to service graph', async () => { const range = { diff --git a/public/app/plugins/datasource/tempo/graphTransform.ts b/public/app/plugins/datasource/tempo/graphTransform.ts index 4b7b4b56fed..08cbbf19c6b 100644 --- a/public/app/plugins/datasource/tempo/graphTransform.ts +++ b/public/app/plugins/datasource/tempo/graphTransform.ts @@ -249,7 +249,7 @@ function createServiceMapDataFrames() { * @param responses */ function getMetricFrames(responses: DataQueryResponse[]): Record { - return responses[0].data.reduce>((acc, frameDTO) => { + return (responses[0]?.data || []).reduce>((acc, frameDTO) => { const frame = toDataFrame(frameDTO); acc[frame.refId ?? 'A'] = new DataFrameView(frame); return acc;