Skip to content

Commit 5d67fc2

Browse files
committed
[skip ci] Simplify logging around peer discovery
1 parent 4a9a745 commit 5d67fc2

File tree

6 files changed

+62
-73
lines changed

6 files changed

+62
-73
lines changed

deps/rabbitmq_peer_discovery_common/include/rabbit_peer_discovery.hrl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
-include_lib("rabbit_common/include/logging.hrl").
99

10-
-define(RMQLOG_DOMAIN_PEER_DIS, ?DEFINE_RMQLOG_DOMAIN(peer_discovery)).
11-
1210
% rabbitmq/rabbitmq-peer-discovery-aws#25
1311
% Note: this timeout must not be greater than the default
1412
% gen_server:call timeout of 5000ms. This `timeout`,

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_cleanup.erl

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ check_cluster() ->
8484
{ok, State :: #state{}, timeout() | hibernate} |
8585
{stop, Reason :: term()} | ignore).
8686
init([]) ->
87+
logger:set_process_metadata(#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
8788
Map = ?CONFIG_MODULE:config_map(?CONFIG_KEY),
8889
case map_size(Map) of
8990
0 ->
9091
?LOG_INFO(
91-
"Peer discovery: node cleanup is disabled",
92-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
92+
"Peer discovery: node cleanup is disabled"),
9393
{ok, #state{}};
9494
_ ->
9595
Interval = ?CONFIG_MODULE:get(cleanup_interval, ?CONFIG_MAPPING, Map),
@@ -103,8 +103,7 @@ init([]) ->
103103
end,
104104
?LOG_INFO(
105105
"Peer discovery: enabling node cleanup (~ts). Check interval: ~tp seconds.",
106-
[WarnMsg, State#state.interval],
107-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
106+
[WarnMsg, State#state.interval]),
108107
{ok, State}
109108
end.
110109

@@ -126,8 +125,7 @@ init([]) ->
126125

127126
handle_call(check_cluster, _From, State) ->
128127
?LOG_DEBUG(
129-
"Peer discovery: checking for partitioned nodes to clean up.",
130-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
128+
"Peer discovery: checking for partitioned nodes to clean up."),
131129
maybe_cleanup(State),
132130
{reply, ok, State};
133131
handle_call(_Request, _From, State) ->
@@ -236,26 +234,24 @@ maybe_cleanup(State) ->
236234
UnreachableNodes :: [node()]) -> ok.
237235
maybe_cleanup(_, []) ->
238236
?LOG_DEBUG(
239-
"Peer discovery: all known cluster nodes are up.",
240-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS});
237+
"Peer discovery: all known cluster nodes are up.");
238+
241239
maybe_cleanup(State, UnreachableNodes) ->
242240
?LOG_DEBUG(
243241
"Peer discovery: cleanup discovered unreachable nodes: ~tp",
244-
[UnreachableNodes],
245-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
242+
[UnreachableNodes]),
246243
case lists:subtract(as_list(UnreachableNodes), as_list(service_discovery_nodes())) of
247244
[] ->
248245
?LOG_DEBUG(
249246
"Peer discovery: all unreachable nodes are still "
250247
"registered with the discovery backend ~tp",
251248
[rabbit_peer_discovery:backend()],
252-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
249+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
253250
ok;
254251
Nodes ->
255252
?LOG_DEBUG(
256253
"Peer discovery: unreachable nodes are not registered "
257-
"with the discovery backend ~tp", [Nodes],
258-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
254+
"with the discovery backend ~tp", [Nodes]),
259255
maybe_remove_nodes(Nodes, State#state.warn_only)
260256
end.
261257

@@ -272,17 +268,14 @@ maybe_cleanup(State, UnreachableNodes) ->
272268
maybe_remove_nodes([], _) -> ok;
273269
maybe_remove_nodes([Node | Nodes], true) ->
274270
?LOG_WARNING(
275-
"Peer discovery: node ~ts is unreachable", [Node],
276-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
271+
"Peer discovery: node ~ts is unreachable", [Node]),
277272
maybe_remove_nodes(Nodes, true);
278273
maybe_remove_nodes([Node | Nodes], false) ->
279274
?LOG_WARNING(
280-
"Peer discovery: removing unknown node ~ts from the cluster", [Node],
281-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
275+
"Peer discovery: removing unknown node ~ts from the cluster", [Node]),
282276
_ = rabbit_db_cluster:forget_member(Node, false),
283277
?LOG_WARNING(
284-
"Peer discovery: removing all quorum queue replicas on node ~ts", [Node],
285-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
278+
"Peer discovery: removing all quorum queue replicas on node ~ts", [Node]),
286279
_ = rabbit_quorum_queue:shrink_all(Node),
287280
maybe_remove_nodes(Nodes, false).
288281

@@ -310,13 +303,11 @@ service_discovery_nodes() ->
310303
Nodes = as_list(OneOrMultipleNodes),
311304
?LOG_DEBUG(
312305
"Peer discovery cleanup: ~tp returned ~tp",
313-
[Module, Nodes],
314-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
306+
[Module, Nodes]),
315307
Nodes;
316308
{error, Reason} ->
317309
?LOG_DEBUG(
318310
"Peer discovery cleanup: ~tp returned error ~tp",
319-
[Module, Reason],
320-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
311+
[Module, Reason]),
321312
[]
322313
end.

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_config.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ get(Key, Mapping, Config) ->
2828
?LOG_ERROR(
2929
"Key ~ts is not found in peer discovery config mapping ~tp!",
3030
[Key, Mapping],
31-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
31+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
3232
throw({badkey, Key});
3333
true ->
3434
get_with_entry_meta(Key, maps:get(Key, Mapping), Config)
@@ -44,7 +44,7 @@ get_integer(Key, Mapping, Config) ->
4444
?LOG_ERROR(
4545
"Key ~ts is not found in peer discovery config mapping ~tp!",
4646
[Key, Mapping],
47-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
47+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
4848
throw({badkey, Key});
4949
true ->
5050
get_integer_with_entry_meta(Key, maps:get(Key, Mapping), Config)

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_httpc.erl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ get(Scheme, Host, Port, Path, Args) ->
141141
%%
142142
get(Scheme, Host, Port, Path, Args, Headers, HttpOpts) ->
143143
URL = build_uri(Scheme, Host, Port, Path, Args),
144-
?LOG_DEBUG("GET ~ts", [URL], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
144+
?LOG_DEBUG("GET ~ts", [URL], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
145145
HttpOpts1 = ensure_timeout(HttpOpts),
146146
Response = httpc:request(get, {URL, Headers}, HttpOpts1, []),
147-
?LOG_DEBUG("Response: ~tp", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
147+
?LOG_DEBUG("Response: ~tp", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
148148
parse_response(Response).
149149

150150

@@ -179,10 +179,10 @@ post(Scheme, Host, Port, Path, Args, Body) ->
179179
%%
180180
post(Scheme, Host, Port, Path, Args, Headers, HttpOpts, Body) ->
181181
URL = build_uri(Scheme, Host, Port, Path, Args),
182-
?LOG_DEBUG("POST ~ts [~tp]", [URL, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
182+
?LOG_DEBUG("POST ~ts [~tp]", [URL, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
183183
HttpOpts1 = ensure_timeout(HttpOpts),
184184
Response = httpc:request(post, {URL, Headers, ?CONTENT_JSON, Body}, HttpOpts1, []),
185-
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
185+
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
186186
parse_response(Response).
187187

188188

@@ -208,10 +208,10 @@ post(Scheme, Host, Port, Path, Args, Headers, HttpOpts, Body) ->
208208
Body :: string() | binary() | tuple().
209209
put(Scheme, Host, Port, Path, Args, Body) ->
210210
URL = build_uri(Scheme, Host, Port, Path, Args),
211-
?LOG_DEBUG("PUT ~ts [~tp]", [URL, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
211+
?LOG_DEBUG("PUT ~ts [~tp]", [URL, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
212212
HttpOpts = ensure_timeout(),
213213
Response = httpc:request(put, {URL, [], ?CONTENT_URLENCODED, Body}, HttpOpts, []),
214-
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
214+
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
215215
parse_response(Response).
216216

217217

@@ -262,10 +262,10 @@ put(Scheme, Host, Port, Path, Args, Headers, Body) ->
262262
Body :: string() | binary() | tuple().
263263
put(Scheme, Host, Port, Path, Args, Headers, HttpOpts, Body) ->
264264
URL = build_uri(Scheme, Host, Port, Path, Args),
265-
?LOG_DEBUG("PUT ~ts [~tp] [~tp]", [URL, Headers, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
265+
?LOG_DEBUG("PUT ~ts [~tp] [~tp]", [URL, Headers, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
266266
HttpOpts1 = ensure_timeout(HttpOpts),
267267
Response = httpc:request(put, {URL, Headers, ?CONTENT_URLENCODED, Body}, HttpOpts1, []),
268-
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
268+
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
269269
parse_response(Response).
270270

271271
%% @public
@@ -304,10 +304,10 @@ delete(Scheme, Host, Port, PathSegments, Args, HttpOpts, Body) when is_list(Path
304304
delete(Scheme, Host, Port, Path, Args, HttpOpts, Body);
305305
delete(Scheme, Host, Port, Path, Args, HttpOpts, Body) ->
306306
URL = build_uri(Scheme, Host, Port, Path, Args),
307-
?LOG_DEBUG("DELETE ~ts [~tp]", [URL, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
307+
?LOG_DEBUG("DELETE ~ts [~tp]", [URL, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
308308
HttpOpts1 = ensure_timeout(HttpOpts),
309309
Response = httpc:request(delete, {URL, [], ?CONTENT_URLENCODED, Body}, HttpOpts1, []),
310-
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
310+
?LOG_DEBUG("Response: [~tp]", [Response], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
311311
parse_response(Response).
312312

313313

@@ -323,7 +323,7 @@ maybe_configure_proxy() ->
323323
0 ->
324324
?LOG_DEBUG(
325325
"HTTP client proxy is not configured",
326-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
326+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
327327
ok;
328328
_ ->
329329
HttpProxy = ?CONFIG_MODULE:get(http_proxy, ?CONFIG_MAPPING, Map),
@@ -332,7 +332,7 @@ maybe_configure_proxy() ->
332332
?LOG_DEBUG(
333333
"Configured HTTP proxy: ~tp, HTTPS proxy: ~tp, exclusions: ~tp",
334334
[HttpProxy, HttpsProxy, ProxyExclusions],
335-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
335+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
336336
_ = maybe_set_proxy(proxy, HttpProxy, ProxyExclusions),
337337
_ = maybe_set_proxy(https_proxy, HttpsProxy, ProxyExclusions),
338338
ok
@@ -368,7 +368,7 @@ maybe_set_proxy(Option, ProxyUrl, ProxyExclusions) ->
368368
?LOG_DEBUG(
369369
"Configuring HTTP client's ~ts setting: ~tp, exclusions: ~tp",
370370
[Option, {Host, Port}, ProxyExclusions],
371-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
371+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
372372
httpc:set_option(Option, {{Host, Port}, ProxyExclusions})
373373
end.
374374

@@ -415,7 +415,7 @@ decode_body(?CONTENT_JSON, Body) ->
415415
"HTTP client could not decode a JSON payload "
416416
"(JSON parser returned an error): ~tp.",
417417
[Err],
418-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
418+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
419419
[]
420420
end.
421421

@@ -428,15 +428,15 @@ decode_body(?CONTENT_JSON, Body) ->
428428
-spec parse_response({ok, integer(), string()} | {error, any()}) -> {ok, term()} | {error, any()}.
429429

430430
parse_response({error, Reason}) ->
431-
?LOG_DEBUG("HTTP error ~tp", [Reason], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
431+
?LOG_DEBUG("HTTP error ~tp", [Reason], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
432432
{error, lists:flatten(io_lib:format("~tp", [Reason]))};
433433
parse_response({ok, {{_,200,_}, Headers, Body}}) ->
434434
{ok, decode_body(proplists:get_value("content-type", Headers, ?CONTENT_JSON), Body)};
435435
parse_response({ok,{{_,201,_}, Headers, Body}}) ->
436436
{ok, decode_body(proplists:get_value("content-type", Headers, ?CONTENT_JSON), Body)};
437437
parse_response({ok,{{_,204,_}, _, _}}) -> {ok, []};
438438
parse_response({ok,{{_Vsn,Code,_Reason},_,Body}}) ->
439-
?LOG_DEBUG("HTTP Response (~tp) ~ts", [Code, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
439+
?LOG_DEBUG("HTTP Response (~tp) ~ts", [Code, Body], #{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
440440
{error, integer_to_list(Code)}.
441441

442442
%% @private

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_util.erl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ as_atom(Value) ->
9595
?LOG_ERROR(
9696
"Unexpected data type for atom value: ~tp",
9797
[Value],
98-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
98+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
9999
Value.
100100

101101

@@ -116,7 +116,7 @@ as_integer(Value) ->
116116
?LOG_ERROR(
117117
"Unexpected data type for integer value: ~tp",
118118
[Value],
119-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
119+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
120120
Value.
121121

122122

@@ -140,7 +140,7 @@ as_string(Value) ->
140140
?LOG_ERROR(
141141
"Unexpected data type for list value: ~tp",
142142
[Value],
143-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
143+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
144144
Value.
145145

146146

@@ -321,14 +321,14 @@ as_proplist(List) when is_list(List) ->
321321
?LOG_ERROR(
322322
"Unexpected data type for proplist value: ~tp. JSON parser returned an error: ~tp!",
323323
[Value, Error],
324-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
324+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
325325
[]
326326
end;
327327
as_proplist(Value) ->
328328
?LOG_ERROR(
329329
"Unexpected data type for proplist value: ~tp.",
330330
[Value],
331-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
331+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
332332
[].
333333

334334
%%--------------------------------------------------------------------
@@ -352,7 +352,7 @@ as_map(List) when is_list(List) ->
352352
?LOG_ERROR(
353353
"Unexpected data type for map value: ~tp. JSON parser returned an error: ~tp!",
354354
[Value, Error],
355-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
355+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
356356
[]
357357
end;
358358
as_map(Map) when is_map(Map) ->
@@ -361,7 +361,7 @@ as_map(Value) ->
361361
?LOG_ERROR(
362362
"Unexpected data type for map value: ~tp.",
363363
[Value],
364-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
364+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
365365
[].
366366

367367
-spec stringify_error({ok, term()} | {error, term()}) -> {ok, term()} | {error, string()}.
@@ -387,15 +387,15 @@ maybe_backend_configured(BackendConfigKey,
387387
?LOG_DEBUG(
388388
"Peer discovery: translated cluster formation configuration: ~tp",
389389
[ClusterFormation],
390-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
390+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
391391
case proplists:get_value(BackendConfigKey, ClusterFormation) of
392392
undefined ->
393393
BackendUndefinedFun();
394394
Proplist ->
395395
?LOG_DEBUG(
396396
"Peer discovery: cluster formation backend configuration: ~tp",
397397
[Proplist],
398-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
398+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
399399
ConfiguredFun(Proplist)
400400
end
401401
end.
@@ -428,5 +428,5 @@ as_list(Value) ->
428428
?LOG_ERROR(
429429
"Unexpected data type for list value: ~tp",
430430
[Value],
431-
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
431+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
432432
Value.

0 commit comments

Comments
 (0)