-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to remove obsolete attributes from telemetry saved object.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/upgrade_assistant/server/saved_object_types/migrations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
41 changes: 41 additions & 0 deletions
41
..._assistant/server/saved_object_types/migrations/telemetry_saved_object_migrations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}); | ||
}); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
...grade_assistant/server/saved_object_types/migrations/telemetry_saved_object_migrations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters