Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion deps/rabbitmq_tracing/src/rabbit_tracing_wm_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-module(rabbit_tracing_wm_file).

-export([init/2, resource_exists/2, serve/2, content_types_provided/2,
is_authorized/2, allowed_methods/2, delete_resource/2]).
charsets_provided/2, is_authorized/2, allowed_methods/2, delete_resource/2]).
-export([serve/1]).

-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").
Expand All @@ -20,6 +20,9 @@ init(Req, _State) ->
content_types_provided(ReqData, Context) ->
{[{<<"text/plain">>, serve}], ReqData, Context}.

charsets_provided(ReqData, Context) ->
{[<<"utf-8">>], ReqData, Context}.

allowed_methods(ReqData, Context) ->
{[<<"HEAD">>, <<"GET">>, <<"DELETE">>], ReqData, Context}.

Expand Down
49 changes: 45 additions & 4 deletions deps/rabbitmq_tracing/test/rabbit_tracing_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ groups() ->
[
{non_parallel_tests, [], [
tracing_test,
tracing_validation_test
tracing_validation_test,
trace_file_content_type_test
]}
].

Expand Down Expand Up @@ -92,9 +93,10 @@ tracing_test(Config) ->
#amqp_msg{props = #'P_basic'{},
payload = <<"Hello world">>}),

rabbit_ct_client_helpers:close_channel(Ch),

timer:sleep(100),
rabbit_ct_helpers:await_condition(fun() ->
TraceFiles = http_get(Config, "/trace-files/"),
lists:any(fun(#{name := Name}) -> Name =:= <<"test.log">> end, TraceFiles)
end),

http_delete(Config, "/traces/%2f/test", ?NO_CONTENT),
[] = http_get(Config, "/traces/%2f/"),
Expand Down Expand Up @@ -128,6 +130,36 @@ tracing_validation_test(Config) ->
http_delete(Config, Path, ?NO_CONTENT),
ok.

trace_file_content_type_test(Config) ->
case filelib:is_dir(?LOG_DIR) of
true -> {ok, Files} = file:list_dir(?LOG_DIR),
[ok = file:delete(?LOG_DIR ++ F) || F <- Files];
_ -> ok
end,

Args = #{format => <<"text">>,
pattern => <<"#">>},
http_put(Config, "/traces/%2f/test-charset", Args, ?CREATED),

Ch = rabbit_ct_client_helpers:open_channel(Config),
amqp_channel:cast(Ch, #'basic.publish'{ exchange = <<"amq.topic">>,
routing_key = <<"key">> },
#amqp_msg{props = #'P_basic'{},
payload = <<"Test message">>}),

rabbit_ct_helpers:await_condition(fun() ->
TraceFiles = http_get(Config, "/trace-files/"),
lists:any(fun(#{name := Name}) -> Name =:= <<"test-charset.log">> end, TraceFiles)
end),

http_delete(Config, "/traces/%2f/test-charset", ?NO_CONTENT),
Headers = http_get_headers(Config, "/trace-files/test-charset.log"),
ContentType = proplists:get_value("content-type", Headers),
?assertEqual(match, re:run(ContentType, "text/plain", [{capture, none}])),
?assertEqual(match, re:run(ContentType, "charset=utf-8", [{capture, none}])),
http_delete(Config, "/trace-files/test-charset.log", ?NO_CONTENT),
ok.

%%---------------------------------------------------------------------------
%% TODO: Below is copied from rabbit_mgmt_test_http,
%% should be moved to use rabbit_mgmt_test_util once rabbitmq_management
Expand All @@ -154,6 +186,15 @@ http_get_raw(Config, Path, User, Pass, CodeExp) ->
assert_code(CodeExp, CodeAct, "GET", Path, ResBody),
ResBody.

http_get_headers(Config, Path) ->
http_get_headers(Config, Path, "guest", "guest", ?OK).

http_get_headers(Config, Path, User, Pass, CodeExp) ->
{ok, {{_HTTP, CodeAct, _}, Headers, ResBody}} =
req(Config, get, Path, [auth_header(User, Pass)]),
assert_code(CodeExp, CodeAct, "GET", Path, ResBody),
Headers.

http_put(Config, Path, List, CodeExp) ->
http_put_raw(Config, Path, format_for_upload(List), CodeExp).

Expand Down
Loading