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

Bug fix:Adds a migration for transforming TSVB vis split_filters #49000

Merged
49 changes: 49 additions & 0 deletions src/legacy/core_plugins/kibana/migrations/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,50 @@ function transformFilterStringToQueryObject(doc) {
}
return newDoc;
}
function transformSplitFiltersStringToQueryObject(doc) {
// Migrate split_filters in TSVB objects that were'nt migrated in 7.3
TinaHeiligers marked this conversation as resolved.
Show resolved Hide resolved
// If any filters exist and they are a string, we assume them to be lucene syntax and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
TinaHeiligers marked this conversation as resolved.
Show resolved Hide resolved
let visState;
try {
visState = JSON.parse(visStateJSON);
} catch (e) {
// let it go, the data is invalid and we'll leave it as is
}
if (visState) {
const visType = get(visState, 'params.type');
const tsvbTypes = ['metric', 'markdown', 'top_n', 'gauge', 'table', 'timeseries'];
if (tsvbTypes.indexOf(visType) === -1) {
// skip
return doc;
}
// migrate the series split_filter filters
const series = get(visState, 'params.series') || [];
series.forEach(item => {
// series item split filters filter
if (item.split_filters) {
const splitFilters = get(item, 'split_filters') || [];
if (splitFilters.length > 0) {
// only transform split_filter filters if we have filters
splitFilters.forEach(filter => {
if (typeof filter.filter === 'string') {
const filterfilterObject = {
query: filter.filter,
language: 'lucene',
};
filter.filter = filterfilterObject;
}
});
}
}
});
newDoc.attributes.visState = JSON.stringify(visState);
}
}
return newDoc;
}

function migrateFiltersAggQuery(doc) {
const visStateJSON = get(doc, 'attributes.visState');
Expand Down Expand Up @@ -435,6 +479,10 @@ const executeSearchMigrations740 = flow(
migrateSearchSortToNestedArray,
);

const executeMigrations750 = flow(
transformSplitFiltersStringToQueryObject
);

export const migrations = {
'index-pattern': {
'6.5.0': doc => {
Expand Down Expand Up @@ -541,6 +589,7 @@ export const migrations = {
'7.2.0': doc => executeMigrations720(doc),
'7.3.0': executeMigrations730,
'7.3.1': executeVisualizationMigrations731,
'7.5.0': executeMigrations750,
},
dashboard: {
'7.0.0': doc => {
Expand Down
115 changes: 115 additions & 0 deletions src/legacy/core_plugins/kibana/migrations/migrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,121 @@ Array [
expect(migratedDoc).toEqual({ attributes: { visState: JSON.stringify(expected) } });
});
});
describe('7.5.0 tsvb split_filters migration', () => {
const migrate = doc => migrations.visualization['7.5.0'](doc);
const generateDoc = ({ params }) => ({
attributes: {
title: 'My Vis',
description: 'This is my super cool vis.',
visState: JSON.stringify({ params }),
uiStateJSON: '{}',
version: 1,
kibanaSavedObjectMeta: {
searchSourceJSON: '{}',
},
},
});
it('should change series item filters from a string into an object for all filters', () => {
const params = {
type: 'timeseries',
filter: {
query: 'bytes:>1000',
language: 'lucene'
},
series: [
{
split_filters: [{ filter: 'bytes:>1000' }],
},
]
};
const timeSeriesDoc = generateDoc({ params: params });
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
const timeSeriesParams = JSON.parse(migratedtimeSeriesDoc.attributes.visState).params;
expect(Object.keys(timeSeriesParams.filter)).toEqual(
expect.arrayContaining(['query', 'language'])
);
TinaHeiligers marked this conversation as resolved.
Show resolved Hide resolved
expect(Object.keys(timeSeriesParams.series[0].split_filters[0].filter)).toEqual(
expect.arrayContaining(['query', 'language'])
);
});
it('should change series item split filters when there is no filter item', () => {
const params = {
type: 'timeseries',
filter: {
query: 'bytes:>1000',
language: 'lucene'
},
series: [
{
split_filters: [{ filter: 'bytes:>1000' }],
},
],
annotations: [
{
query_string: {
query: 'bytes:>1000',
language: 'lucene'
}
}
],
};
const timeSeriesDoc = generateDoc({ params: params });
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
const timeSeriesParams = JSON.parse(migratedtimeSeriesDoc.attributes.visState).params;
expect(timeSeriesParams.series[0].split_filters[0].filter).toHaveProperty('query');
});
it('should not error out if there are no split filter items', () => {
const params = {
type: 'timeseries',
filter: {
query: 'bytes:>1000',
language: 'lucene'
},
series: [
{
split_filters: [],
},
]
};
const timeSeriesDoc = generateDoc({ params: params });
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
const timeSeriesParams = JSON.parse(migratedtimeSeriesDoc.attributes.visState).params;
expect(timeSeriesParams.series[0].split_filters).not.toHaveProperty;
TinaHeiligers marked this conversation as resolved.
Show resolved Hide resolved
});
it('should do nothing if a split_filter is already a query:language object', () => {
const params = {
type: 'timeseries',
filter: {
query: 'bytes:>1000',
language: 'lucene'
},
series: [
{
split_filters: [{
filter: {
query: 'bytes:>1000',
language: 'lucene',
}
}],
},
],
annotations: [
{
query_string: {
query: 'bytes:>1000',
language: 'lucene'
}
}
],
};
const timeSeriesDoc = generateDoc({ params: params });
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
const timeSeriesParams = JSON.parse(migratedtimeSeriesDoc.attributes.visState).params;
expect(timeSeriesParams.series[0].split_filters[0].filter.query).toEqual('bytes:>1000');
expect(timeSeriesParams.series[0].split_filters[0].filter.language).toEqual('lucene');

});
});
});

describe('dashboard', () => {
Expand Down
4 changes: 1 addition & 3 deletions test/api_integration/apis/saved_objects/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ export default function ({ getService }) {
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
}
],
migrationVersion: {
visualization: '7.3.1',
},
migrationVersion: resp.body.saved_objects[0].migrationVersion,
updated_at: '2017-09-21T18:51:23.794Z',
version: 'WzIsMV0=',
},
Expand Down