feat: impl resource reset_metrics
This commit is contained in:
parent
fa0c4d17ee
commit
8f06a9ec62
|
@ -53,6 +53,8 @@
|
||||||
, recreate_local/4
|
, recreate_local/4
|
||||||
, remove/1 %% remove the config and stop the instance
|
, remove/1 %% remove the config and stop the instance
|
||||||
, remove_local/1
|
, remove_local/1
|
||||||
|
, reset_metrics/1
|
||||||
|
, reset_metrics_local/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% Calls to the callback module with current resource state
|
%% Calls to the callback module with current resource state
|
||||||
|
@ -184,6 +186,14 @@ remove(InstId) ->
|
||||||
remove_local(InstId) ->
|
remove_local(InstId) ->
|
||||||
call_instance(InstId, {remove, InstId}).
|
call_instance(InstId, {remove, InstId}).
|
||||||
|
|
||||||
|
-spec reset_metrics_local(instance_id()) -> ok.
|
||||||
|
reset_metrics_local(InstId) ->
|
||||||
|
call_instance(InstId, {reset_metrics, InstId}).
|
||||||
|
|
||||||
|
-spec reset_metrics(instance_id()) -> ok | {error, Reason :: term()}.
|
||||||
|
reset_metrics(InstId) ->
|
||||||
|
wrap_rpc(emqx_resource_proto_v1:reset_metrics(InstId)).
|
||||||
|
|
||||||
%% =================================================================================
|
%% =================================================================================
|
||||||
-spec query(instance_id(), Request :: term()) -> Result :: term().
|
-spec query(instance_id(), Request :: term()) -> Result :: term().
|
||||||
query(InstId, Request) ->
|
query(InstId, Request) ->
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
%% load resource instances from *.conf files
|
%% load resource instances from *.conf files
|
||||||
-export([ lookup/1
|
-export([ lookup/1
|
||||||
, get_metrics/1
|
, get_metrics/1
|
||||||
|
, reset_metrics/1
|
||||||
, list_all/0
|
, list_all/0
|
||||||
, list_group/1
|
, list_group/1
|
||||||
]).
|
]).
|
||||||
|
@ -77,6 +78,9 @@ make_test_id() ->
|
||||||
get_metrics(InstId) ->
|
get_metrics(InstId) ->
|
||||||
emqx_plugin_libs_metrics:get_metrics(resource_metrics, InstId).
|
emqx_plugin_libs_metrics:get_metrics(resource_metrics, InstId).
|
||||||
|
|
||||||
|
reset_metrics(InstId) ->
|
||||||
|
emqx_plugin_libs_metrics:reset_metrics(resource_metrics, InstId).
|
||||||
|
|
||||||
force_lookup(InstId) ->
|
force_lookup(InstId) ->
|
||||||
{ok, _Group, Data} = lookup(InstId),
|
{ok, _Group, Data} = lookup(InstId),
|
||||||
Data.
|
Data.
|
||||||
|
@ -114,6 +118,9 @@ handle_call({create_dry_run, ResourceType, Config}, _From, State) ->
|
||||||
handle_call({recreate, InstId, ResourceType, Config, Opts}, _From, State) ->
|
handle_call({recreate, InstId, ResourceType, Config, Opts}, _From, State) ->
|
||||||
{reply, do_recreate(InstId, ResourceType, Config, Opts), State};
|
{reply, do_recreate(InstId, ResourceType, Config, Opts), State};
|
||||||
|
|
||||||
|
handle_call({reset_metrics, InstId}, _From, State) ->
|
||||||
|
{reply, do_reset_metrics(InstId), State};
|
||||||
|
|
||||||
handle_call({remove, InstId}, _From, State) ->
|
handle_call({remove, InstId}, _From, State) ->
|
||||||
{reply, do_remove(InstId), State};
|
{reply, do_remove(InstId), State};
|
||||||
|
|
||||||
|
@ -222,6 +229,9 @@ do_create_dry_run(ResourceType, Config) ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
do_reset_metrics(Instance) ->
|
||||||
|
reset_metrics(Instance).
|
||||||
|
|
||||||
do_remove(Instance) ->
|
do_remove(Instance) ->
|
||||||
do_remove(Instance, true).
|
do_remove(Instance, true).
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
, create_dry_run/2
|
, create_dry_run/2
|
||||||
, recreate/4
|
, recreate/4
|
||||||
, remove/1
|
, remove/1
|
||||||
|
, reset_metrics/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-include_lib("emqx/include/bpapi.hrl").
|
-include_lib("emqx/include/bpapi.hrl").
|
||||||
|
@ -61,3 +62,8 @@ recreate(InstId, ResourceType, Config, Opts) ->
|
||||||
emqx_cluster_rpc:multicall_return(ok).
|
emqx_cluster_rpc:multicall_return(ok).
|
||||||
remove(InstId) ->
|
remove(InstId) ->
|
||||||
emqx_cluster_rpc:multicall(emqx_resource, remove_local, [InstId]).
|
emqx_cluster_rpc:multicall(emqx_resource, remove_local, [InstId]).
|
||||||
|
|
||||||
|
-spec reset_metrics(emqx_resource:instance_id()) ->
|
||||||
|
emqx_cluster_rpc:multicall_return(ok).
|
||||||
|
reset_metrics(InstId) ->
|
||||||
|
emqx_cluster_rpc:multicall(emqx_resource, reset_metrics_local, [InstId]).
|
||||||
|
|
|
@ -294,7 +294,7 @@ t_create_dry_run_local(_) ->
|
||||||
|
|
||||||
?assertEqual(undefined, whereis(test_resource)).
|
?assertEqual(undefined, whereis(test_resource)).
|
||||||
|
|
||||||
t_create_dry_run_local_failed(_) ->
|
t_create_dry_run_local_failed(_) ->
|
||||||
{Res, _} = emqx_resource:create_dry_run_local(?TEST_RESOURCE,
|
{Res, _} = emqx_resource:create_dry_run_local(?TEST_RESOURCE,
|
||||||
#{cteate_error => true}),
|
#{cteate_error => true}),
|
||||||
?assertEqual(error, Res),
|
?assertEqual(error, Res),
|
||||||
|
@ -313,6 +313,19 @@ t_test_func(_) ->
|
||||||
?assertEqual(ok, erlang:apply(emqx_resource_validator:max(array, 10), [[a,b,c,d]])),
|
?assertEqual(ok, erlang:apply(emqx_resource_validator:max(array, 10), [[a,b,c,d]])),
|
||||||
?assertEqual(ok, erlang:apply(emqx_resource_validator:max(string, 10), ["less10"])).
|
?assertEqual(ok, erlang:apply(emqx_resource_validator:max(string, 10), ["less10"])).
|
||||||
|
|
||||||
|
t_reset_metrics(_) ->
|
||||||
|
{ok, _} = emqx_resource:create(
|
||||||
|
?ID,
|
||||||
|
?DEFAULT_RESOURCE_GROUP,
|
||||||
|
?TEST_RESOURCE,
|
||||||
|
#{name => test_resource}),
|
||||||
|
|
||||||
|
#{pid := Pid} = emqx_resource:query(?ID, get_state),
|
||||||
|
emqx_resource:reset_metrics(?ID),
|
||||||
|
?assert(is_process_alive(Pid)),
|
||||||
|
ok = emqx_resource:remove(?ID),
|
||||||
|
?assertNot(is_process_alive(Pid)).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Helpers
|
%% Helpers
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue