Skip to content

Commit b405eec

Browse files
committed
Add condition to avoid sanitizing every doc.
1 parent b387983 commit b405eec

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

x-pack/plugins/upgrade_assistant/server/saved_object_types/migrations/telemetry_saved_object_migrations.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,39 @@
55
* 2.0.
66
*/
77

8-
import { omit, flow } from 'lodash';
8+
import { get, omit, flow, some } from 'lodash';
99
import type { SavedObjectMigrationFn } from 'kibana/server';
1010

1111
const v716RemoveUnusedTelemetry: SavedObjectMigrationFn<any, any> = (doc) => {
1212
// Dynamically defined in 6.7 (https://github.com/elastic/kibana/pull/28878)
1313
// and then statically defined in 7.8 (https://github.com/elastic/kibana/pull/64332).
1414
const attributesBlocklist = [
15-
'ui_open.overview',
1615
'ui_open.cluster',
1716
'ui_open.indices',
17+
'ui_open.overview',
1818
'ui_reindex.close',
1919
'ui_reindex.open',
2020
'ui_reindex.start',
2121
'ui_reindex.stop',
2222
];
2323

24-
try {
25-
return {
26-
...doc,
27-
attributes: {
28-
...omit(doc.attributes, attributesBlocklist),
29-
},
30-
};
31-
} catch (e) {
32-
// Let it go, the data is invalid and we'll leave it as is
24+
const isDocEligible = some(attributesBlocklist, (attribute: string) => {
25+
return get(doc, 'attributes', attribute);
26+
});
27+
28+
if (isDocEligible) {
29+
try {
30+
return {
31+
...doc,
32+
attributes: {
33+
...omit(doc.attributes, attributesBlocklist),
34+
},
35+
};
36+
} catch (e) {
37+
// Let it go, the data is invalid and we'll leave it as is
38+
}
3339
}
40+
3441
return doc;
3542
};
3643

0 commit comments

Comments
 (0)