From 31e7e35bff2f313a8749806c1dd70fd81d368c5b Mon Sep 17 00:00:00 2001 From: lzd <24379844+lzdw@users.noreply.github.com> Date: Wed, 6 Nov 2019 15:42:36 +0800 Subject: [PATCH] Datasource/Elasticsearch: Fix logs which were displayed with incorrect timestamp in Explore logs tab (#20009) --- .../src/dataframe/MutableDataFrame.test.ts | 10 ++++++++++ .../grafana-data/src/dataframe/MutableDataFrame.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/packages/grafana-data/src/dataframe/MutableDataFrame.test.ts b/packages/grafana-data/src/dataframe/MutableDataFrame.test.ts index eb6f8aaee43..7e00dd1e594 100644 --- a/packages/grafana-data/src/dataframe/MutableDataFrame.test.ts +++ b/packages/grafana-data/src/dataframe/MutableDataFrame.test.ts @@ -57,6 +57,16 @@ describe('Apending DataFrame', () => { { time: null, name: null, value: null, value2: 'XXX' }, // 4 ]); + // Add a time value that has an array type + frame.add({ time: [300] }); + expect(frame.toArray()).toEqual([ + { time: 100, name: 'a', value: 1, value2: null }, // 1 + { time: 200, name: 'BB', value: 20, value2: null }, // 2 + { time: null, name: null, value: 3, value2: null }, // 3 + { time: null, name: null, value: null, value2: 'XXX' }, // 4 + { time: 300, name: null, value: null, value2: null }, // 5 + ]); + // Make sure length survives a spread operator const keys = Object.keys(frame); const copy = { ...frame } as any; diff --git a/packages/grafana-data/src/dataframe/MutableDataFrame.ts b/packages/grafana-data/src/dataframe/MutableDataFrame.ts index 9ff9aa0f3ae..6c192cfcd5b 100644 --- a/packages/grafana-data/src/dataframe/MutableDataFrame.ts +++ b/packages/grafana-data/src/dataframe/MutableDataFrame.ts @@ -234,6 +234,11 @@ export class MutableDataFrame implements DataFrame, MutableVector { field.parse = makeFieldParser(val, field); } val = field.parse(val); + } else if (field.type === FieldType.time && isArray(val)) { + if (!field.parse) { + field.parse = (val: any[]) => val[0] || undefined; + } + val = field.parse(val); } if (val === undefined) {