Przeglądaj źródła

chore: emqx_dashboard_monitor:current_rate/0 not exported anymore

JimMoen 2 lat temu
rodzic
commit
3d6b65aced

+ 34 - 26
apps/emqx_dashboard/src/emqx_dashboard_monitor.erl

@@ -40,11 +40,14 @@
 -export([
     samplers/0,
     samplers/2,
-    current_rate/0,
     current_rate/1,
     granularity_adapter/1
 ]).
 
+-ifdef(TEST).
+-export([current_rate_cluster/0]).
+-endif.
+
 %% for rpc
 -export([do_sample/2]).
 
@@ -112,29 +115,8 @@ granularity_adapter(List) when length(List) > 1000 ->
 granularity_adapter(List) ->
     List.
 
-%% Get the current rate. Not the current sampler data.
-current_rate() ->
-    Fun =
-        fun
-            (Node, Cluster) when is_map(Cluster) ->
-                case current_rate(Node) of
-                    {ok, CurrentRate} ->
-                        merge_cluster_rate(CurrentRate, Cluster);
-                    {badrpc, Reason} ->
-                        {badrpc, {Node, Reason}}
-                end;
-            (_Node, Error) ->
-                Error
-        end,
-    case lists:foldl(Fun, #{}, mria:cluster_nodes(running)) of
-        {badrpc, Reason} ->
-            {badrpc, Reason};
-        Rate ->
-            {ok, Rate}
-    end.
-
 current_rate(all) ->
-    current_rate();
+    current_rate_cluster();
 current_rate(Node) when Node == node() ->
     try
         {ok, Rate} = do_call(current_rate),
@@ -148,7 +130,7 @@ current_rate(Node) when Node == node() ->
                 {Key, 0}
              || Key <- ?GAUGE_SAMPLER_LIST ++ maps:values(?DELTA_SAMPLER_RATE_MAP)
             ],
-            {ok, maps:from_list(Rate0)}
+            {ok, maps:merge(maps:from_list(Rate0), non_rate_value())}
     end;
 current_rate(Node) ->
     case emqx_dashboard_proto_v1:current_rate(Node) of
@@ -158,6 +140,27 @@ current_rate(Node) ->
             {ok, Rate}
     end.
 
+%% Get the current rate. Not the current sampler data.
+current_rate_cluster() ->
+    Fun =
+        fun
+            (Node, Cluster) when is_map(Cluster) ->
+                case current_rate(Node) of
+                    {ok, CurrentRate} ->
+                        merge_cluster_rate(CurrentRate, Cluster);
+                    {badrpc, Reason} ->
+                        {badrpc, {Node, Reason}}
+                end;
+            (_Node, Error) ->
+                Error
+        end,
+    case lists:foldl(Fun, #{}, mria:cluster_nodes(running)) of
+        {badrpc, Reason} ->
+            {badrpc, Reason};
+        Rate ->
+            {ok, Rate}
+    end.
+
 %% -------------------------------------------------------------------------------------------------
 %% gen_server functions
 
@@ -258,8 +261,13 @@ merge_cluster_sampler_map(M1, M2) ->
 merge_cluster_rate(Node, Cluster) ->
     Fun =
         fun
-            (topics, Value, NCluster) ->
-                NCluster#{topics => Value};
+            %% cluster-synced values
+            (topics, V, NCluster) ->
+                NCluster#{topics => V};
+            (retained_msg_count, V, NCluster) ->
+                NCluster#{retained_msg_count => V};
+            (license_quota, V, NCluster) ->
+                NCluster#{license_quota => V};
             (Key, Value, NCluster) ->
                 ClusterValue = maps:get(Key, NCluster, 0),
                 NCluster#{Key => Value + ClusterValue}

+ 4 - 0
apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl

@@ -151,7 +151,11 @@ monitor_current(get, #{bindings := Bindings}) ->
     RawNode = maps:get(node, Bindings, <<"all">>),
     emqx_utils_api:with_node_or_cluster(RawNode, fun current_rate/1).
 
+-spec current_rate(atom()) ->
+    {error, term()}
+    | {ok, Result :: map()}.
 current_rate(Node) ->
+    %% Node :: 'all' or `NodeName`
     case emqx_dashboard_monitor:current_rate(Node) of
         {badrpc, _} = BadRpc ->
             {error, BadRpc};