feat(telemetry): report basic exhook usage
This commit is contained in:
parent
72b87a6a7e
commit
6eed6e45c2
|
@ -349,7 +349,8 @@ get_telemetry(State0 = #state{uuid = UUID}) ->
|
|||
{authn_authz, get_authn_authz_info()},
|
||||
{gateway, get_gateway_info()},
|
||||
{rule_engine, RuleEngineInfo},
|
||||
{bridge, BridgeInfo}
|
||||
{bridge, BridgeInfo},
|
||||
{exhook, get_exhook_info()}
|
||||
]}.
|
||||
|
||||
report_telemetry(State0 = #state{url = URL}) ->
|
||||
|
@ -505,6 +506,9 @@ get_rule_engine_and_bridge_info() ->
|
|||
}
|
||||
}.
|
||||
|
||||
get_exhook_info() ->
|
||||
emqx_exhook:get_basic_usage_info().
|
||||
|
||||
bin(L) when is_list(L) ->
|
||||
list_to_binary(L);
|
||||
bin(A) when is_atom(A) ->
|
||||
|
|
|
@ -123,6 +123,26 @@ init_per_testcase(t_rule_engine_and_data_bridge_info, Config) ->
|
|||
ok = emqx_bridge_SUITE:setup_fake_telemetry_data(),
|
||||
ok = setup_fake_rule_engine_data(),
|
||||
Config;
|
||||
init_per_testcase(t_exhook_info, Config) ->
|
||||
mock_httpc(),
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
ExhookConf =
|
||||
#{
|
||||
<<"exhook">> =>
|
||||
#{
|
||||
<<"servers">> =>
|
||||
[
|
||||
#{
|
||||
<<"name">> => "myhook",
|
||||
<<"url">> => "http://127.0.0.1:9000"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{ok, _} = emqx_exhook_demo_svr:start(),
|
||||
ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf),
|
||||
{ok, _} = application:ensure_all_started(emqx_exhook),
|
||||
Config;
|
||||
init_per_testcase(_Testcase, Config) ->
|
||||
TestPID = self(),
|
||||
ok = meck:new(httpc, [non_strict, passthrough, no_history, no_link]),
|
||||
|
@ -169,6 +189,11 @@ end_per_testcase(t_rule_engine_and_data_bridge_info, _Config) ->
|
|||
]
|
||||
),
|
||||
ok;
|
||||
end_per_testcase(t_exhook_info, _Config) ->
|
||||
meck:unload(httpc),
|
||||
emqx_exhook_demo_svr:stop(),
|
||||
application:stop(emqx_exhook),
|
||||
ok;
|
||||
end_per_testcase(_Testcase, _Config) ->
|
||||
meck:unload([httpc]),
|
||||
ok.
|
||||
|
@ -391,6 +416,39 @@ t_rule_engine_and_data_bridge_info(_Config) ->
|
|||
),
|
||||
ok.
|
||||
|
||||
t_exhook_info(_Config) ->
|
||||
{ok, TelemetryData} = emqx_telemetry:get_telemetry(),
|
||||
ExhookInfo = get_value(exhook, TelemetryData),
|
||||
?assertEqual(1, maps:get(num_servers, ExhookInfo)),
|
||||
[Server] = maps:get(servers, ExhookInfo),
|
||||
?assertEqual(grpc, maps:get(driver, Server)),
|
||||
Hooks = maps:get(hooks, Server),
|
||||
?assertEqual(
|
||||
[
|
||||
'client.authenticate',
|
||||
'client.authorize',
|
||||
'client.connack',
|
||||
'client.connect',
|
||||
'client.connected',
|
||||
'client.disconnected',
|
||||
'client.subscribe',
|
||||
'client.unsubscribe',
|
||||
'message.acked',
|
||||
'message.delivered',
|
||||
'message.dropped',
|
||||
'message.publish',
|
||||
'session.created',
|
||||
'session.discarded',
|
||||
'session.resumed',
|
||||
'session.subscribed',
|
||||
'session.takenover',
|
||||
'session.terminated',
|
||||
'session.unsubscribed'
|
||||
],
|
||||
lists:sort(Hooks)
|
||||
),
|
||||
ok.
|
||||
|
||||
assert_approximate(Map, Key, Expected) ->
|
||||
Value = maps:get(Key, Map),
|
||||
?assertEqual(Expected, float_to_list(Value, [{decimals, 2}])).
|
||||
|
|
Loading…
Reference in New Issue