Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[uiSettings] always use the latest config document to create the new one #159649

Merged
merged 8 commits into from
Jun 19, 2023

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jun 14, 2023

Summary

Fix #159646

Fix the config creation-from-previous-one logic by always using the latest config for the new version's creation

Release Note

Fix a bug that could cause old Kibana deployments to loose their uiSettings after an upgrade

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:fix v8.9.0 labels Jun 14, 2023
Copy link
Contributor Author

@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.

self-review

Comment on lines +54 to 60
const matchingResults = savedConfigs.filter((savedConfig) =>
isConfigVersionUpgradeable(savedConfig.id, version)
);
if (findResult) {
return { id: findResult.id, attributes: findResult.attributes };
const mostRecentConfig = getMostRecentConfig(matchingResults);
if (mostRecentConfig) {
return { id: mostRecentConfig.id, attributes: mostRecentConfig.attributes };
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The root change. The code was making the assumption that sorting by buildNum was sufficient, but this field is indexed as keyword, not number, which cause the order to be wrong in some situations.

E.g

["9517", "16602", "63240"].sort()
>> (3) ['16602', '63240', '9517']

So we're now manually comparing the version of each matching document to make sure that the most recent is used.

Comment on lines +13 to +15
export function stripVersionQualifier(version: string): string {
return version.split('-')[0];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted from the SO service to be reused elsewhere

Comment on lines 113 to +114
type: (isNamespaceScope ? 'config' : 'config-global') as 'config' | 'config-global',
id: version,
id: stripVersionQualifier(version),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For consistency with how we're treating qualified versions (e.g X.Y.Z-SNAPSHOT or X.Y.Z-RC1) in other parts of core, especially in SO code, we're now stripping qualifiers when providing the version to the uiSettings client.

Note that this isn't directly related to the fix, but it was trivial enough to include it there.

Comment on lines 35 to 37
const config = await kibanaServer.savedObjects.get({
id: await kibanaServer.version.get(),
id: stripVersionQualifier(await kibanaServer.version.get()),
type: 'config',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only FTR test that was doing direct config access by ID using the SO client. Had to adapt for the version change described in previous comment.

@pgayvallet pgayvallet marked this pull request as ready for review June 14, 2023 11:50
@pgayvallet pgayvallet requested review from a team as code owners June 14, 2023 11:50
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@thomheymann thomheymann left a comment

Choose a reason for hiding this comment

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

security changes LGTM

const savedObjectsClient = savedObjectsClientMock.create();
savedObjectsClient.find.mockResolvedValue({
saved_objects: [
{ id: '7.2.0', attributes: 'foo' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Could there ever be a scenario where we have an invalid version value in the id field? If so, would be nice to have test coverage for it. If not, ignore this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory, there shouldn't, but life alway finds a way, so I guess adding a test wouldn't hurt

@pgayvallet pgayvallet enabled auto-merge (squash) June 19, 2023 06:09
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #43 / APM API tests fleet/migration_check.spec.ts cloud no archive Fleet migration check - cloud has_apm_integrations should be false when no APM package policies exist

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/std 64 65 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 2.2MB 2.2MB +91.0B
Unknown metric groups

API count

id before after diff
@kbn/std 100 102 +2

ESLint disabled line counts

id before after diff
enterpriseSearch 13 15 +2
securitySolution 411 415 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 14 16 +2
securitySolution 494 498 +4
total +6

History

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

@pgayvallet pgayvallet merged commit 83abc6e into elastic:main Jun 19, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:uiSettings release_note:fix Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[uiSettings] stored uiSettings can be lost after an upgrade
7 participants