Skip to content

Commit

Permalink
Cleanup enabled: false saved objects mappings (#149102)
Browse files Browse the repository at this point in the history
## Summary

Clean up saved object mappings to reduce the field count and make
mappings more future-proof.

This PR attempts to remove all `enabled: false` mappings. It's not
possible to toggle the `enabled` property so it becomes impossible to
ever query over a disabled field. `type: 'object', enabled: 'false'`
also provides worse validation since it's possible to index a string
into such an object. So using `dynamic: false, properties: {}` provides
better validation and is more future-proof allowing us to query over
these fields should the need arise.

Since these fields can't be queried over it should be safe to remove
these mappings but please review and/or test to ensure there's no
regressions. If your plugin every relied on the lack of validation for
being able to ingest a `string` field into an `type: 'object', enabled:
'false'` field this PR would now cause failures.

Related: elastic/dev#2189


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
rudolf authored Feb 9, 2023
1 parent dadea40 commit 111d9d1
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 102 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const REMOVED_TYPES: string[] = [
'ui-counter',
// Deprecated, no longer used since 7.13 https://github.com/elastic/kibana/pull/94923/files
'application_usage_transactional',
// Removed in 7.8.1 / 7.9.0 https://github.com/elastic/kibana/pull/69871
'maps-telemetry',
// Deprecated, no longer used since 8.7 https://github.com/elastic/kibana/pull/148530
'csp_rule',
].sort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ describe('createInitialState', () => {
"type": "guided-setup-state",
},
},
Object {
"term": Object {
"type": "maps-telemetry",
},
},
Object {
"term": Object {
"type": "ml-telemetry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function removeLogFile() {
}

/** Number of SO documents dropped during the migration because they belong to an unused type */
const UNUSED_SO_COUNT = 4;
const UNUSED_SO_COUNT = 5;

describe('migration from 7.7.2-xpack with 100k objects', () => {
let esServer: TestElasticsearchUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
Object {
"action": "6cfc277ed3211639e37546ac625f4a68f2494215",
"action_task_params": "db2afea7d78e00e725486b791554d0d4e81956ef",
"alert": "492f749af60bed1cc7022519ddf5fe4c482b62c4",
"alert": "f81ad957a7936522482e4539c7a96a963ebdbc3e",
"api_key_pending_invalidation": "16e7bcf8e78764102d7f525542d5b616809a21ee",
"apm-indices": "d19dd7fb51f2d2cbc1f8769481721e0953f9a6d2",
"apm-server-schema": "1d42f17eff9ec6c16d3a9324d9539e2d123d0a9a",
Expand All @@ -70,7 +70,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"canvas-workpad": "ab0525bd5aa4dbad2d6fdb30e6a51bb475254751",
"canvas-workpad-template": "c54f2a188a1d0bf18a6cebd9d6f28a7337d41bbf",
"cases": "74c00dfb25f4b109894971bd1090fce4a7c99490",
"cases-comments": "b94072c8f0cb642dd6da43c833bd2d391e175ec0",
"cases-comments": "371662a8464e623f1f4f55a981cec78bec4a12f5",
"cases-configure": "25099c9e4bbb91e01e334848c605b4a5de5c9fce",
"cases-connector-mappings": "8de3b77dc6ae8ee62cce2b58a222471dfc3dbdad",
"cases-telemetry": "fdeddcef28c75d8c66422475a829e75d37f0b668",
Expand All @@ -84,7 +84,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"endpoint:user-artifact": "a5b154962fb6cdf5d9e7452e58690054c95cc72a",
"endpoint:user-artifact-manifest": "5989989c0f84dd2d02da1eb46b6254e334bd2ccd",
"enterprise_search_telemetry": "4b41830e3b28a16eb92dee0736b44ae6276ced9b",
"epm-packages": "1922a722ea42ab4953a96037fabb81a9ded8e240",
"epm-packages": "83235af7c95fd9bfb1d70996a5511e05b3fcc9ef",
"epm-packages-assets": "00c8b5e5bf059627ffc9fbde920e1ac75926c5f6",
"event_loop_delays_daily": "ef49e7f15649b551b458c7ea170f3ed17f89abd0",
"exception-list": "38181294f64fc406c15f20d85ca306c8a4feb3c0",
Expand All @@ -104,33 +104,32 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ingest-agent-policies": "e5bb18f8c1d1106139e82fccb93fce01b21fde9b",
"ingest-download-sources": "95a15b6589ef46e75aca8f7e534c493f99cc3ccd",
"ingest-outputs": "f5adeb3f6abc732a6067137e170578dbf1f58c62",
"ingest-package-policies": "f20a00d14ba0651e0dbdada40f9762926819e298",
"ingest-package-policies": "98a5f5defe00d606bfaa64f80bd745ff1465df18",
"ingest_manager_settings": "fb75bff08a8de3435b23664b1191f9244a255701",
"inventory-view": "6d47ef0b38166ecbd1c2fc7394599a4500db1ae4",
"kql-telemetry": "23ed96ff02cd69cbfaa22f313cae3a54c434db51",
"legacy-url-alias": "9b8cca3fbb2da46fd12823d3cd38fdf1c9f24bc8",
"lens": "42793535312de4e3e3df16a69cb85f5df3b14f72",
"lens-ui-telemetry": "d6c4e330d170eefc6214dbf77a53de913fa3eebc",
"map": "7902b2e2a550e0b73fd5aa6c4e2ba3a4e6558877",
"maps-telemetry": "1b2e468ec4dd1207e417b98f84b24cd87e1efd14",
"metrics-explorer-view": "713dbf1ab5e067791d19170f715eb82cf07ebbcc",
"ml-job": "12e21f1b1adfcc1052dc0b10c7459de875653b94",
"ml-module": "c88b6a012cfb7b7adb7629b1edeab6b83f1fd048",
"ml-trained-model": "49a1685d79990ad05ea1d1d30e28456fe002f3b9",
"monitoring-telemetry": "24f7393dfacb6c7b0f7ad7d242171a1c29feaa48",
"osquery-manager-usage-metric": "23a8f08a98dd0f58ab4e559daa35b06edc40ed4f",
"osquery-pack": "407f82b8f05f02a04627993e6d2a071b4d71f816",
"osquery-pack-asset": "e10ca4b6ac5dff1954b5140ed97c3187d353a029",
"osquery-saved-query": "86bd3e1d39c470375263b28437c67b4f96667bc2",
"query": "495b96d251383d44b48ad3ccd831b857f909ae41",
"osquery-pack": "edd84b2c59ef36214ece0676706da8f22175c660",
"osquery-pack-asset": "18e08979d46ee7e5538f54c080aec4d8c58516ca",
"osquery-saved-query": "f5e4e303f65c7607248ea8b2672f1ee30e4fb15e",
"query": "f94de164936da788e9215c0e9b824f8b948ea859",
"rules-settings": "9854495c3b54b16a6625fb250c35e5504da72266",
"sample-data-telemetry": "c38daf1a49ed24f2a4fb091e6e1e833fccf19935",
"search": "928589cf4b2497623faa48d22f406bab4721704c",
"search-session": "e0f495ac1b3bb40ba3eb3aea90b2d11e6c8d4c32",
"search": "01bc42d635e9ea0588741c4c7a2bbd3feb3ac5dc",
"search-session": "5f40f6101fc2ec8ce5210d735ea2e00a87c02886",
"search-telemetry": "ab67ef721f294f28d5e10febbd20653347720188",
"security-rule": "1ff82dfb2298c3caf6888fc3ef15c6bf7a628877",
"security-solution-signals-migration": "c2db409c1857d330beb3d6fd188fa186f920302c",
"siem-detection-engine-rule-actions": "dbf3747aad2b986534b052703063a7026b25f485",
"siem-detection-engine-rule-actions": "123c130dc38120a470d8db9fed9a4cebd2046445",
"siem-ui-timeline": "e9d6b3a9fd7af6dc502293c21cbdb309409f3996",
"siem-ui-timeline-note": "13c9d4c142f96624a93a623c6d7cba7e1ae9b5a6",
"siem-ui-timeline-pinned-event": "96a43d59b9e2fc11f12255a0cb47ef0a3d83af4c",
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/data/server/saved_objects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export const querySavedObjectType: SavedObjectsType = {
query: {
properties: { language: { type: 'keyword' }, query: { type: 'keyword', index: false } },
},
filters: { type: 'object', enabled: false },
timefilter: { type: 'object', enabled: false },
filters: {
dynamic: false,
properties: {},
},
timefilter: { dynamic: false, properties: {} },
},
},
migrations: savedQueryMigrations,
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/data/server/search/saved_objects/search_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export const searchSessionSavedObjectType: SavedObjectsType = {
type: 'keyword',
},
initialState: {
type: 'object',
enabled: false,
dynamic: false,
properties: {},
},
restoreState: {
type: 'object',
enabled: false,
dynamic: false,
properties: {},
},
idMapping: {
type: 'object',
enabled: false,
dynamic: false,
properties: {},
},
realmType: {
type: 'keyword',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/saved_search/server/saved_objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getSavedSearchObjectType(
},
sort: { type: 'keyword', index: false, doc_values: false },
title: { type: 'text' },
grid: { type: 'object', enabled: false },
grid: { dynamic: false, properties: {} },
version: { type: 'integer' },
rowHeight: { type: 'text' },
timeRestore: { type: 'boolean', index: false, doc_values: false },
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/saved_objects/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = {
type: 'keyword',
},
params: {
enabled: false,
type: 'object',
dynamic: false,
properties: {},
},
frequency: {
properties: {
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/cases/server/saved_object_types/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ export const createCaseCommentSavedObjectType = ({
},
externalReferenceMetadata: {
dynamic: false,
type: 'object',
enabled: false,
properties: {},
},
persistableStateAttachmentTypeId: {
type: 'keyword',
},
persistableStateAttachmentState: {
dynamic: false,
type: 'object',
enabled: false,
properties: {},
},
pushed_at: {
type: 'date',
Expand Down
55 changes: 10 additions & 45 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,48 +184,13 @@ const getSavedObjectTypes = (
},
},
elasticsearch: {
enabled: false,
properties: {
privileges: {
properties: {
cluster: { type: 'keyword' },
},
},
},
dynamic: false,
properties: {},
},
vars: { type: 'flattened' },
inputs: {
type: 'nested',
enabled: false,
properties: {
type: { type: 'keyword' },
policy_template: { type: 'keyword' },
enabled: { type: 'boolean' },
vars: { type: 'flattened' },
config: { type: 'flattened' },
compiled_input: { type: 'flattened' },
streams: {
type: 'nested',
properties: {
id: { type: 'keyword' },
enabled: { type: 'boolean' },
data_stream: {
properties: {
dataset: { type: 'keyword' },
type: { type: 'keyword' },
elasticsearch: {
properties: {
privileges: { type: 'flattened' },
},
},
},
},
vars: { type: 'flattened' },
config: { type: 'flattened' },
compiled_stream: { type: 'flattened' },
},
},
},
dynamic: false,
properties: {},
},
revision: { type: 'integer' },
updated_at: { type: 'date' },
Expand Down Expand Up @@ -264,8 +229,8 @@ const getSavedObjectTypes = (
internal: { type: 'boolean' },
keep_policies_up_to_date: { type: 'boolean', index: false },
es_index_patterns: {
enabled: false,
type: 'object',
dynamic: false,
properties: {},
},
verification_status: { type: 'keyword' },
verification_key_id: { type: 'keyword' },
Expand All @@ -278,13 +243,13 @@ const getSavedObjectTypes = (
},
},
installed_kibana: {
type: 'object',
enabled: false,
dynamic: false,
properties: {},
},
installed_kibana_space_id: { type: 'keyword' },
package_assets: {
type: 'object',
enabled: false,
dynamic: false,
properties: {},
},
install_started_at: { type: 'date' },
install_version: { type: 'keyword' },
Expand Down
17 changes: 0 additions & 17 deletions x-pack/plugins/maps/server/saved_objects/setup_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,6 @@ export function setupSavedObjects(
);
},
});

/*
* The maps-telemetry saved object type isn't used, but in order to remove these fields from
* the mappings we register this type with `type: 'object', enabled: true` to remove all
* previous fields from the mappings until https://github.com/elastic/kibana/issues/67086 is
* solved.
*/
core.savedObjects.registerType({
name: 'maps-telemetry',
hidden: false,
namespaceType: 'agnostic',
mappings: {
// @ts-ignore Core types don't support this since it's only really valid when removing a previously registered type
type: 'object',
enabled: false,
},
});
}

/**
Expand Down
Loading

0 comments on commit 111d9d1

Please sign in to comment.