Skip to content

Commit

Permalink
Fixes #42519 dashboard migration bug (#42520) (#42673)
Browse files Browse the repository at this point in the history
* Fixes #42519 dashboard migration bug

* Tests

* Dashboard migration errors: log stack and dashboard document
  • Loading branch information
rudolf authored Aug 6, 2019
1 parent 0740aa3 commit b4adf8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit b4adf8f

Please sign in to comment.