fix(metrics): inc `connack.auth_error` when using MQTT 3.1
Since MQTT 3.1 uses a different reason code for auth failures, it was failing to increase the corresponding metric that works for MQTT 5.0.
This commit is contained in:
parent
8a89fb2238
commit
1ba8ad4c25
|
@ -429,8 +429,12 @@ inc_sent(Packet) ->
|
|||
|
||||
do_inc_sent(?CONNACK_PACKET(ReasonCode)) ->
|
||||
(ReasonCode == ?RC_SUCCESS) orelse inc('packets.connack.error'),
|
||||
(ReasonCode == ?RC_NOT_AUTHORIZED) andalso inc('packets.connack.auth_error'),
|
||||
(ReasonCode == ?RC_BAD_USER_NAME_OR_PASSWORD) andalso inc('packets.connack.auth_error'),
|
||||
((ReasonCode == ?RC_NOT_AUTHORIZED)
|
||||
orelse (ReasonCode == ?CONNACK_AUTH))
|
||||
andalso inc('packets.connack.auth_error'),
|
||||
((ReasonCode == ?RC_BAD_USER_NAME_OR_PASSWORD)
|
||||
orelse (ReasonCode == ?CONNACK_CREDENTIALS))
|
||||
andalso inc('packets.connack.auth_error'),
|
||||
inc('packets.connack.sent');
|
||||
|
||||
do_inc_sent(?PUBLISH_PACKET(QoS)) ->
|
||||
|
|
|
@ -277,6 +277,38 @@ t_stats_fun({'end', _Config}) ->
|
|||
ok = emqx_broker:unsubscribe(<<"topic">>),
|
||||
ok = emqx_broker:unsubscribe(<<"topic2">>).
|
||||
|
||||
t_connack_auth_error({init, Config}) ->
|
||||
process_flag(trap_exit, true),
|
||||
emqx_ct_helpers:stop_apps([]),
|
||||
emqx_ct_helpers:boot_modules(all),
|
||||
Handler =
|
||||
fun(emqx) ->
|
||||
application:set_env(emqx, acl_nomatch, deny),
|
||||
application:set_env(emqx, allow_anonymous, false),
|
||||
application:set_env(emqx, enable_acl_cache, false),
|
||||
ok;
|
||||
(_) ->
|
||||
ok
|
||||
end,
|
||||
emqx_ct_helpers:start_apps([], Handler),
|
||||
Config;
|
||||
t_connack_auth_error({'end', _Config}) ->
|
||||
emqx_ct_helpers:stop_apps([]),
|
||||
emqx_ct_helpers:boot_modules(all),
|
||||
emqx_ct_helpers:start_apps([]),
|
||||
ok;
|
||||
t_connack_auth_error(Config) when is_list(Config) ->
|
||||
%% MQTT 3.1
|
||||
?assertEqual(0, emqx_metrics:val('packets.connack.auth_error')),
|
||||
{ok, C0} = emqtt:start_link([{proto_ver, v4}]),
|
||||
?assertEqual({error, {unauthorized_client, undefined}}, emqtt:connect(C0)),
|
||||
?assertEqual(1, emqx_metrics:val('packets.connack.auth_error')),
|
||||
%% MQTT 5.0
|
||||
{ok, C1} = emqtt:start_link([{proto_ver, v5}]),
|
||||
?assertEqual({error, {not_authorized, #{}}}, emqtt:connect(C1)),
|
||||
?assertEqual(2, emqx_metrics:val('packets.connack.auth_error')),
|
||||
ok.
|
||||
|
||||
recv_msgs(Count) ->
|
||||
recv_msgs(Count, []).
|
||||
|
||||
|
|
Loading…
Reference in New Issue