fix: rename to emqx_metrics_worker

This commit is contained in:
EMQ-YangM 2022-04-29 11:44:15 +08:00 committed by Shawn
parent 1e170da9e8
commit 4a6dabbe57
2 changed files with 9 additions and 9 deletions

View File

@ -173,7 +173,7 @@ do_post_config_update({?CMD_PREPEND, RawNewSource}, Sources) ->
InitedNewSource = init_source(get_source_by_type(type(RawNewSource), Sources)), InitedNewSource = init_source(get_source_by_type(type(RawNewSource), Sources)),
%% create metrics %% create metrics
TypeName = type(RawNewSource), TypeName = type(RawNewSource),
ok = emqx_plugin_libs_metrics:create_metrics( ok = emqx_metrics_worker:create_metrics(
authz_metrics, authz_metrics,
TypeName, TypeName,
[matched, allow, deny, ignore], [matched, allow, deny, ignore],
@ -194,7 +194,7 @@ do_post_config_update({{?CMD_DELETE, Type}, _RawNewSource}, _Sources) ->
OldInitedSources = lookup(), OldInitedSources = lookup(),
{OldSource, Front, Rear} = take(Type, OldInitedSources), {OldSource, Front, Rear} = take(Type, OldInitedSources),
%% delete metrics %% delete metrics
ok = emqx_plugin_libs_metrics:clear_metrics(authz_metrics, Type), ok = emqx_metrics_worker:clear_metrics(authz_metrics, Type),
ok = ensure_resource_deleted(OldSource), ok = ensure_resource_deleted(OldSource),
clear_certs(OldSource), clear_certs(OldSource),
Front ++ Rear; Front ++ Rear;
@ -268,7 +268,7 @@ init_source(#{type := Type} = Source) ->
init_metrics(Source) -> init_metrics(Source) ->
TypeName = type(Source), TypeName = type(Source),
emqx_plugin_libs_metrics:create_metrics( emqx_metrics_worker:create_metrics(
authz_metrics, authz_metrics,
TypeName, TypeName,
[matched, allow, deny, ignore], [matched, allow, deny, ignore],
@ -310,7 +310,7 @@ authorize(
ipaddr => IpAddress, ipaddr => IpAddress,
topic => Topic topic => Topic
}), }),
emqx_plugin_libs_metrics:inc(authz_metrics, AuthzSource, allow), emqx_metrics_worker:inc(authz_metrics, AuthzSource, allow),
emqx_metrics:inc(?METRIC_ALLOW), emqx_metrics:inc(?METRIC_ALLOW),
{stop, allow}; {stop, allow};
{{matched, deny}, AuthzSource} -> {{matched, deny}, AuthzSource} ->
@ -324,7 +324,7 @@ authorize(
ipaddr => IpAddress, ipaddr => IpAddress,
topic => Topic topic => Topic
}), }),
emqx_plugin_libs_metrics:inc(authz_metrics, AuthzSource, deny), emqx_metrics_worker:inc(authz_metrics, AuthzSource, deny),
emqx_metrics:inc(?METRIC_DENY), emqx_metrics:inc(?METRIC_DENY),
{stop, deny}; {stop, deny};
nomatch -> nomatch ->
@ -354,10 +354,10 @@ do_authorize(
[Connector = #{type := Type} | Tail] [Connector = #{type := Type} | Tail]
) -> ) ->
Module = authz_module(Type), Module = authz_module(Type),
emqx_plugin_libs_metrics:inc(authz_metrics, Type, matched), emqx_metrics_worker:inc(authz_metrics, Type, matched),
case Module:authorize(Client, PubSub, Topic, Connector) of case Module:authorize(Client, PubSub, Topic, Connector) of
nomatch -> nomatch ->
emqx_plugin_libs_metrics:inc(authz_metrics, Type, ignore), emqx_metrics_worker:inc(authz_metrics, Type, ignore),
do_authorize(Client, PubSub, Topic, Tail); do_authorize(Client, PubSub, Topic, Tail);
Matched -> Matched ->
{Matched, Type} {Matched, Type}

View File

@ -308,7 +308,7 @@ lookup_from_local_node(Type) ->
NodeId = node(self()), NodeId = node(self()),
try emqx_authz:lookup(Type) of try emqx_authz:lookup(Type) of
#{annotations := #{id := ResourceId}} -> #{annotations := #{id := ResourceId}} ->
Metrics = emqx_plugin_libs_metrics:get_metrics(authz_metrics, Type), Metrics = emqx_metrics_worker:get_metrics(authz_metrics, Type),
case emqx_resource:get_instance(ResourceId) of case emqx_resource:get_instance(ResourceId) of
{error, not_found} -> {error, not_found} ->
{error, {NodeId, not_found_resource}}; {error, {NodeId, not_found_resource}};
@ -316,7 +316,7 @@ lookup_from_local_node(Type) ->
{ok, {NodeId, Status, Metrics, ResourceMetrics}} {ok, {NodeId, Status, Metrics, ResourceMetrics}}
end; end;
_ -> _ ->
Metrics = emqx_plugin_libs_metrics:get_metrics(authz_metrics, Type), Metrics = emqx_metrics_worker:get_metrics(authz_metrics, Type),
{ok, {NodeId, connected, Metrics, #{}}} {ok, {NodeId, connected, Metrics, #{}}}
catch catch
_:Reason -> {error, {NodeId, list_to_binary(io_lib:format("~p", [Reason]))}} _:Reason -> {error, {NodeId, list_to_binary(io_lib:format("~p", [Reason]))}}