Skip to content

Commit 24d200f

Browse files
authored
Merge pull request #7157 from rabbitmq/mergify/bp/v3.11.x/pr-7156
Feature flags: Fix experimental feature flags inventory (backport #7156)
2 parents 5c16890 + 6adc8af commit 24d200f

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

deps/rabbit/src/rabbit_feature_flags.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,13 @@ get_state(FeatureName) when is_atom(FeatureName) ->
881881
end
882882
end.
883883

884-
-spec get_stability(feature_name() | feature_props_extended()) -> stability().
884+
-spec get_stability
885+
(FeatureName) -> Stability | undefined when
886+
FeatureName :: feature_name(),
887+
Stability :: stability();
888+
(FeatureProps) -> Stability when
889+
FeatureProps :: feature_props_extended(),
890+
Stability :: stability().
885891
%% @doc
886892
%% Returns the stability of a feature flag.
887893
%%
@@ -895,12 +901,12 @@ get_state(FeatureName) when is_atom(FeatureName) ->
895901
%% <li>`experimental': the feature flag is experimental and may change in
896902
%% the future (without a guaranteed upgrade path): enabling it in
897903
%% production is not recommended.</li>
898-
%% <li>`unavailable': the feature flag is unsupported by at least one
899-
%% node in the cluster and can not be enabled for now.</li>
900904
%% </ul>
901905
%%
902906
%% @param FeatureName The name of the feature flag to check.
903-
%% @returns `stable' or `experimental'.
907+
%% @param FeatureProps A feature flag properties map.
908+
%% @returns `required', `stable' or `experimental', or `undefined' if the
909+
%% given feature flag name doesn't correspond to a known feature flag.
904910

905911
get_stability(FeatureName) when is_atom(FeatureName) ->
906912
case rabbit_ff_registry:get(FeatureName) of

deps/rabbit/src/rabbit_ff_controller.erl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,12 +990,32 @@ merge_feature_flags(FeatureFlagsA, FeatureFlagsB) ->
990990
FeatureFlags = maps:merge(FeatureFlagsA, FeatureFlagsB),
991991
maps:map(
992992
fun(FeatureName, FeatureProps) ->
993-
FeaturePropsA = maps:get(FeatureName, FeatureFlagsA, #{}),
994-
FeaturePropsB = maps:get(FeatureName, FeatureFlagsB, #{}),
993+
%% When we collect feature flag properties from all nodes, we
994+
%% start with an empty cluster inventory (a common Erlang
995+
%% recursion pattern). This means that all feature flags are
996+
%% unknown at first.
997+
%%
998+
%% Here we must compute a global stability level for each
999+
%% feature flag, in case all nodes are not on the same page
1000+
%% (like one nodes considers a feature flag experimental, but
1001+
%% another one marks it as stable). That's why we rank stability
1002+
%% level: required > stable > experimental.
1003+
%%
1004+
%% We must distinguish an unknown feature flag (they are all
1005+
%% unknown at the beginning of the collection) from a known
1006+
%% feature flags with no explicit stability level. In the latter
1007+
%% case, `rabbit_feature_flags:get_stability/1' will consider it
1008+
%% stable. However in the former case, we must consider it
1009+
%% experimental otherwise it would default to be stable would
1010+
%% superceed an experimental level, even though all nodes agree
1011+
%% on that level, because `rabbit_feature_flags:get_stability/1'
1012+
%% would return stable as well.
1013+
UnknownProps = #{stability => experimental},
1014+
FeaturePropsA = maps:get(
1015+
FeatureName, FeatureFlagsA, UnknownProps),
1016+
FeaturePropsB = maps:get(
1017+
FeatureName, FeatureFlagsB, UnknownProps),
9951018

996-
%% There is a rank between stability levels. If a feature flag
997-
%% is required somewhere, it is required globally. Otherwise if
998-
%% it is stable somewhere, it is stable globally.
9991019
StabilityA = rabbit_feature_flags:get_stability(FeaturePropsA),
10001020
StabilityB = rabbit_feature_flags:get_stability(FeaturePropsB),
10011021
Stability = case {StabilityA, StabilityB} of

deps/rabbit/src/rabbit_ff_registry_factory.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ do_initialize_registry(RegistryVsn,
375375
"Feature flags: [~s] ~s~n",
376376
[case maps:get(FeatureName, FeatureStates, false) of
377377
true -> "x";
378-
state_changing -> "~~";
378+
state_changing -> "~";
379379
false -> " "
380380
end,
381381
FeatureName])

0 commit comments

Comments
 (0)