mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Fix migration issue that assumes old filter queries that don't have meta property have query string * fix type error * adjust snapshot so it includes the new title attribute
This commit is contained in:
parent
e4c2b1986f
commit
bdb517b8fa
4 changed files with 70 additions and 20 deletions
|
@ -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 = {
|
||||
|
@ -36,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: '{}',
|
||||
|
@ -52,22 +55,55 @@ 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\\"}}",
|
||||
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.
|
||||
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}',
|
||||
},
|
||||
},
|
||||
"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",
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
||||
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', () => {
|
||||
|
@ -76,6 +112,7 @@ test('dashboard migration 7.3.0 migrates panels', () => {
|
|||
type: 'dashboard',
|
||||
references: [],
|
||||
attributes: {
|
||||
title: 'hi',
|
||||
useMargins: true,
|
||||
description: '',
|
||||
uiStateJSON: '{}',
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<DashboardAttributes>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue