Skip to content

[Migrations] Only reindex indices if needed#147371

Merged
gsoldevila merged 52 commits intoelastic:mainfrom
jloleysens:only-migrate-if-needed-KBNA-4488
Dec 23, 2022
Merged

[Migrations] Only reindex indices if needed#147371
gsoldevila merged 52 commits intoelastic:mainfrom
jloleysens:only-migrate-if-needed-KBNA-4488

Conversation

@jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Dec 12, 2022

Fixes #124946

Summary

Takes a step toward optimising our migration paths by only reindexing (an expensive operation) when needed by checking whether the current SO mappings have "changed".

By "changed" we mean that we have detected a new md5 checksum of any registered saved object type relative to the hashes we have stored.

How to test

These changes are constrained to the model.ts, a test was added for correctly detecting that mappings are the same during the INIT phase to send us down the correct migration path.

Additionally, we have a new Jest integration test skip_reindex.test.ts that runs Kibana and inspects the logs for the expected model transitions.

Everything else should remain the same.

Happy path for skipping reindex

RUN INIT

IF !versionMigrationIsComplete AND
   !kibana indexBelongsToLaterVersion AND
   !waitForMigrationCompletion AND
   mappingsAreUnchanged
THEN
  the migration operations must target the existing .kibana_x.y.z_001 index

RUN PREPARE_COMPATIBLE_MIGRATION (new state)
    we remove old version aliases (prevent old reads/writes), and set the current version alias (prevent old migrations)

SKIP LEGACY_SET_WRITE_BLOCK
SKIP ...
SKIP SET_SOURCE_WRITE_BLOCK 
SKIP ...
SKIP REFRESH_TARGET

RUN OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT
...
RUN MARK_VERSION_INDEX_READY
DONE

Notes

  • This optimisation will only be triggered when there are no mappings changes AND we are upgrading to a new version. This does not cover all cases. In future we will make this more sophisticated by checking for incompatible changes to mappings and only reindexing when those occur.

Related

Checklist

