fix(telemetry): avoid hanging emqx_modules_app init with request
This commit is contained in:
parent
ada3b03f6e
commit
727bc712e6
|
@ -145,9 +145,13 @@ init(_Opts) ->
|
|||
{NodeUUID, ClusterUUID} = ensure_uuids(),
|
||||
{ok, State0#state{node_uuid = NodeUUID, cluster_uuid = ClusterUUID}}.
|
||||
|
||||
handle_call(enable, _From, State0) ->
|
||||
State = report_telemetry(State0),
|
||||
{reply, ok, ensure_report_timer(State)};
|
||||
handle_call(enable, _From, State) ->
|
||||
%% Wait a few moments before reporting the first telemetry, as the
|
||||
%% apps might still be starting up. Also, this avoids hanging
|
||||
%% `emqx_modules_app' initialization in case the POST request
|
||||
%% takes a lot of time.
|
||||
FirstReportTimeoutMS = timer:seconds(10),
|
||||
{reply, ok, ensure_report_timer(FirstReportTimeoutMS, State)};
|
||||
handle_call(disable, _From, State = #state{timer = Timer}) ->
|
||||
emqx_misc:cancel_timer(Timer),
|
||||
{reply, ok, State#state{timer = undefined}};
|
||||
|
@ -194,6 +198,9 @@ official_version(Version) ->
|
|||
match =:= re:run(Version, Pt, [{capture, none}]).
|
||||
|
||||
ensure_report_timer(State = #state{report_interval = ReportInterval}) ->
|
||||
ensure_report_timer(ReportInterval, State).
|
||||
|
||||
ensure_report_timer(ReportInterval, State) ->
|
||||
State#state{timer = emqx_misc:start_timer(ReportInterval, time_to_report_telemetry_data)}.
|
||||
|
||||
os_info() ->
|
||||
|
|
|
@ -367,7 +367,15 @@ t_send_after_enable(_) ->
|
|||
ok = snabbkaffe:start_trace(),
|
||||
try
|
||||
ok = emqx_telemetry:enable(),
|
||||
?assertMatch({ok, _}, ?block_until(#{?snk_kind := telemetry_data_reported}, 2000, 100)),
|
||||
Timeout = 12_000,
|
||||
?assertMatch(
|
||||
{ok, _},
|
||||
?wait_async_action(
|
||||
ok = emqx_telemetry:enable(),
|
||||
#{?snk_kind := telemetry_data_reported},
|
||||
Timeout
|
||||
)
|
||||
),
|
||||
receive
|
||||
{request, post, _URL, _Headers, Body} ->
|
||||
{ok, Decoded} = emqx_json:safe_decode(Body, [return_maps]),
|
||||
|
|
Loading…
Reference in New Issue