From 9118cfb4ad66d22334c74d620913062a77149e07 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Wed, 9 Feb 2022 15:41:28 +0800 Subject: [PATCH] fix(connection): revert metric names for 'recv_msg.dropped.await_pubrel_timeout' --- apps/emqx/src/emqx_connection.erl | 58 ++++++++++--------- apps/emqx/src/emqx_session.erl | 46 ++++++++------- apps/emqx/test/emqx_session_SUITE.erl | 16 ++--- .../src/emqx_mgmt_api_clients.erl | 6 +- 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/apps/emqx/src/emqx_connection.erl b/apps/emqx/src/emqx_connection.erl index 08f8ef612..43566d1df 100644 --- a/apps/emqx/src/emqx_connection.erl +++ b/apps/emqx/src/emqx_connection.erl @@ -124,35 +124,39 @@ -define(ACTIVE_N, 100). --define(INFO_KEYS, [ socktype - , peername - , sockname - , sockstate - ]). +-define(INFO_KEYS, + [ socktype + , peername + , sockname + , sockstate + ]). --define(CONN_STATS, [ recv_pkt - , recv_msg - , 'recv_msg.qos0' - , 'recv_msg.qos1' - , 'recv_msg.qos2' - , send_pkt - , send_msg - , 'send_msg.qos0' - , 'send_msg.qos1' - , 'send_msg.qos2' - , 'send_msg.dropped' - , 'send_msg.dropped.await_pubrel_timeout' - , 'send_msg.dropped.expired' - , 'send_msg.dropped.queue_full' - , 'send_msg.dropped.too_large' - ]). +-define(CONN_STATS, + [ recv_pkt + , recv_msg + , 'recv_msg.qos0' + , 'recv_msg.qos1' + , 'recv_msg.qos2' + , 'recv_msg.dropped' + , 'recv_msg.dropped.await_pubrel_timeout' + , send_pkt + , send_msg + , 'send_msg.qos0' + , 'send_msg.qos1' + , 'send_msg.qos2' + , 'send_msg.dropped' + , 'send_msg.dropped.expired' + , 'send_msg.dropped.queue_full' + , 'send_msg.dropped.too_large' + ]). --define(SOCK_STATS, [ recv_oct - , recv_cnt - , send_oct - , send_cnt - , send_pend - ]). +-define(SOCK_STATS, + [ recv_oct + , recv_cnt + , send_oct + , send_cnt + , send_pend + ]). -define(ENABLED(X), (X =/= undefined)). diff --git a/apps/emqx/src/emqx_session.erl b/apps/emqx/src/emqx_session.erl index 65a7697d2..1d888d910 100644 --- a/apps/emqx/src/emqx_session.erl +++ b/apps/emqx/src/emqx_session.erl @@ -147,27 +147,29 @@ -type(replies() :: list(publish() | pubrel())). --define(INFO_KEYS, [id, - is_persistent, - subscriptions, - upgrade_qos, - retry_interval, - await_rel_timeout, - created_at - ]). +-define(INFO_KEYS, + [ id + , is_persistent + , subscriptions + , upgrade_qos + , retry_interval + , await_rel_timeout + , created_at + ]). --define(STATS_KEYS, [subscriptions_cnt, - subscriptions_max, - inflight_cnt, - inflight_max, - mqueue_len, - mqueue_max, - mqueue_dropped, - next_pkt_id, - awaiting_rel_cnt, - awaiting_rel_max, - latency_stats - ]). +-define(STATS_KEYS, + [ subscriptions_cnt + , subscriptions_max + , inflight_cnt + , inflight_max + , mqueue_len + , mqueue_max + , mqueue_dropped + , next_pkt_id + , awaiting_rel_cnt + , awaiting_rel_max + , latency_stats + ]). -define(DEFAULT_BATCH_N, 1000). @@ -730,8 +732,8 @@ inc_delivery_expired_cnt(N) -> emqx_metrics:inc('delivery.dropped.expired', N). inc_await_pubrel_timeout(N) -> - ok = inc_pd('send_msg.dropped', N), - ok = inc_pd('send_msg.dropped.await_pubrel_timeout', N), + ok = inc_pd('recv_msg.dropped', N), + ok = inc_pd('recv_msg.dropped.await_pubrel_timeout', N), ok = emqx_metrics:inc('messages.dropped', N), emqx_metrics:inc('messages.dropped.await_pubrel_timeout', N). diff --git a/apps/emqx/test/emqx_session_SUITE.erl b/apps/emqx/test/emqx_session_SUITE.erl index bc2cb426f..9932424d7 100644 --- a/apps/emqx/test/emqx_session_SUITE.erl +++ b/apps/emqx/test/emqx_session_SUITE.erl @@ -126,19 +126,19 @@ t_unsubscribe(_) -> t_publish_qos0(_) -> ok = meck:expect(emqx_broker, publish, fun(_) -> [] end), Msg = emqx_message:make(clientid, ?QOS_0, <<"t">>, <<"payload">>), - {ok, [], Session} = emqx_session:publish(clientinfo(), 1, Msg, Session = session()), - {ok, [], Session} = emqx_session:publish(clientinfo(), undefined, Msg, Session). + {ok, [], Session} = emqx_session:publish(clientinfo(), 1, Msg, Session = session()), + {ok, [], Session} = emqx_session:publish(clientinfo(), undefined, Msg, Session). t_publish_qos1(_) -> ok = meck:expect(emqx_broker, publish, fun(_) -> [] end), Msg = emqx_message:make(clientid, ?QOS_1, <<"t">>, <<"payload">>), - {ok, [], Session} = emqx_session:publish(clientinfo(), 1, Msg, Session = session()), - {ok, [], Session} = emqx_session:publish(clientinfo(), 2, Msg, Session). + {ok, [], Session} = emqx_session:publish(clientinfo(), 1, Msg, Session = session()), + {ok, [], Session} = emqx_session:publish(clientinfo(), 2, Msg, Session). t_publish_qos2(_) -> ok = meck:expect(emqx_broker, publish, fun(_) -> [] end), Msg = emqx_message:make(clientid, ?QOS_2, <<"t">>, <<"payload">>), - {ok, [], Session} = emqx_session:publish(clientinfo(), 1, Msg, session()), + {ok, [], Session} = emqx_session:publish(clientinfo(), 1, Msg, session()), ?assertEqual(1, emqx_session:info(awaiting_rel_cnt, Session)), {ok, Session1} = emqx_session:pubrel(clientinfo(), 1, Session), ?assertEqual(0, emqx_session:info(awaiting_rel_cnt, Session1)), @@ -150,10 +150,10 @@ t_publish_qos2_with_error_return(_) -> awaiting_rel => #{1 => ts(millisecond)} }), Msg = emqx_message:make(clientid, ?QOS_2, <<"t">>, <<"payload">>), - {error, ?RC_PACKET_IDENTIFIER_IN_USE} = emqx_session:publish(clientinfo(), 1, Msg, Session), - {ok, [], Session1} = emqx_session:publish(clientinfo(), 2, Msg, Session), + {error, ?RC_PACKET_IDENTIFIER_IN_USE} = emqx_session:publish(clientinfo(), 1, Msg, Session), + {ok, [], Session1} = emqx_session:publish(clientinfo(), 2, Msg, Session), ?assertEqual(2, emqx_session:info(awaiting_rel_cnt, Session1)), - {error, ?RC_RECEIVE_MAXIMUM_EXCEEDED} = emqx_session:publish(clientinfo(), 3, Msg, Session1). + {error, ?RC_RECEIVE_MAXIMUM_EXCEEDED} = emqx_session:publish(clientinfo(), 3, Msg, Session1). t_is_awaiting_full_false(_) -> Session = session(#{max_awaiting_rel => infinity}), diff --git a/apps/emqx_management/src/emqx_mgmt_api_clients.erl b/apps/emqx_management/src/emqx_mgmt_api_clients.erl index 90b524a95..5c9747cbf 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_clients.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_clients.erl @@ -152,6 +152,10 @@ properties(client) -> <<"Number of PUBLISH QoS1 packets received">>}, {'recv_msg.qos2', integer, <<"Number of PUBLISH QoS2 packets received">>}, + {'recv_msg.dropped', integer, + <<"Number of dropped PUBLISH messages">>}, + {'recv_msg.dropped.await_pubrel_timeout', integer, + <<"Number of dropped PUBLISH messages due to waiting PUBREL timeout">>}, {recv_oct, integer, <<"Number of bytes received by EMQ X Broker (the same below)">>}, {recv_pkt, integer, @@ -170,8 +174,6 @@ properties(client) -> <<"Number of PUBLISH QoS2 messages sent">>}, {'send_msg.dropped', integer, <<"Number of dropped PUBLISH messages">>}, - {'send_msg.dropped.await_pubrel_timeout', integer, - <<"Number of dropped PUBLISH packets due to waiting PUBREL timeout">>}, {'send_msg.dropped.expired', integer, <<"Number of dropped PUBLISH messages due to expired">>}, {'send_msg.dropped.queue_full', integer,