From e5661390d013d96d56f18e8be82aab178d68f46b Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 6 Aug 2019 11:05:29 +0200 Subject: [PATCH] Fixes #42519 dashboard migration bug (#42520) * Fixes #42519 dashboard migration bug * Tests * Dashboard migration errors: log stack and dashboard document --- .../migrations/migrate_to_730_panels.test.ts | 22 +++++++++++++++++++ .../migrations/migrate_to_730_panels.ts | 2 +- .../dashboard/migrations/migrations_730.ts | 11 ++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts index c06ab33f093fd..ef363ae0dcde1 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts @@ -298,6 +298,28 @@ test('6.1 migrates uiState, sort, and scales', async () => { expect((newPanel.embeddableConfig as any).vis.defaultColors['0+-+100']).toBe('rgb(0,104,55)'); }); +// https://github.com/elastic/kibana/issues/42519 +it('6.1 migrates when uiState={} and panels have sort / column override', () => { + const uiState = {}; + const panels: RawSavedDashboardPanel610[] = [ + { + panelIndex: 1, + sort: 'sort', + version: '6.1.0', + name: 'panel-123', + gridData: { h: 3, x: 0, y: 0, w: 6, i: '123' }, + }, + { + panelIndex: 2, + columns: ['hi'], + version: '6.1.0', + name: 'panel-123', + gridData: { h: 3, x: 0, y: 0, w: 6, i: '123' }, + }, + ]; + expect(() => migratePanelsTo730(panels, '8.0.0', true, uiState)).not.toThrow(); +}); + test('6.2 migrates sort and scales', async () => { const panels: RawSavedDashboardPanel620[] = [ { diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts index 6cc69013a4b1a..de976cc670631 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts @@ -151,7 +151,7 @@ function migrate610PanelToLatest( } }); - const embeddableConfig = uiState ? uiState[`P-${panel.panelIndex}`] : {}; + const embeddableConfig = uiState ? uiState[`P-${panel.panelIndex}`] || {} : {}; // 2. (6.4) remove columns, sort properties if (panel.columns || panel.sort) { diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts index ee28643f36446..cbb695a564190 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts @@ -17,6 +17,7 @@ * under the License. */ import { Logger } from 'target/types/server/saved_objects/migrations/core/migration_logger'; +import { inspect } from 'util'; import { DashboardDoc730ToLatest, DashboardDoc700To720 } from './types'; import { isDashboardDoc } from './is_dashboard_doc'; import { moveFiltersToQuery } from './move_filters_to_query'; @@ -43,7 +44,9 @@ export function migrations730( ); } catch (e) { logger.warning( - `Exception @ migrations730 while trying to migrate query filters!\nError:${e}\nSearchSource JSON:\n${doc.attributes.kibanaSavedObjectMeta.searchSourceJSON}` + `Exception @ migrations730 while trying to migrate dashboard query filters!\n` + + `${e.stack}\n` + + `dashboard: ${inspect(doc, false, null)}` ); return doc; } @@ -67,7 +70,11 @@ export function migrations730( delete doc.attributes.uiStateJSON; } catch (e) { - logger.warning(`Exception @ migrations730 while trying to migrate dashboard panels! ${e}`); + logger.warning( + `Exception @ migrations730 while trying to migrate dashboard panels!\n` + + `Error: ${e.stack}\n` + + `dashboard: ${inspect(doc, false, null)}` + ); return doc; }