Skip to content

Commit

Permalink
Do not apply search source data for tsvb (#75137) (#76875)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Sep 7, 2020
1 parent ccf48e9 commit 324760e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1578,4 +1578,46 @@ describe('migration visualization', () => {
expect(metric.denominator).toHaveProperty('language');
});
});

describe('7.10.0 remove tsvb search source', () => {
const migrate = (doc: any) =>
visualizationSavedObjectTypeMigrations['7.10.0'](
doc as Parameters<SavedObjectMigrationFn>[0],
savedObjectMigrationContext
);
const generateDoc = (visState: any) => ({
attributes: {
title: 'My Vis',
description: 'This is my super cool vis.',
visState: JSON.stringify(visState),
uiStateJSON: '{}',
version: 1,
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
filter: [],
query: {
query: {
query_string: {
query: '*',
},
},
language: 'lucene',
},
}),
},
},
});

it('should remove the search source JSON', () => {
const timeSeriesDoc = generateDoc({ type: 'metrics' });
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
expect(migratedtimeSeriesDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON).toEqual('{}');
const { kibanaSavedObjectMeta, ...attributes } = migratedtimeSeriesDoc.attributes;
const {
kibanaSavedObjectMeta: oldKibanaSavedObjectMeta,
...oldAttributes
} = migratedtimeSeriesDoc.attributes;
expect(attributes).toEqual(oldAttributes);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,35 @@ const migrateTsvbDefaultColorPalettes: SavedObjectMigrationFn<any, any> = (doc)
return doc;
};

// [TSVB] Remove serialized search source as it's not used in TSVB visualizations
const removeTSVBSearchSource: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get(doc, 'attributes.visState');
let visState;

const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');

if (visStateJSON) {
try {
visState = JSON.parse(visStateJSON);
} catch (e) {
// Let it go, the data is invalid and we'll leave it as is
}
if (visState && visState.type === 'metrics' && searchSourceJSON !== '{}') {
return {
...doc,
attributes: {
...doc.attributes,
kibanaSavedObjectMeta: {
...get(doc, 'attributes.kibanaSavedObjectMeta'),
searchSourceJSON: '{}',
},
},
};
}
}
return doc;
};

export const visualizationSavedObjectTypeMigrations = {
/**
* We need to have this migration twice, once with a version prior to 7.0.0 once with a version
Expand Down Expand Up @@ -752,5 +781,5 @@ export const visualizationSavedObjectTypeMigrations = {
'7.4.2': flow(transformSplitFiltersStringToQueryObject),
'7.7.0': flow(migrateOperatorKeyTypo, migrateSplitByChartRow),
'7.8.0': flow(migrateTsvbDefaultColorPalettes),
'7.10.0': flow(migrateFilterRatioQuery),
'7.10.0': flow(migrateFilterRatioQuery, removeTSVBSearchSource),
};

0 comments on commit 324760e

Please sign in to comment.