Thales Macedo Garitezi 2 лет назад
Родитель
Сommit
697c8f5ee1

+ 8 - 6
apps/emqx_bridge/src/emqx_bridge.erl

@@ -347,14 +347,16 @@ lookup(Type, Name, RawConf) ->
             }}
     end.
 
-get_metrics(Type, Name) ->
-    case emqx_bridge_v2:is_bridge_v2_type(Type) of
+get_metrics(ActionType, Name) ->
+    case emqx_bridge_v2:is_bridge_v2_type(ActionType) of
         true ->
-            case emqx_bridge_v2:bridge_v1_is_valid(Type, Name) of
+            case emqx_bridge_v2:bridge_v1_is_valid(ActionType, Name) of
                 true ->
-                    BridgeV2Type = emqx_bridge_v2:bridge_v2_type_to_connector_type(Type),
+                    BridgeV2Type = emqx_bridge_v2:bridge_v2_type_to_connector_type(ActionType),
                     try
-                        ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one(Type, Name),
+                        ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one(
+                            ActionType, Name
+                        ),
                         emqx_bridge_v2:get_metrics(ConfRootKey, BridgeV2Type, Name)
                     catch
                         error:Reason ->
@@ -364,7 +366,7 @@ get_metrics(Type, Name) ->
                     {error, not_bridge_v1_compatible}
             end;
         false ->
-            emqx_resource:get_metrics(emqx_bridge_resource:resource_id(Type, Name))
+            emqx_resource:get_metrics(emqx_bridge_resource:resource_id(ActionType, Name))
     end.
 
 maybe_upgrade(mqtt, Config) ->

+ 1 - 0
apps/emqx_bridge/src/emqx_bridge_v2.erl

@@ -46,6 +46,7 @@
     %% The remove/2 function is only for internal use as it may create
     %% rules with broken dependencies
     remove/2,
+    remove/3,
     %% The following is the remove function that is called by the HTTP API
     %% It also checks for rule action dependencies and optionally removes
     %% them

+ 4 - 13
apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl

@@ -188,18 +188,7 @@ end_per_testcase(_, Config) ->
     ok.
 
 clear_resources() ->
-    lists:foreach(
-        fun(#{type := Type, name := Name}) ->
-            ok = emqx_bridge_v2:remove(Type, Name)
-        end,
-        emqx_bridge_v2:list()
-    ),
-    lists:foreach(
-        fun(#{type := Type, name := Name}) ->
-            ok = emqx_connector:remove(Type, Name)
-        end,
-        emqx_connector:list()
-    ),
+    emqx_bridge_v2_testlib:delete_all_bridges_and_connectors(),
     lists:foreach(
         fun(#{type := Type, name := Name}) ->
             ok = emqx_bridge:remove(Type, Name)
@@ -1026,9 +1015,11 @@ t_with_redact_update(Config) ->
     BridgeConf = emqx_utils:redact(Template),
     BridgeID = emqx_bridge_resource:bridge_id(Type, Name),
     {ok, 200, _} = request(put, uri(["bridges", BridgeID]), BridgeConf, Config),
+    %% bridge is migrated after creation
+    ConfigRootKey = connectors,
     ?assertEqual(
         Password,
-        get_raw_config([bridges, Type, Name, password], Config)
+        get_raw_config([ConfigRootKey, Type, Name, password], Config)
     ),
 
     %% probe with new password; should not be considered redacted

+ 8 - 2
apps/emqx_bridge/test/emqx_bridge_v2_testlib.erl

@@ -96,9 +96,15 @@ delete_all_bridges_and_connectors() ->
 delete_all_bridges() ->
     lists:foreach(
         fun(#{name := Name, type := Type}) ->
-            emqx_bridge_v2:remove(Type, Name)
+            emqx_bridge_v2:remove(actions, Type, Name)
         end,
-        emqx_bridge_v2:list()
+        emqx_bridge_v2:list(actions)
+    ),
+    lists:foreach(
+        fun(#{name := Name, type := Type}) ->
+            emqx_bridge_v2:remove(sources, Type, Name)
+        end,
+        emqx_bridge_v2:list(sources)
     ).
 
 delete_all_connectors() ->

+ 9 - 3
apps/emqx_bridge_http/test/emqx_bridge_http_SUITE.erl

@@ -244,6 +244,12 @@ parse_http_request_assertive(ReqStr0) ->
 %% Helper functions
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+get_metrics(Name) ->
+    %% Note: `emqx_bridge:get_metrics/2' is currently *only* called in prod by
+    %% `emqx_bridge_api:lookup_from_local_node' with an action (not v1 bridge) type.
+    Type = <<"http">>,
+    emqx_bridge:get_metrics(Type, Name).
+
 bridge_async_config(#{port := Port} = Config) ->
     Type = maps:get(type, Config, ?BRIDGE_TYPE),
     Name = maps:get(name, Config, ?BRIDGE_NAME),
@@ -570,7 +576,7 @@ t_path_not_found(Config) ->
                             success := 0
                         }
                     },
-                    emqx_bridge:get_metrics(?BRIDGE_TYPE, ?BRIDGE_NAME)
+                    get_metrics(?BRIDGE_NAME)
                 )
             ),
             ok
@@ -611,7 +617,7 @@ t_too_many_requests(Config) ->
                             success := 1
                         }
                     },
-                    emqx_bridge:get_metrics(?BRIDGE_TYPE, ?BRIDGE_NAME)
+                    get_metrics(?BRIDGE_NAME)
                 )
             ),
             ok
@@ -654,7 +660,7 @@ t_rule_action_expired(Config) ->
                             dropped := 1
                         }
                     },
-                    emqx_bridge:get_metrics(?BRIDGE_TYPE, ?BRIDGE_NAME)
+                    get_metrics(?BRIDGE_NAME)
                 )
             ),
             ?retry(