summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Cogoluègnes <acogoluegnes@gmail.com>2018-05-21 17:39:52 +0100
committerArnaud Cogoluègnes <acogoluegnes@gmail.com>2018-05-21 17:39:52 +0100
commit8b062c4fdea4b5df7d897d52e04c6a46f84cdc8f (patch)
treed3cc43ff09bd734b171323f3e33fb303926cf372
parent99ea452490a8bed98a8840c604759e189edf0f15 (diff)
downloadrabbitmq-server-git-8b062c4fdea4b5df7d897d52e04c6a46f84cdc8f.tar.gz
Add connection_user_provided_name to connection created/closed events
Fixes #1596 [#157500358]
-rw-r--r--src/rabbit_reader.erl38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 8b6d640dec..4e6ef103b0 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -134,7 +134,7 @@
peer_cert_validity, auth_mechanism, ssl_protocol,
ssl_key_exchange, ssl_cipher, ssl_hash, protocol, user, vhost,
timeout, frame_max, channel_max, client_properties, connected_at,
- node, user_who_performed_action]).
+ node, user_who_performed_action, connection_user_provided_name]).
-define(INFO_KEYS, ?CREATION_EVENT_KEYS ++ ?STATISTICS_KEYS -- [pid]).
@@ -394,10 +394,17 @@ start_connection(Parent, HelperSup, Deb, Sock) ->
Properties ->
Properties
end,
+ ConnectionUserProvidedName = case get(connection_user_provided_name) of
+ undefined ->
+ '';
+ ConnectionName ->
+ ConnectionName
+ end,
rabbit_event:notify(connection_closed, [{name, Name},
{pid, self()},
{node, node()},
- {client_properties, ClientProperties}])
+ {client_properties, ClientProperties},
+ {connection_user_provided_name, ConnectionUserProvidedName}])
end,
done.
@@ -1140,6 +1147,7 @@ handle_method0(#'connection.start_ok'{mechanism = Mechanism,
% adding client properties to process dictionary to send them later
% in the connection_closed event
put(client_properties, ClientProperties),
+ put(connection_user_provided_name, user_provided_connection_name(Connection2)),
auth_phase(Response, State);
handle_method0(#'connection.secure_ok'{response = Response},
@@ -1469,6 +1477,13 @@ ic(client_properties, #connection{client_properties = CP}) -> CP;
ic(auth_mechanism, #connection{auth_mechanism = none}) -> none;
ic(auth_mechanism, #connection{auth_mechanism = {Name, _Mod}}) -> Name;
ic(connected_at, #connection{connected_at = T}) -> T;
+ic(connection_user_provided_name, C) ->
+ case user_provided_connection_name(C) of
+ undefined ->
+ '';
+ ConnectionUserProvidedName ->
+ ConnectionUserProvidedName
+ end;
ic(Item, #connection{}) -> throw({bad_argument, Item}).
socket_info(Get, Select, #v1{sock = Sock}) ->
@@ -1671,16 +1686,23 @@ control_throttle(State = #v1{connection_state = CS,
_ -> State1
end.
-augment_connection_log_name(#connection{client_properties = ClientProperties,
- name = Name} = Connection) ->
- case rabbit_misc:table_lookup(ClientProperties, <<"connection_name">>) of
- {longstr, UserSpecifiedName} ->
+augment_connection_log_name(#connection{name = Name} = Connection) ->
+ case user_provided_connection_name(Connection) of
+ undefined ->
+ Connection;
+ UserSpecifiedName ->
LogName = <<Name/binary, " - ", UserSpecifiedName/binary>>,
rabbit_log_connection:info("Connection ~p (~s) has a client-provided name: ~s~n", [self(), Name, UserSpecifiedName]),
?store_proc_name(LogName),
- Connection#connection{log_name = LogName};
+ Connection#connection{log_name = LogName}
+ end.
+
+user_provided_connection_name(#connection{client_properties = ClientProperties}) ->
+ case rabbit_misc:table_lookup(ClientProperties, <<"connection_name">>) of
+ {longstr, UserSpecifiedName} ->
+ UserSpecifiedName;
_ ->
- Connection
+ undefined
end.
dynamic_connection_name(Default) ->