Skip to content

Commit 55e3569

Browse files
authored
Merge pull request #7156 from rabbitmq/fix-default-feature-flags-filtering-in-ff-controller
Feature flags: Fix experimental feature flags inventory
2 parents 70094e6 + 55cb7ec commit 55e3569

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
@@ -682,7 +682,13 @@ get_state(FeatureName) when is_atom(FeatureName) ->
682682
end
683683
end.
684684

685-
-spec get_stability(feature_name() | feature_props_extended()) -> stability().
685+
-spec get_stability
686+
(FeatureName) -> Stability | undefined when
687+
FeatureName :: feature_name(),
688+
Stability :: stability();
689+
(FeatureProps) -> Stability when
690+
FeatureProps :: feature_props_extended(),
691+
Stability :: stability().
686692
%% @doc
687693
%% Returns the stability of a feature flag.
688694
%%
@@ -696,12 +702,12 @@ get_state(FeatureName) when is_atom(FeatureName) ->
696702
%% <li>`experimental': the feature flag is experimental and may change in
697703
%% the future (without a guaranteed upgrade path): enabling it in
698704
%% production is not recommended.</li>
699-
%% <li>`unavailable': the feature flag is unsupported by at least one
700-
%% node in the cluster and can not be enabled for now.</li>
701705
%% </ul>
702706
%%
703707
%% @param FeatureName The name of the feature flag to check.
704-
%% @returns `stable' or `experimental'.
708+
%% @param FeatureProps A feature flag properties map.
709+
%% @returns `required', `stable' or `experimental', or `undefined' if the
710+
%% given feature flag name doesn't correspond to a known feature flag.
705711

706712
get_stability(FeatureName) when is_atom(FeatureName) ->
707713
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
@@ -982,12 +982,32 @@ merge_feature_flags(FeatureFlagsA, FeatureFlagsB) ->
982982
FeatureFlags = maps:merge(FeatureFlagsA, FeatureFlagsB),
983983
maps:map(
984984
fun(FeatureName, FeatureProps) ->
985-
FeaturePropsA = maps:get(FeatureName, FeatureFlagsA, #{}),
986-
FeaturePropsB = maps:get(FeatureName, FeatureFlagsB, #{}),
985+
%% When we collect feature flag properties from all nodes, we
986+
%% start with an empty cluster inventory (a common Erlang
987+
%% recursion pattern). This means that all feature flags are
988+
%% unknown at first.
989+
%%
990+
%% Here we must compute a global stability level for each
991+
%% feature flag, in case all nodes are not on the same page
992+
%% (like one nodes considers a feature flag experimental, but
993+
%% another one marks it as stable). That's why we rank stability
994+
%% level: required > stable > experimental.
995+
%%
996+
%% We must distinguish an unknown feature flag (they are all
997+
%% unknown at the beginning of the collection) from a known
998+
%% feature flags with no explicit stability level. In the latter
999+
%% case, `rabbit_feature_flags:get_stability/1' will consider it
1000+
%% stable. However in the former case, we must consider it
1001+
%% experimental otherwise it would default to be stable would
1002+
%% superceed an experimental level, even though all nodes agree
1003+
%% on that level, because `rabbit_feature_flags:get_stability/1'
1004+
%% would return stable as well.
1005+
UnknownProps = #{stability => experimental},
1006+
FeaturePropsA = maps:get(
1007+
FeatureName, FeatureFlagsA, UnknownProps),
1008+
FeaturePropsB = maps:get(
1009+
FeatureName, FeatureFlagsB, UnknownProps),
9871010

988-
%% There is a rank between stability levels. If a feature flag
989-
%% is required somewhere, it is required globally. Otherwise if
990-
%% it is stable somewhere, it is stable globally.
9911011
StabilityA = rabbit_feature_flags:get_stability(FeaturePropsA),
9921012
StabilityB = rabbit_feature_flags:get_stability(FeaturePropsB),
9931013
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
@@ -396,7 +396,7 @@ do_initialize_registry(RegistryVsn,
396396
"Feature flags: [~ts] ~ts~n",
397397
[case maps:get(FeatureName, FeatureStates, false) of
398398
true -> "x";
399-
state_changing -> "~~";
399+
state_changing -> "~";
400400
false -> " "
401401
end,
402402
FeatureName])

0 commit comments

Comments
 (0)