From b13395afbccde52d02ac926919234032237794e1 Mon Sep 17 00:00:00 2001 From: Fabrizio <135109076+fabrizio-grafana@users.noreply.github.com> Date: Thu, 2 Nov 2023 11:23:18 +0100 Subject: [PATCH] Tempo: Handle empty responses in ServiceGraph (#77539) --- .../datasource/tempo/graphTransform.test.ts | 21 +++++++++++++++++++ .../datasource/tempo/graphTransform.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) 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;