Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not apply search source data for tsvb #75137

Merged
merged 6 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
};