@jloleysens jloleysens added Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed Feature:Migrations v8.7.0 labels Dec 12, 2022
jloleysens and others added 9 commits December 13, 2022 11:11
…n" and importantly, move the mappings check further down the logic tree separate from the version check
* main: (21 commits)
  [Profiling] Remove link to 'Other' bucket (elastic#147523)
  [Synthetics UI] Add missing configuration options to the add/edit monitor forms (elastic#147265)
  [DOCS] Updates what's new pages (elastic#147483)
  [Fleet][Endpoint][RBAC V2] Update fleet router and config to allow API access via RBAC controls (elastic#145361)
  [Guided onboarding] Update guide IDs (elastic#147348)
  [Synthetics] Add synthetics settings alerting default (elastic#147339)
  [Security Solution][Endpoint] Fix Policy form being displayed as Read Only when displayed in Fleet pages (elastic#147212)
  [Cases] Save draft user comment (elastic#146327)
  [API Docs] Fix `--plugin` filter (elastic#147500)
  [Fleet] added a logic to use `destinationId` when tagging imported SOs (elastic#147439)
  Do not skip UPDATE_TARGET_MAPPINGS if upgrading to a newer stack version (elastic#147503)
  [Discover] Validate if Data View time field exists on Alert creation / editing (elastic#146324)
  [Discover] Fix Discover navigation from Lens embeddable (elastic#147000)
  Allow users to Update API Keys (elastic#146237)
  Update dependency xstate to ^4.35.0 (main) (elastic#147463)
  [Behavioral Analytics] Remove feature flag to hide functionality (elastic#147429)
  [Fleet] Add agent policy `inactivity_timeout`experimental setting (elastic#147432)
  [APM] Switching service groups from grid to flex layout (elastic#147448)
  [Fleet] Add missing endpoints to openApi specs (elastic#147452)
  [AO] Allow providing custom time range for Alert Summary Widget (elastic#147253)
  ...
@jloleysens jloleysens marked this pull request as ready for review December 15, 2022 12:51
@jloleysens jloleysens requested a review from a team as a code owner December 15, 2022 12:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @rudolf have the final review here, but the approach looks fine to me

@gsoldevila gsoldevila enabled auto-merge (squash) December 23, 2022 13:59
@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled in files

id before after diff
@kbn/analytics-shippers-fullstory 1 2 +1
@kbn/analytics-shippers-gainsight 1 2 +1
@kbn/apm-synthtrace 3 4 +1
@kbn/babel-register 1 2 +1
@kbn/bazel-packages 1 2 +1
@kbn/cli-dev-mode 1 2 +1
@kbn/core-deprecations-server-internal 2 3 +1
@kbn/core-metrics-collectors-server-internal 2 4 +2
@kbn/core-overlays-browser-internal 2 4 +2
@kbn/core-rendering-server-internal 2 4 +2
@kbn/core-saved-objects-api-server-internal 1 2 +1
@kbn/crypto-browser 1 2 +1
@kbn/docs-utils 3 4 +1
@kbn/es-query 1 2 +1
@kbn/eslint-plugin-disable 39 76 +37
@kbn/failed-test-reporter-cli 1 2 +1
@kbn/handlebars 5 9 +4
@kbn/i18n 2 3 +1
@kbn/monaco 5 10 +5
@kbn/optimizer 2 4 +2
@kbn/safer-lodash-set 5 8 +3
@kbn/securitysolution-io-ts-alerting-types 9 18 +9
@kbn/securitysolution-io-ts-list-types 14 28 +14
@kbn/shared-ux-file-picker 1 2 +1
@kbn/shared-ux-file-upload 1 2 +1
@kbn/shared-ux-link-redirect-app 1 2 +1
@kbn/storybook 1 2 +1
@kbn/ts-project-linter 2 4 +2
actions 2 4 +2
apm 13 25 +12
bfetch 1 2 +1
canvas 4 7 +3
cases 17 27 +10
cloudFullStory 1 2 +1
cloudSecurityPosture 1 2 +1
console 3 5 +2
crossClusterReplication 2 4 +2
dashboardEnhanced 2 4 +2
data 2 4 +2
dataViewEditor 1 2 +1
dataViews 2 4 +2
discover 1 2 +1
embeddable 2 4 +2
embeddableEnhanced 2 4 +2
enterpriseSearch 1 2 +1
eventAnnotation 1 2 +1
expressionError 1 2 +1
expressionImage 1 2 +1
expressionMetric 1 2 +1
expressionRepeatImage 1 2 +1
expressionRevealImage 1 2 +1
expressions 5 9 +4
expressionTagcloud 1 2 +1
files 2 4 +2
fleet 9 15 +6
home 1 2 +1
indexLifecycleManagement 1 2 +1
indexManagement 4 8 +4
infra 8 15 +7
inspector 2 4 +2
kibanaReact 4 8 +4
kibanaUsageCollection 3 6 +3
kibanaUtils 2 4 +2
lens 3 6 +3
lists 5 10 +5
maps 28 42 +14
ml 3 6 +3
monitoring 7 14 +7
observability 7 10 +3
osquery 1 2 +1
reporting 1 2 +1
ruleRegistry 2 3 +1
savedSearch 1 2 +1
screenshotting 3 5 +2
securitySolution 75 134 +59
share 2 3 +1
snapshotRestore 1 2 +1
synthetics 6 11 +5
telemetry 6 11 +5
transform 3 6 +3
triggersActionsUi 3 5 +2
uiActionsEnhanced 4 8 +4
urlForwarding 1 2 +1
usageCollection 1 2 +1
ux 3 4 +1
visTypeTimelion 1 2 +1
visTypeTimeseries 3 6 +3
visTypeVislib 2 3 +1
visTypeXy 1 2 +1
visualizations 2 4 +2
total +321

ESLint disabled line counts

id before after diff
@kbn/alerts 2 3 +1
@kbn/analytics 1 2 +1
@kbn/analytics-client 18 36 +18
@kbn/analytics-shippers-elastic-v3-browser 4 8 +4
@kbn/analytics-shippers-elastic-v3-server 19 38 +19
@kbn/analytics-shippers-fullstory 5 10 +5
@kbn/apm-config-loader 2 4 +2
@kbn/apm-synthtrace 9 17 +8
@kbn/cases-components 1 2 +1
@kbn/cli-dev-mode 4 8 +4
@kbn/coloring 1 2 +1
@kbn/content-management-table-list 2 3 +1
@kbn/core-analytics-browser-internal 10 20 +10
@kbn/core-application-browser-internal 1 2 +1
@kbn/core-chrome-browser-internal 2 4 +2
@kbn/core-elasticsearch-client-server-internal 2 4 +2
@kbn/core-elasticsearch-server-internal 1 2 +1
@kbn/core-fatal-errors-browser-internal 4 8 +4
@kbn/core-http-server-internal 2 4 +2
@kbn/core-i18n-browser-internal 1 2 +1
@kbn/core-logging-browser-internal 3 6 +3
@kbn/core-logging-server-internal 8 16 +8
@kbn/core-metrics-collectors-server-internal 1 2 +1
@kbn/core-plugins-server-internal 4 8 +4
@kbn/core-root-browser-internal 4 8 +4
@kbn/core-root-server-internal 3 6 +3
@kbn/core-saved-objects-api-server-internal 6 12 +6
@kbn/core-saved-objects-base-server-internal 3 6 +3
@kbn/core-ui-settings-server-internal 1 2 +1
@kbn/datemath 1 2 +1
@kbn/docs-utils 8 16 +8
@kbn/es 1 2 +1
@kbn/eslint-plugin-disable 23 48 +25
@kbn/eslint-plugin-imports 1 2 +1
@kbn/handlebars 4 5 +1
@kbn/i18n 1 2 +1
@kbn/i18n-react 4 6 +2
@kbn/interpreter 5 8 +3
@kbn/journeys 1 2 +1
@kbn/ml-string-hash 2 4 +2
@kbn/monaco 2 3 +1
@kbn/optimizer 4 7 +3
@kbn/peggy-loader 1 2 +1
@kbn/rison 2 4 +2
@kbn/securitysolution-autocomplete 1 2 +1
@kbn/securitysolution-exception-list-components 2 3 +1
@kbn/securitysolution-io-ts-utils 1 2 +1
@kbn/securitysolution-list-api 6 12 +6
@kbn/securitysolution-list-hooks 1 2 +1
@kbn/securitysolution-t-grid 1 2 +1
@kbn/server-http-tools 1 2 +1
@kbn/shared-ux-avatar-user-profile-components 2 4 +2
@kbn/shared-ux-file-image 2 4 +2
@kbn/shared-ux-link-redirect-app 1 2 +1
@kbn/std 1 2 +1
@kbn/storybook 1 2 +1
@kbn/test 6 12 +6
@kbn/ui-shared-deps-npm 1 2 +1
@kbn/ui-shared-deps-src 2 3 +1
@kbn/ui-theme 2 4 +2
@kbn/user-profile-components 3 6 +3
actions 22 42 +20
advancedSettings 2 3 +1
aiops 30 58 +28
alerting 70 121 +51
apm 75 144 +69
canvas 32 52 +20
cases 58 97 +39
cloudChat 2 4 +2
cloudExperiments 4 8 +4
cloudFullStory 1 2 +1
cloudGainsight 1 2 +1
cloudSecurityPosture 11 15 +4
console 36 71 +35
controls 2 4 +2
core 7 14 +7
crossClusterReplication 7 14 +7
customIntegrations 11 20 +9
dashboard 6 10 +4
data 52 92 +40
dataViewFieldEditor 9 14 +5
dataViews 12 16 +4
dataVisualizer 46 92 +46
discover 40 81 +41
embeddable 7 14 +7
embeddableEnhanced 3 4 +1
enterpriseSearch 8 15 +7
esUiShared 12 24 +12
eventLog 4 7 +3
expressionError 5 7 +2
expressionGauge 2 3 +1
expressionHeatmap 2 3 +1
expressionLegacyMetricVis 5 8 +3
expressionMetricVis 2 4 +2
expressionPartitionVis 3 5 +2
expressions 16 25 +9
expressionTagcloud 2 3 +1
expressionXY 1 2 +1
fieldFormats 5 7 +2
fileUpload 4 7 +3
fleet 56 102 +46
globalSearch 3 4 +1
globalSearchBar 1 2 +1
graph 4 8 +4
grokdebugger 1 2 +1
home 10 17 +7
indexLifecycleManagement 1 2 +1
indexManagement 14 28 +14
infra 45 84 +39
ingestPipelines 15 30 +15
interactiveSetup 10 20 +10
kibanaReact 12 23 +11
kibanaUsageCollection 6 10 +4
kibanaUtils 12 23 +11
kubernetesSecurity 7 11 +4
lens 19 37 +18
licenseApiGuard 1 2 +1
lists 18 32 +14
maps 39 76 +37
ml 564 1124 +560
monitoring 18 36 +18
notifications 4 8 +4
observability 47 90 +43
osquery 106 199 +93
painlessLab 1 2 +1
presentationUtil 10 18 +8
profiling 9 15 +6
remoteClusters 2 3 +1
reporting 4 7 +3
rollup 5 10 +5
ruleRegistry 1 2 +1
savedObjectsFinder 1 2 +1
savedObjectsTagging 2 4 +2
savedObjectsTaggingOss 1 2 +1
screenshotMode 1 2 +1
screenshotting 6 12 +6
security 24 47 +23
securitySolution 432 760 +328
sessionView 6 9 +3
share 7 13 +6
snapshotRestore 3 6 +3
spaces 1 2 +1
stackAlerts 25 46 +21
stackConnectors 78 113 +35
synthetics 69 123 +54
taskManager 22 41 +19
telemetry 1 2 +1
telemetryCollectionManager 7 14 +7
telemetryManagementSection 1 2 +1
threatIntelligence 6 10 +4
timelines 23 30 +7
transform 27 54 +27
triggersActionsUi 137 228 +91
uiActions 1 2 +1
uiActionsEnhanced 9 18 +9
unifiedFieldList 17 28 +11
unifiedHistogram 2 4 +2
unifiedSearch 23 42 +19
upgradeAssistant 9 17 +8
urlDrilldown 4 6 +2
usageCollection 2 3 +1
ux 9 16 +7
visDefaultEditor 4 7 +3
visTypeTable 4 5 +1
visTypeTimelion 5 7 +2
visTypeTimeseries 19 23 +4
visTypeVega 6 8 +2
visTypeXy 4 5 +1
visualizations 15 25 +10
watcher 3 6 +3
total +2413

Total ESLint disabled count

id before after diff
@kbn/alerts 2 3 +1
@kbn/analytics 1 2 +1
@kbn/analytics-client 18 36 +18
@kbn/analytics-shippers-elastic-v3-browser 4 8 +4
@kbn/analytics-shippers-elastic-v3-server 19 38 +19
@kbn/analytics-shippers-fullstory 6 12 +6
@kbn/analytics-shippers-gainsight 1 2 +1
@kbn/apm-config-loader 2 4 +2
@kbn/apm-synthtrace 12 21 +9
@kbn/babel-register 1 2 +1
@kbn/bazel-packages 1 2 +1
@kbn/cases-components 1 2 +1
@kbn/cli-dev-mode 5 10 +5
@kbn/coloring 1 2 +1
@kbn/content-management-table-list 2 3 +1
@kbn/core-analytics-browser-internal 10 20 +10
@kbn/core-application-browser-internal 1 2 +1
@kbn/core-chrome-browser-internal 2 4 +2
@kbn/core-deprecations-server-internal 2 3 +1
@kbn/core-elasticsearch-client-server-internal 2 4 +2
@kbn/core-elasticsearch-server-internal 1 2 +1
@kbn/core-fatal-errors-browser-internal 4 8 +4
@kbn/core-http-server-internal 2 4 +2
@kbn/core-i18n-browser-internal 1 2 +1
@kbn/core-logging-browser-internal 3 6 +3
@kbn/core-logging-server-internal 8 16 +8
@kbn/core-metrics-collectors-server-internal 3 6 +3
@kbn/core-overlays-browser-internal 2 4 +2
@kbn/core-plugins-server-internal 4 8 +4
@kbn/core-rendering-server-internal 2 4 +2
@kbn/core-root-browser-internal 4 8 +4
@kbn/core-root-server-internal 3 6 +3
@kbn/core-saved-objects-api-server-internal 7 14 +7
@kbn/core-saved-objects-base-server-internal 3 6 +3
@kbn/core-ui-settings-server-internal 1 2 +1
@kbn/crypto-browser 1 2 +1
@kbn/datemath 1 2 +1
@kbn/docs-utils 11 20 +9
@kbn/es 1 2 +1
@kbn/es-query 9 10 +1
@kbn/eslint-plugin-disable 62 124 +62
@kbn/eslint-plugin-imports 1 2 +1
@kbn/failed-test-reporter-cli 1 2 +1
@kbn/handlebars 9 14 +5
@kbn/i18n 3 5 +2
@kbn/i18n-react 4 6 +2
@kbn/interpreter 5 8 +3
@kbn/journeys 1 2 +1
@kbn/ml-string-hash 2 4 +2
@kbn/monaco 7 13 +6
@kbn/optimizer 6 11 +5
@kbn/peggy-loader 1 2 +1
@kbn/rison 2 4 +2
@kbn/safer-lodash-set 5 8 +3
@kbn/securitysolution-autocomplete 1 2 +1
@kbn/securitysolution-exception-list-components 2 3 +1
@kbn/securitysolution-io-ts-alerting-types 9 18 +9
@kbn/securitysolution-io-ts-list-types 14 28 +14
@kbn/securitysolution-io-ts-utils 1 2 +1
@kbn/securitysolution-list-api 6 12 +6
@kbn/securitysolution-list-hooks 1 2 +1
@kbn/securitysolution-t-grid 1 2 +1
@kbn/server-http-tools 1 2 +1
@kbn/shared-ux-avatar-user-profile-components 2 4 +2
@kbn/shared-ux-file-image 2 4 +2
@kbn/shared-ux-file-picker 1 2 +1
@kbn/shared-ux-file-upload 1 2 +1
@kbn/shared-ux-link-redirect-app 2 4 +2
@kbn/std 1 2 +1
@kbn/storybook 2 4 +2
@kbn/test 6 12 +6
@kbn/ts-project-linter 2 4 +2
@kbn/ui-shared-deps-npm 1 2 +1
@kbn/ui-shared-deps-src 2 3 +1
@kbn/ui-theme 2 4 +2
@kbn/user-profile-components 3 6 +3
actions 24 46 +22
advancedSettings 2 3 +1
aiops 30 58 +28
alerting 71 122 +51
apm 88 169 +81
bfetch 6 7 +1
canvas 36 59 +23
cases 75 124 +49
cloudChat 2 4 +2
cloudExperiments 4 8 +4
cloudFullStory 2 4 +2
cloudGainsight 3 4 +1
cloudSecurityPosture 12 17 +5
console 39 76 +37
controls 2 4 +2
core 7 14 +7
crossClusterReplication 9 18 +9
customIntegrations 11 20 +9
dashboard 6 10 +4
dashboardEnhanced 7 9 +2
data 54 96 +42
dataViewEditor 3 4 +1
dataViewFieldEditor 9 14 +5
dataViews 14 20 +6
dataVisualizer 46 92 +46
discover 41 83 +42
embeddable 9 18 +9
embeddableEnhanced 5 8 +3
enterpriseSearch 9 17 +8
esUiShared 12 24 +12
eventAnnotation 1 2 +1
eventLog 4 7 +3
expressionError 6 9 +3
expressionGauge 2 3 +1
expressionHeatmap 2 3 +1
expressionImage 2 3 +1
expressionLegacyMetricVis 5 8 +3
expressionMetric 2 3 +1
expressionMetricVis 2 4 +2
expressionPartitionVis 3 5 +2
expressionRepeatImage 2 3 +1
expressionRevealImage 2 3 +1
expressions 21 34 +13
expressionTagcloud 3 5 +2
expressionXY 1 2 +1
fieldFormats 5 7 +2
files 3 5 +2
fileUpload 4 7 +3
fleet 65 117 +52
globalSearch 3 4 +1
globalSearchBar 1 2 +1
graph 4 8 +4
grokdebugger 1 2 +1
home 11 19 +8
indexLifecycleManagement 2 4 +2
indexManagement 18 36 +18
infra 53 99 +46
ingestPipelines 15 30 +15
inspector 3 5 +2
interactiveSetup 10 20 +10
kibanaReact 16 31 +15
kibanaUsageCollection 9 16 +7
kibanaUtils 14 27 +13
kubernetesSecurity 7 11 +4
lens 22 43 +21
licenseApiGuard 1 2 +1
lists 23 42 +19
maps 67 118 +51
ml 567 1130 +563
monitoring 25 50 +25
notifications 4 8 +4
observability 54 100 +46
osquery 107 201 +94
painlessLab 1 2 +1
presentationUtil 10 18 +8
profiling 9 15 +6
remoteClusters 2 3 +1
reporting 5 9 +4
rollup 5 10 +5
ruleRegistry 3 5 +2
savedObjectsFinder 1 2 +1
savedObjectsTagging 2 4 +2
savedObjectsTaggingOss 1 2 +1
savedSearch 1 2 +1
screenshotMode 1 2 +1
screenshotting 9 17 +8
security 26 49 +23
securitySolution 507 894 +387
sessionView 6 9 +3
share 9 16 +7
snapshotRestore 4 8 +4
spaces 1 2 +1
stackAlerts 25 46 +21
stackConnectors 82 117 +35
synthetics 75 134 +59
taskManager 22 41 +19
telemetry 7 13 +6
telemetryCollectionManager 7 14 +7
telemetryManagementSection 1 2 +1
threatIntelligence 6 10 +4
timelines 23 30 +7
transform 30 60 +30
triggersActionsUi 140 233 +93
uiActions 1 2 +1
uiActionsEnhanced 13 26 +13
unifiedFieldList 17 28 +11
unifiedHistogram 2 4 +2
unifiedSearch 23 42 +19
upgradeAssistant 9 17 +8
urlDrilldown 4 6 +2
urlForwarding 1 2 +1
usageCollection 3 5 +2
ux 12 20 +8
visDefaultEditor 5 8 +3
visTypeTable 4 5 +1
visTypeTimelion 6 9 +3
visTypeTimeseries 22 29 +7
visTypeVega 6 8 +2
visTypeVislib 3 4 +1
visTypeXy 5 7 +2
visualizations 17 29 +12
watcher 3 6 +3
total +2734

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@gsoldevila gsoldevila merged commit bcb8a13 into elastic:main Dec 23, 2022
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Dec 23, 2022
@jloleysens jloleysens deleted the only-migrate-if-needed-KBNA-4488 branch January 3, 2023 12:01
gsoldevila added a commit that referenced this pull request Jan 17, 2023
Fixes a bug introduced by #147371.

The goal of the aforementioned PR was to avoid reindexing if the SO
mappings didn't change.
But in that scenario we are still going to perform some operations on
the index, and thus we must await for the index to be ready (aka
`WAIT_FOR_YELLOW_SOURCE`).

This PR moves the `diffMappings` check (and the corresponding
"shortcircuit") after the `WAIT_FOR_YELLOW_SOURCE` state + operation.


![image](https://user-images.githubusercontent.com/25349407/212710909-2b479d2b-a817-4929-bf21-e760e2d3a0eb.png)
gsoldevila added a commit that referenced this pull request Feb 27, 2023
In the context of migrations,
#147371 avoids reindexing during
an upgrade, provided that `diffMappings === false`.

This _alternative path_ skips some key steps that are performed before
reindexing:
* `CHECK_UNKNOWN_DOCUMENTS`
* `CALCULATE_EXCLUDE_FILTERS`

These steps enrich a search query that is used during reindexing,
effectively filtering out undesired documents.

If the mappings [match](#147371)
(or they are
[compatible](#149326)) and we _no
longer reindex_, this cleanup operation does not happen, leaving
undesired documents in our system indices.

The goal of this PR is to add an extra step in the state machine
(`CLEANUP_UNKNOWN_AND_EXCLUDED`), which will actively cleanup a system
index if we're going the _skip reindexing_ path.


![image](https://user-images.githubusercontent.com/25349407/216979691-fef40638-f990-4850-bac8-ee3e58330a7f.png)

Fixes #150299

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
gsoldevila added a commit to gsoldevila/kibana that referenced this pull request Feb 27, 2023
In the context of migrations,
elastic#147371 avoids reindexing during
an upgrade, provided that `diffMappings === false`.

This _alternative path_ skips some key steps that are performed before
reindexing:
* `CHECK_UNKNOWN_DOCUMENTS`
* `CALCULATE_EXCLUDE_FILTERS`

These steps enrich a search query that is used during reindexing,
effectively filtering out undesired documents.

If the mappings [match](elastic#147371)
(or they are
[compatible](elastic#149326)) and we _no
longer reindex_, this cleanup operation does not happen, leaving
undesired documents in our system indices.

The goal of this PR is to add an extra step in the state machine
(`CLEANUP_UNKNOWN_AND_EXCLUDED`), which will actively cleanup a system
index if we're going the _skip reindexing_ path.

![image](https://user-images.githubusercontent.com/25349407/216979691-fef40638-f990-4850-bac8-ee3e58330a7f.png)

Fixes elastic#150299

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 754e868)
gsoldevila added a commit that referenced this pull request Feb 27, 2023
# Backport

This will backport the following commits from `main` to `8.7`:
- [Introduce CLEANUP_UNKNOWN_AND_EXCLUDED step
(#149931)](#149931)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Gerard
Soldevila","email":"gerard.soldevila@elastic.co"},"sourceCommit":{"committedDate":"2023-02-27T10:43:13Z","message":"Introduce
CLEANUP_UNKNOWN_AND_EXCLUDED step (#149931)\n\nIn the context of
migrations,\r\nhttps://github.com//pull/147371 avoids
reindexing during\r\nan upgrade, provided that `diffMappings ===
false`.\r\n\r\nThis _alternative path_ skips some key steps that are
performed before\r\nreindexing:\r\n* `CHECK_UNKNOWN_DOCUMENTS`\r\n*
`CALCULATE_EXCLUDE_FILTERS`\r\n\r\nThese steps enrich a search query
that is used during reindexing,\r\neffectively filtering out undesired
documents.\r\n\r\nIf the mappings
[match](https://github.com/elastic/kibana/pull/147371)\r\n(or they
are\r\n[compatible](#149326)) and
we _no\r\nlonger reindex_, this cleanup operation does not happen,
leaving\r\nundesired documents in our system indices.\r\n\r\nThe goal of
this PR is to add an extra step in the state
machine\r\n(`CLEANUP_UNKNOWN_AND_EXCLUDED`), which will actively cleanup
a system\r\nindex if we're going the _skip reindexing_
path.\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/25349407/216979691-fef40638-f990-4850-bac8-ee3e58330a7f.png)\r\n\r\nFixes
https://github.com/elastic/kibana/issues/150299\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"754e8682d45196e519720693e036017c915c0379","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Core","release_note:skip","Feature:Migrations","backport:prev-minor","v8.7.0","v8.8.0"],"number":149931,"url":"https://github.com/elastic/kibana/pull/149931","mergeCommit":{"message":"Introduce
CLEANUP_UNKNOWN_AND_EXCLUDED step (#149931)\n\nIn the context of
migrations,\r\nhttps://github.com//pull/147371 avoids
reindexing during\r\nan upgrade, provided that `diffMappings ===
false`.\r\n\r\nThis _alternative path_ skips some key steps that are
performed before\r\nreindexing:\r\n* `CHECK_UNKNOWN_DOCUMENTS`\r\n*
`CALCULATE_EXCLUDE_FILTERS`\r\n\r\nThese steps enrich a search query
that is used during reindexing,\r\neffectively filtering out undesired
documents.\r\n\r\nIf the mappings
[match](https://github.com/elastic/kibana/pull/147371)\r\n(or they
are\r\n[compatible](#149326)) and
we _no\r\nlonger reindex_, this cleanup operation does not happen,
leaving\r\nundesired documents in our system indices.\r\n\r\nThe goal of
this PR is to add an extra step in the state
machine\r\n(`CLEANUP_UNKNOWN_AND_EXCLUDED`), which will actively cleanup
a system\r\nindex if we're going the _skip reindexing_
path.\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/25349407/216979691-fef40638-f990-4850-bac8-ee3e58330a7f.png)\r\n\r\nFixes
https://github.com/elastic/kibana/issues/150299\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"754e8682d45196e519720693e036017c915c0379"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/149931","number":149931,"mergeCommit":{"message":"Introduce
CLEANUP_UNKNOWN_AND_EXCLUDED step (#149931)\n\nIn the context of
migrations,\r\nhttps://github.com//pull/147371 avoids
reindexing during\r\nan upgrade, provided that `diffMappings ===
false`.\r\n\r\nThis _alternative path_ skips some key steps that are
performed before\r\nreindexing:\r\n* `CHECK_UNKNOWN_DOCUMENTS`\r\n*
`CALCULATE_EXCLUDE_FILTERS`\r\n\r\nThese steps enrich a search query
that is used during reindexing,\r\neffectively filtering out undesired
documents.\r\n\r\nIf the mappings
[match](https://github.com/elastic/kibana/pull/147371)\r\n(or they
are\r\n[compatible](#149326)) and
we _no\r\nlonger reindex_, this cleanup operation does not happen,
leaving\r\nundesired documents in our system indices.\r\n\r\nThe goal of
this PR is to add an extra step in the state
machine\r\n(`CLEANUP_UNKNOWN_AND_EXCLUDED`), which will actively cleanup
a system\r\nindex if we're going the _skip reindexing_
path.\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/25349407/216979691-fef40638-f990-4850-bac8-ee3e58330a7f.png)\r\n\r\nFixes
https://github.com/elastic/kibana/issues/150299\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"754e8682d45196e519720693e036017c915c0379"}}]}]
BACKPORT-->
gsoldevila added a commit that referenced this pull request Mar 1, 2023
…ex (#149326)

Fixes [#147237](#147237)

Based on the same principle as
[#147371](#147371), the goal of
this PR is to **avoid reindexing if possible**.
This time, the idea is to check whether the new mappings are still
compatible with the ones stored in ES.
To to so, we attempt to update the mappings in place in the existing
index, introducing a new `CHECK_COMPATIBLE_MAPPINGS` step:
* If the update operation fails, we assume the mappings are NOT
compatible, and we continue with the normal reindexing flow.
* If the update operation succeeds, we assume the mappings ARE
compatible, and we skip reindexing, just like
[#147371](#147371) does.


![image](https://user-images.githubusercontent.com/25349407/216979882-9fe9f034-b521-4171-b85d-50be6a13e179.png)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
bmorelli25 pushed a commit to bmorelli25/kibana that referenced this pull request Mar 10, 2023
In the context of migrations,
elastic#147371 avoids reindexing during
an upgrade, provided that `diffMappings === false`.

This _alternative path_ skips some key steps that are performed before
reindexing:
* `CHECK_UNKNOWN_DOCUMENTS`
* `CALCULATE_EXCLUDE_FILTERS`

These steps enrich a search query that is used during reindexing,
effectively filtering out undesired documents.

If the mappings [match](elastic#147371)
(or they are
[compatible](elastic#149326)) and we _no
longer reindex_, this cleanup operation does not happen, leaving
undesired documents in our system indices.

The goal of this PR is to add an extra step in the state machine
(`CLEANUP_UNKNOWN_AND_EXCLUDED`), which will actively cleanup a system
index if we're going the _skip reindexing_ path.


![image](https://user-images.githubusercontent.com/25349407/216979691-fef40638-f990-4850-bac8-ee3e58330a7f.png)

Fixes elastic#150299

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
bmorelli25 pushed a commit to bmorelli25/kibana that referenced this pull request Mar 10, 2023
…ex (elastic#149326)

Fixes [elastic#147237](elastic#147237)

Based on the same principle as
[elastic#147371](elastic#147371), the goal of
this PR is to **avoid reindexing if possible**.
This time, the idea is to check whether the new mappings are still
compatible with the ones stored in ES.
To to so, we attempt to update the mappings in place in the existing
index, introducing a new `CHECK_COMPATIBLE_MAPPINGS` step:
* If the update operation fails, we assume the mappings are NOT
compatible, and we continue with the normal reindexing flow.
* If the update operation succeeds, we assume the mappings ARE
compatible, and we skip reindexing, just like
[elastic#147371](elastic#147371) does.


![image](https://user-images.githubusercontent.com/25349407/216979882-9fe9f034-b521-4171-b85d-50be6a13e179.png)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@rudolf rudolf added the Epic:ScaleMigrations Scale upgrade migrations to millions of saved objects label Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed backport:skip This PR does not require backporting Epic:ScaleMigrations Scale upgrade migrations to millions of saved objects Feature:Migrations release_note:skip Skip the PR/issue when compiling release notes Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v8.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only migrate an index if necessary

8 participants