Merge pull request #13156 from savonarola/0529-fix-dashboard-monitor
fix(dashboard_monitor): correctly merge old and new sample data
This commit is contained in:
commit
b657dc537c
|
@ -209,7 +209,7 @@ do_call(Request) ->
|
||||||
gen_server:call(?MODULE, Request, 5000).
|
gen_server:call(?MODULE, Request, 5000).
|
||||||
|
|
||||||
do_sample(all, Time) ->
|
do_sample(all, Time) ->
|
||||||
do_sample(mria:cluster_nodes(running), Time, #{});
|
do_sample(emqx:running_nodes(), Time, #{});
|
||||||
do_sample(Node, Time) when Node == node() ->
|
do_sample(Node, Time) when Node == node() ->
|
||||||
MS = match_spec(Time),
|
MS = match_spec(Time),
|
||||||
internal_format(ets:select(?TAB, MS));
|
internal_format(ets:select(?TAB, MS));
|
||||||
|
@ -259,7 +259,7 @@ merge_cluster_sampler_map(M1, M2) ->
|
||||||
Key =:= subscriptions_durable;
|
Key =:= subscriptions_durable;
|
||||||
Key =:= disconnected_durable_sessions
|
Key =:= disconnected_durable_sessions
|
||||||
->
|
->
|
||||||
Map#{Key => maps:get(Key, M1)};
|
Map#{Key => maps:get(Key, M1, maps:get(Key, M2, 0))};
|
||||||
(Key, Map) ->
|
(Key, Map) ->
|
||||||
Map#{Key => maps:get(Key, M1, 0) + maps:get(Key, M2, 0)}
|
Map#{Key => maps:get(Key, M1, 0) + maps:get(Key, M2, 0)}
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||||
|
-include_lib("emqx/include/asserts.hrl").
|
||||||
|
|
||||||
-define(SERVER, "http://127.0.0.1:18083").
|
-define(SERVER, "http://127.0.0.1:18083").
|
||||||
-define(BASE_PATH, "/api/v5").
|
-define(BASE_PATH, "/api/v5").
|
||||||
|
@ -191,6 +192,41 @@ t_monitor_sampler_format(_Config) ->
|
||||||
[?assert(lists:member(SamplerName, SamplerKeys)) || SamplerName <- ?SAMPLER_LIST],
|
[?assert(lists:member(SamplerName, SamplerKeys)) || SamplerName <- ?SAMPLER_LIST],
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_handle_old_monitor_data(_Config) ->
|
||||||
|
Now = erlang:system_time(second),
|
||||||
|
FakeOldData = maps:from_list(
|
||||||
|
lists:map(
|
||||||
|
fun(N) ->
|
||||||
|
Time = (Now - N) * 1000,
|
||||||
|
{Time, #{foo => 123}}
|
||||||
|
end,
|
||||||
|
lists:seq(0, 9)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
Self = self(),
|
||||||
|
|
||||||
|
ok = meck:new(emqx, [passthrough, no_history]),
|
||||||
|
ok = meck:expect(emqx, running_nodes, fun() -> [node(), 'other@node'] end),
|
||||||
|
ok = meck:new(emqx_dashboard_proto_v1, [passthrough, no_history]),
|
||||||
|
ok = meck:expect(emqx_dashboard_proto_v1, do_sample, fun('other@node', _Time) ->
|
||||||
|
Self ! sample_called,
|
||||||
|
FakeOldData
|
||||||
|
end),
|
||||||
|
|
||||||
|
{ok, _} =
|
||||||
|
snabbkaffe:block_until(
|
||||||
|
?match_event(#{?snk_kind := dashboard_monitor_flushed}),
|
||||||
|
infinity
|
||||||
|
),
|
||||||
|
?assertMatch(
|
||||||
|
#{},
|
||||||
|
hd(emqx_dashboard_monitor:samplers())
|
||||||
|
),
|
||||||
|
?assertReceive(sample_called, 1_000),
|
||||||
|
ok = meck:unload([emqx, emqx_dashboard_proto_v1]),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_monitor_api(_) ->
|
t_monitor_api(_) ->
|
||||||
{ok, _} =
|
{ok, _} =
|
||||||
snabbkaffe:block_until(
|
snabbkaffe:block_until(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix crashes on monitor dashboard page happening after update to v5.7.0.
|
Loading…
Reference in New Issue