From 223f96445e96c40096620f9f5e0c9e20931c9d4e Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Tue, 16 Jul 2019 09:49:14 -0400 Subject: [PATCH 1/3] Fix migration issue that assumes old filter queries that don't have meta property have query string --- .../migrations/migrations_730.test.ts | 35 +++++++++++++++++++ .../dashboard/migrations/migrations_730.ts | 11 ++++-- .../migrations/move_filters_to_query.ts | 4 ++- .../public/dashboard/migrations/types.ts | 8 +++-- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts index 52182ee0be0b1..c195e722b900e 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts @@ -17,11 +17,13 @@ * under the License. */ +import { migrations } from '../../../migrations/'; import { migrations730 } from './migrations_730'; import { DashboardDoc700To720, DashboardDoc730ToLatest, RawSavedDashboardPanel730ToLatest, + DashboardDocPre700, } from './types'; const mockLogger = { @@ -70,12 +72,45 @@ Object { `); }); +// See https://github.com/elastic/kibana/issues/41240 - this can happen. +test('dashboard migration 7.3.0 does not migrate filters to query on search source when there is no query string property', () => { + const doc: DashboardDocPre700 = { + id: 'AWviOturFv4p9HkVSIgn', + type: 'dashboard', + attributes: { + title: 'all_the_viz', + description: '', + panelsJSON: + '[{"col":1,"columns":["_source"],"id":"AWviL7GTFv4p9HkVSIf8","panelIndex":1,"row":1,"size_x":6,"size_y":3,"sort":["@timestamp","desc"],"type":"search"},{"col":7,"id":"AWviMFurFv4p9HkVSIf9","panelIndex":2,"row":1,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviMOBlFv4p9HkVSIf-","panelIndex":3,"row":4,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviMZ6SFv4p9HkVSIf_","panelIndex":4,"row":4,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviMqdpFv4p9HkVSIgK","panelIndex":5,"row":7,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviM0kxFv4p9HkVSIga","panelIndex":6,"row":7,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviM_UOFv4p9HkVSIgb","panelIndex":7,"row":10,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviNMDaFv4p9HkVSIgc","panelIndex":8,"row":10,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviNR7vFv4p9HkVSIgd","panelIndex":9,"row":13,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviNcPPFv4p9HkVSIge","panelIndex":10,"row":13,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviNu5XFv4p9HkVSIgf","panelIndex":11,"row":16,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviN5pxFv4p9HkVSIgg","panelIndex":12,"row":16,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviN_qeFv4p9HkVSIgh","panelIndex":13,"row":19,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviOI-XFv4p9HkVSIgi","panelIndex":14,"row":19,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviOP2GFv4p9HkVSIgj","panelIndex":15,"row":22,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviOYpkFv4p9HkVSIgk","panelIndex":16,"row":22,"size_x":6,"size_y":3,"type":"visualization"},{"col":1,"id":"AWviOilNFv4p9HkVSIgl","panelIndex":17,"row":25,"size_x":6,"size_y":3,"type":"visualization"},{"col":7,"id":"AWviOpW1Fv4p9HkVSIgm","panelIndex":18,"row":25,"size_x":6,"size_y":3,"type":"visualization"}]', + optionsJSON: '{"darkTheme":false}', + uiStateJSON: + '{"P-9":{"vis":{"params":{"sort":{"columnIndex":null,"direction":null}}}},"P-3":{"vis":{"defaultColors":{"0 - 88":"rgb(247,252,245)","88 - 175":"rgb(199,233,192)","175 - 263":"rgb(116,196,118)","263 - 350":"rgb(35,139,69)"}}},"P-10":{"vis":{"defaultColors":{"0 - 50":"rgb(0,104,55)","50 - 75":"rgb(255,255,190)","75 - 100":"rgb(165,0,38)"}}},"P-11":{"vis":{"defaultColors":{"0 - 100":"rgb(0,104,55)"}}},"P-12":{"vis":{"defaultColors":{"0 - 100":"rgb(0,104,55)"}}}}', + version: 1, + timeRestore: false, + kibanaSavedObjectMeta: { + searchSourceJSON: + '{"filter":[{"query":{"match_all":{}}}],"highlightAll":true,"version":true}', + }, + }, + }; + + const doc700: DashboardDoc700To720 = migrations.dashboard['7.0.0'](doc, mockLogger); + const newDoc = migrations.dashboard['7.3.0'](doc700, mockLogger); + + const parsedSearchSource = JSON.parse(newDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON); + expect(parsedSearchSource.filter.length).toBe(1); + expect(parsedSearchSource.query.query).toBe(''); + + expect(newDoc.attributes.uiStateJSON).toBeUndefined(); +}); + test('dashboard migration 7.3.0 migrates panels', () => { const doc: DashboardDoc700To720 = { id: '1', type: 'dashboard', references: [], attributes: { + title: 'hi', useMargins: true, description: '', uiStateJSON: '{}', 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 b786ee90dc6f8..ee28643f36446 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 @@ -42,7 +42,9 @@ export function migrations730( moveFiltersToQuery(searchSource) ); } catch (e) { - logger.warning(`Exception @ migrations730 while trying to migrate query filters! ${e}`); + logger.warning( + `Exception @ migrations730 while trying to migrate query filters!\nError:${e}\nSearchSource JSON:\n${doc.attributes.kibanaSavedObjectMeta.searchSourceJSON}` + ); return doc; } @@ -55,7 +57,12 @@ export function migrations730( try { const panels = JSON.parse(doc.attributes.panelsJSON); doc.attributes.panelsJSON = JSON.stringify( - migratePanelsTo730(panels, '7.3.0', doc.attributes.useMargins, uiState) + migratePanelsTo730( + panels, + '7.3.0', + doc.attributes.useMargins === undefined ? true : doc.attributes.useMargins, + uiState + ) ); delete doc.attributes.uiStateJSON; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/move_filters_to_query.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/move_filters_to_query.ts index 1ccebbe5758fc..c99f3efbbf632 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/move_filters_to_query.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/move_filters_to_query.ts @@ -41,7 +41,9 @@ export interface SearchSource730 { } function isQueryFilter(filter: Filter | { query: unknown }): filter is Pre600FilterQuery { - return filter.query && !(filter as Filter).meta; + return ( + filter.query && !(filter as Filter).meta && (filter as Pre600FilterQuery).query.query_string + ); } export function moveFiltersToQuery( diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts index b2d70602b6f3b..17398a9e828f4 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts @@ -31,7 +31,9 @@ interface DashboardAttributes extends SavedObjectAttributes { description: string; version: number; timeRestore: boolean; - useMargins: boolean; + useMargins?: boolean; + title: string; + optionsJSON?: string; } export type DashboardAttributes730ToLatest = DashboardAttributes; @@ -42,7 +44,9 @@ interface DashboardAttributesTo720 extends SavedObjectAttributes { uiStateJSON: string; version: number; timeRestore: boolean; - useMargins: boolean; + useMargins?: boolean; + title: string; + optionsJSON?: string; } export type DashboardDoc730ToLatest = Doc; From b9657ac775150f633197e54d9a46fec6437c07c5 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Tue, 16 Jul 2019 10:20:57 -0400 Subject: [PATCH 2/3] fix type error --- .../kibana/public/dashboard/migrations/migrations_730.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts index c195e722b900e..757119d4ea352 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts @@ -38,6 +38,7 @@ test('dashboard migration 7.3.0 migrates filters to query on search source', () type: 'dashboard', references: [], attributes: { + title: 'hi', useMargins: true, description: '', uiStateJSON: '{}', From 94fdeb8a77b7e67d61b37c53a06e575e4743fecd Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Tue, 16 Jul 2019 11:11:56 -0400 Subject: [PATCH 3/3] adjust snapshot so it includes the new title attribute --- .../migrations/migrations_730.test.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts index 757119d4ea352..dfeeb2a486a54 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.test.ts @@ -55,22 +55,23 @@ test('dashboard migration 7.3.0 migrates filters to query on search source', () const newDoc = migrations730(doc, mockLogger); expect(newDoc).toMatchInlineSnapshot(` -Object { - "attributes": Object { - "description": "", - "kibanaSavedObjectMeta": Object { - "searchSourceJSON": "{\\"filter\\":[],\\"highlightAll\\":true,\\"version\\":true,\\"query\\":{\\"query\\":\\"n: 6\\",\\"language\\":\\"lucene\\"}}", - }, - "panelsJSON": "[{\\"id\\":\\"1\\",\\"type\\":\\"visualization\\",\\"foo\\":true},{\\"id\\":\\"2\\",\\"type\\":\\"visualization\\",\\"bar\\":true}]", - "timeRestore": false, - "useMargins": true, - "version": 1, - }, - "id": "1", - "references": Array [], - "type": "dashboard", -} -`); + Object { + "attributes": Object { + "description": "", + "kibanaSavedObjectMeta": Object { + "searchSourceJSON": "{\\"filter\\":[],\\"highlightAll\\":true,\\"version\\":true,\\"query\\":{\\"query\\":\\"n: 6\\",\\"language\\":\\"lucene\\"}}", + }, + "panelsJSON": "[{\\"id\\":\\"1\\",\\"type\\":\\"visualization\\",\\"foo\\":true},{\\"id\\":\\"2\\",\\"type\\":\\"visualization\\",\\"bar\\":true}]", + "timeRestore": false, + "title": "hi", + "useMargins": true, + "version": 1, + }, + "id": "1", + "references": Array [], + "type": "dashboard", + } + `); }); // See https://github.com/elastic/kibana/issues/41240 - this can happen.