Introduce setting aliases to migrate settings more easily.#106061
Introduce setting aliases to migrate settings more easily.#106061mosche wants to merge 2 commits intoelastic:mainfrom
Conversation
Fallback settings are not well-suited when migrating a setting from one key to another. The problem is that update consumers are not properly triggerd if both the old (fallback) and new setting are both used causing changes to be silently ignored. Alias settings behave similar to fallback settings with the difference that updates to the deprecated alias are copied to the new setting in addition. This ensures that update consumers are always triggered properly. Usage of a setting alias will always trigger a deprecation warning.
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
| } | ||
| } | ||
|
|
||
| void logDeprecatedAlias() { |
There was a problem hiding this comment.
Currently I'm always considering an alias to be deprecated. It's really just a mechanism to migrate a setting and shouldn't be used permanently.
Though, if preferred, this could be triggered by a new property, e.g. DeprecatedAlias.
|
Can fallbacks be implemented on top of aliases, so we don't have two separate concepts that do kinda the same thing but in different ways? |
I've been wondering about this myself, fair question. Fallbacks and Aliases are certainly fairly similar, but there's differences:
A few thoughts without having an ultimate answer:
|
|
I share Simon's concerns about supporting both aliases and fallbacks. While it seems like more work to have a consistent, single concept, I fear adding yet another concept to settings is going to complicate them too much. Some of the things you mention seem like bugs in the same way that fallbacks are not considered today for updates. For example:
That seems like another bug. Fallbacks are supposed to be what you have framed as aliases. While they are clunky today (eg so many method variants to take fallbacks), we should find a way to make them work consistently (and maybe that means changing the concept from fallbacks to aliases, but not having both). |
Interestingly that's one of the important differences and actually required so that fallbacks work as intended. Reasons is public final T get(Settings primary, Settings secondary) {
if (exists(primary)) {
return get(primary);
}
if (exists(secondary)) {
return get(secondary);
}
if (fallbackSetting == null) {
return get(primary);
}
if (fallbackSetting.exists(primary)) {
return fallbackSetting.get(primary);
}
return fallbackSetting.get(secondary);
}which is called from Another feature fallbacks support is a chain of fallbacks. I think I've seen at least one place using multiple levels of fallbacks. With the above in mind I'll give this another look to see if I can actually do the opposite, implement the alias behavior on top of fallbacks. I expect that
The variants are definitely a hassle regardless if alias or fallback. I think it would greatly improve things if moving away from the current factory methods capturing everything in all the possible combinations to a more fluent configuration style starting off a few factories with a basic, common usage pattern. Anyways, that's a much simpler and separate thing to look at. |
|
For simple & list settings this can be re-implemented on top of fallbacks without much effort. When looking into affix settings I ran into #106284. Also, I wouldn't be surprised to find more bugs there. My proposal would be to:
|
|
Do more complex settings still need to be kept separate between fallbacks and aliases? What's the plan to combine those at some point in the future, or does that need the more exhaustive tests first? |
Most of all, the implementation is buggy and needs more through testing to identify the gaps first. |
|
That looks sensible to me - implementing one on top of the other, and increasing test coverage, should get us to a good solution |
|
Closed, in favor of #106997 |
Fallback settings are not well-suited when migrating a setting from one key to another. The problem is that update consumers are not properly triggered if both the old (fallback) and new setting are present causing changes to be silently ignored if the old version is used.
Alias settings behave similar to fallback settings with the difference that updates to the deprecated alias are copied to the new setting in addition. This ensures that update consumers are always triggered properly to ensure a more intuitive / less confusing behavior.
Usage of a setting alias will always trigger a deprecation warning.
(relates to ES-7815)