Skip to content

Commit

Permalink
Add migration to remove obsolete attributes from telemetry saved object.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Oct 14, 2021
1 parent 7a49731 commit b77716b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { telemetrySavedObjectMigrations } from './telemetry_saved_object_migrations';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { telemetrySavedObjectMigrations } from './telemetry_saved_object_migrations';

describe('Telemetry saved object migration', () => {
describe('7.16.0', () => {
test('removes ui_open and ui_reindex attributes while preserving other attributes', () => {
const doc = {
type: 'upgrade-assistant-telemetry',
id: 'upgrade-assistant-telemetry',
attributes: {
'test.property': 5,
'ui_open.cluster': 1,
'ui_open.indices': 1,
'ui_open.overview': 1,
'ui_reindex.close': 1,
'ui_reindex.open': 1,
'ui_reindex.start': 1,
'ui_reindex.stop': 1,
},
references: [],
updated_at: '2021-09-29T21:17:17.410Z',
migrationVersion: {},
};

expect(telemetrySavedObjectMigrations['7.16.0'](doc)).toStrictEqual({
type: 'upgrade-assistant-telemetry',
id: 'upgrade-assistant-telemetry',
attributes: { 'test.property': 5 },
references: [],
updated_at: '2021-09-29T21:17:17.410Z',
migrationVersion: {},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { omit, flow } from 'lodash';
import type { SavedObjectMigrationFn } from 'kibana/server';

const v716RemoveUnusedTelemetry: SavedObjectMigrationFn<any, any> = (doc) => {
// Dynamically defined in 6.7 (https://github.com/elastic/kibana/pull/28878)
// and then statically defined in 7.8 (https://github.com/elastic/kibana/pull/64332).
const attributesBlocklist = [
'ui_open.overview',
'ui_open.cluster',
'ui_open.indices',
'ui_reindex.close',
'ui_reindex.open',
'ui_reindex.start',
'ui_reindex.stop',
];

try {
return {
...doc,
attributes: {
...omit(doc.attributes, attributesBlocklist),
},
};
} catch (e) {
// Let it go, the data is invalid and we'll leave it as is
}
return doc;
};

export const telemetrySavedObjectMigrations = {
'7.16.0': flow(v716RemoveUnusedTelemetry),
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { SavedObjectsType } from 'src/core/server';

import { UPGRADE_ASSISTANT_TYPE } from '../../common/types';
import { telemetrySavedObjectMigrations } from './migrations';

export const telemetrySavedObjectType: SavedObjectsType = {
name: UPGRADE_ASSISTANT_TYPE,
Expand All @@ -29,4 +30,5 @@ export const telemetrySavedObjectType: SavedObjectsType = {
},
},
},
migrations: telemetrySavedObjectMigrations,
};

0 comments on commit b77716b

Please sign in to comment.