Просмотр исходного кода

Merge pull request #11033 from HJianBo/fix-exproto-mountpoint

feat(exproto): abandon the mountpoint field in AuthenticateRequest
zhongwencool 2 лет назад
Родитель
Сommit
beee35bdea

+ 2 - 0
apps/emqx_gateway_exproto/priv/protos/exproto.proto

@@ -277,6 +277,8 @@ message ClientInfo {
 
   string username = 4;
 
+  // deprecated since v5.1.0
+  // the request value of `mountpoint` will be ignored after v5.1.0
   string mountpoint = 5;
 }
 

+ 22 - 5
apps/emqx_gateway_exproto/src/emqx_exproto_channel.erl

@@ -121,11 +121,11 @@ info(ctx, #channel{ctx = Ctx}) ->
 stats(#channel{subscriptions = Subs}) ->
     [
         {subscriptions_cnt, maps:size(Subs)},
-        {subscriptions_max, 0},
+        {subscriptions_max, infinity},
         {inflight_cnt, 0},
-        {inflight_max, 0},
+        {inflight_max, infinity},
         {mqueue_len, 0},
-        {mqueue_max, 0},
+        {mqueue_max, infinity},
         {mqueue_dropped, 0},
         {next_pkt_id, 0},
         {awaiting_rel_cnt, 0},
@@ -164,7 +164,8 @@ init(
     DefaultClientInfo = default_clientinfo(NConnInfo),
     ClientInfo = DefaultClientInfo#{
         listener => ListenerId,
-        enable_authn => EnableAuthn
+        enable_authn => EnableAuthn,
+        mountpoint => maps:get(mountpoint, Options, undefined)
     },
     Channel = #channel{
         ctx = Ctx,
@@ -758,7 +759,23 @@ enrich_conninfo(InClientInfo, ConnInfo) ->
     maps:merge(ConnInfo, maps:with(Ks, InClientInfo)).
 
 enrich_clientinfo(InClientInfo = #{proto_name := ProtoName}, ClientInfo) ->
-    Ks = [clientid, username, mountpoint],
+    Ks = [clientid, username],
+    case maps:get(mountpoint, InClientInfo, <<>>) of
+        <<>> ->
+            ok;
+        Mp ->
+            ?SLOG(
+                warning,
+                #{
+                    msg => "failed_to_override_mountpoint",
+                    reason =>
+                        "The mountpoint in AuthenticateRequest has been deprecated. "
+                        "Please use the `gateway.exproto.mountpoint` configuration.",
+                    requested_mountpoint => Mp,
+                    configured_mountpoint => maps:get(mountpoint, ClientInfo)
+                }
+            )
+    end,
     NClientInfo = maps:merge(ClientInfo, maps:with(Ks, InClientInfo)),
     NClientInfo#{protocol => proto_name_to_protocol(ProtoName)}.
 

+ 8 - 6
apps/emqx_gateway_exproto/test/emqx_exproto_SUITE.erl

@@ -128,7 +128,7 @@ init_per_group(LisType, ServiceName, Scheme, Cfg) ->
     Svrs = emqx_exproto_echo_svr:start(Scheme),
     application:load(emqx_gateway_exproto),
     emqx_common_test_helpers:start_apps(
-        [emqx_authn, emqx_gateway],
+        [emqx_conf, emqx_authn, emqx_gateway],
         fun(App) ->
             set_special_cfg(App, LisType, ServiceName, Scheme)
         end
@@ -143,7 +143,7 @@ init_per_group(LisType, ServiceName, Scheme, Cfg) ->
 
 end_per_group(_, Cfg) ->
     emqx_config:erase(gateway),
-    emqx_common_test_helpers:stop_apps([emqx_gateway, emqx_authn]),
+    emqx_common_test_helpers:stop_apps([emqx_gateway, emqx_authn, emqx_conf]),
     emqx_exproto_echo_svr:stop(proplists:get_value(servers, Cfg)).
 
 init_per_testcase(TestCase, Cfg) when
@@ -166,6 +166,7 @@ set_special_cfg(emqx_gateway, LisType, ServiceName, Scheme) ->
         #{
             server => #{bind => 9100},
             idle_timeout => 5000,
+            mountpoint => <<"ct/">>,
             handler => #{
                 address => Addrs,
                 service_name => ServiceName,
@@ -196,7 +197,8 @@ t_mountpoint_echo(Cfg) ->
         proto_name => <<"demo">>,
         proto_ver => <<"v0.1">>,
         clientid => <<"test_client_1">>,
-        mountpoint => <<"ct/">>
+        %% deperated since v5.1.0, and this value will be ignored
+        mountpoint => <<"deperated/">>
     },
     Password = <<"123456">>,
 
@@ -239,7 +241,7 @@ t_raw_publish(Cfg) ->
         proto_name => <<"demo">>,
         proto_ver => <<"v0.1">>,
         clientid => <<"test_client_1">>,
-        mountpoint => <<"ct/">>
+        mountpoint => <<>>
     },
     Password = <<"123456">>,
 
@@ -321,7 +323,7 @@ t_acl_deny(Cfg) ->
     send(Sock, SubBin),
     {ok, SubAckBin} = recv(Sock, 5000),
 
-    emqx:publish(emqx_message:make(<<"t/dn">>, <<"echo">>)),
+    emqx:publish(emqx_message:make(<<"ct/t/dn">>, <<"echo">>)),
 
     PubBin = frame_publish(<<"t/dn">>, 0, <<"echo">>),
     PubBinFailedAck = frame_puback(1),
@@ -510,7 +512,7 @@ t_hook_message_delivered(Cfg) ->
 
     emqx_hooks:add('message.delivered', {?MODULE, hook_fun5, []}, 1000),
 
-    emqx:publish(emqx_message:make(<<"t/dn">>, <<"1">>)),
+    emqx:publish(emqx_message:make(<<"ct/t/dn">>, <<"1">>)),
     PubBin1 = frame_publish(<<"t/dn">>, 0, <<"2">>),
     {ok, PubBin1} = recv(Sock, 5000),
 

+ 8 - 0
changes/ce/fix-11033.en.md

@@ -0,0 +1,8 @@
+Deprecates the `mountpoint` field in `AuthenticateRequest` in ExProto gateway.
+
+This field was introduced in v4.x, but in fact, in 5.0 we have provided
+`gateway.exproto.mountpoint` for configuration, so there is no need to override
+it through the Authenticate request.
+
+Additionally, updates the default value of `subscriptions_max`, `inflight_max`,
+`mqueue_max` to `infinity`