-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Do not mutate config in place during deprecations #99629
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf08463
refactor config deprecations to avoid config mutations
mshustov 04c837a
remove dynamic access keys in core deprecations.
mshustov 4c29b45
refactor custom config deprecations to match the new signature
mshustov e51543e
improve config deprecations fixtures for nested keys
mshustov 346d20f
add a test for xpack.banner config deprecations
mshustov da506e7
Merge branch 'master' into issue-97791
mshustov 03532f9
key --> path, add a test for invalid command
mshustov File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
* Side Public License, v 1. | ||
*/ | ||
|
||
import { cloneDeep } from 'lodash'; | ||
import { cloneDeep, unset } from 'lodash'; | ||
import { set } from '@elastic/safer-lodash-set'; | ||
import { ConfigDeprecationWithContext, AddConfigDeprecation } from './types'; | ||
|
||
const noopAddDeprecationFactory: () => AddConfigDeprecation = () => () => undefined; | ||
|
@@ -22,9 +23,21 @@ export const applyDeprecations = ( | |
deprecations: ConfigDeprecationWithContext[], | ||
createAddDeprecation: (pluginId: string) => AddConfigDeprecation = noopAddDeprecationFactory | ||
) => { | ||
let processed = cloneDeep(config); | ||
const result = cloneDeep(config); | ||
deprecations.forEach(({ deprecation, path }) => { | ||
processed = deprecation(processed, path, createAddDeprecation(path)); | ||
const commands = deprecation(result, path, createAddDeprecation(path)); | ||
if (commands) { | ||
if (commands.set) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I will change in a follow-up |
||
commands.set.forEach(function ({ path: commandPath, value }) { | ||
set(result, commandPath, value); | ||
}); | ||
} | ||
if (commands.unset) { | ||
commands.unset.forEach(function ({ path: commandPath }) { | ||
unset(result, commandPath); | ||
}); | ||
} | ||
} | ||
}); | ||
return processed; | ||
return result; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bamieh In a follow-up, we can store all the commands to report them later. Do we need original values? Or config keys only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mshustov for the telemetry collector we'd only need the deprecated config keys