refactor: improve bookkeeping api

This commit is contained in:
Thales Macedo Garitezi 2024-07-25 11:26:44 -03:00
parent 6dbf015c93
commit 6da71200f3
2 changed files with 5 additions and 9 deletions

View File

@ -83,9 +83,7 @@ handle_tally_routes() ->
ok. ok.
tally_routes([ClusterName | ClusterNames]) -> tally_routes([ClusterName | ClusterNames]) ->
Tab = emqx_cluster_link_extrouter:extroute_tab(), NumRoutes = emqx_cluster_link_extrouter:count(ClusterName),
Pat = emqx_cluster_link_extrouter:cluster_routes_ms(ClusterName),
NumRoutes = ets:select_count(Tab, Pat),
emqx_cluster_link_metrics:routes_set(ClusterName, NumRoutes), emqx_cluster_link_metrics:routes_set(ClusterName, NumRoutes),
tally_routes(ClusterNames); tally_routes(ClusterNames);
tally_routes([]) -> tally_routes([]) ->

View File

@ -35,7 +35,7 @@
]). ]).
%% Internal export for bookkeeping %% Internal export for bookkeeping
-export([cluster_routes_ms/1, extroute_tab/0]). -export([count/1]).
%% Strictly monotonically increasing integer. %% Strictly monotonically increasing integer.
-type smint() :: integer(). -type smint() :: integer().
@ -151,16 +151,14 @@ make_extroute_rec_pat(Entry) ->
). ).
%% Internal exports for bookkeeping %% Internal exports for bookkeeping
cluster_routes_ms(ClusterName) -> count(ClusterName) ->
TopicPat = '_', TopicPat = '_',
RouteIDPat = '_', RouteIDPat = '_',
Pat = make_extroute_rec_pat( Pat = make_extroute_rec_pat(
emqx_trie_search:make_pat(TopicPat, ?ROUTE_ID(ClusterName, RouteIDPat)) emqx_trie_search:make_pat(TopicPat, ?ROUTE_ID(ClusterName, RouteIDPat))
), ),
[{Pat, [], [true]}]. MS = [{Pat, [], [true]}],
ets:select_count(?EXTROUTE_TAB, MS).
extroute_tab() ->
?EXTROUTE_TAB.
%% %%