feat(resman): also move out metrics collection for debugging

Now `emqx_resource:list_instances_verbose/0` will populate the metrics
for each instance, for the sake of simplicity.
This commit is contained in:
Andrew Mayorov 2023-04-11 17:01:34 +03:00
parent d5ae5ebfd8
commit 9c9f39d0f7
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
4 changed files with 8 additions and 11 deletions

View File

@ -43,8 +43,7 @@
config := resource_config(),
error := term(),
state := resource_state(),
status := resource_status(),
metrics => emqx_metrics_worker:metrics()
status := resource_status()
}.
-type resource_group() :: binary().
-type creation_opts() :: #{

View File

@ -327,9 +327,12 @@ fetch_creation_opts(Opts) ->
list_instances() ->
[Id || #{id := Id} <- list_instances_verbose()].
-spec list_instances_verbose() -> [resource_data()].
-spec list_instances_verbose() -> [_ResourceDataWithMetrics :: map()].
list_instances_verbose() ->
emqx_resource_manager:list_all().
[
Res#{metrics => get_metrics(ResId)}
|| #{id := ResId} = Res <- emqx_resource_manager:list_all()
].
-spec list_instances_by_type(module()) -> [resource_id()].
list_instances_by_type(ResourceType) ->

View File

@ -258,7 +258,7 @@ reset_metrics(ResId) ->
list_all() ->
try
[
data_record_to_external_map_with_metrics(Data)
data_record_to_external_map(Data)
|| {_Id, _Group, Data} <- ets:tab2list(?ETS_TABLE)
]
catch
@ -669,11 +669,6 @@ data_record_to_external_map(Data) ->
state => Data#data.state
}.
-spec data_record_to_external_map_with_metrics(data()) -> resource_data().
data_record_to_external_map_with_metrics(Data) ->
DataMap = data_record_to_external_map(Data),
DataMap#{metrics => get_metrics(Data#data.id)}.
-spec wait_for_ready(resource_id(), integer()) -> ok | timeout | {error, term()}.
wait_for_ready(ResId, WaitTime) ->
do_wait_for_ready(ResId, WaitTime div ?WAIT_FOR_RESOURCE_DELAY).

View File

@ -1 +1 @@
Metrics now are not implicitly collected in places where API handlers don't make any use of them. Instead, a separate backplane RPC gathers cluster-wide metrics.
Metrics now are not implicitly collected in places where API handlers don't make any use of them. Instead, a separate backplane RPC gathers cluster-wide metrics.