Commit 52b192cd authored by Heinz N. Gies's avatar Heinz N. Gies

Add more debug options

parent 0ac16d86
......@@ -21,50 +21,53 @@ handle(Req, State) ->
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State};
{Q, Req1} ->
{Opts, Req2} = case cowboy_req:qs_val(<<"debug">>, Req1) of
{undefined, ReqX} ->
{[{timeout, infinity}], ReqX};
{<<>>, ReqX} ->
{[{timeout, infinity}, debug], ReqX};
{Token, ReqX} ->
{[{timeout, infinity}, debug,
{token, Token}], ReqX}
end,
{Opts, Req2} = build_opts(Req1),
ReqR = Req2,
case timer:tc(dqe, run, [Q, Opts]) of
{_, {error, E}} ->
Error = list_to_binary(dqe:error_string({error, E})),
lager:warning("Error in query [~s]: ~p", [Q, E]),
{ok, Req3} =
cowboy_req:reply(400, [], Error, Req2),
{ok, Req3, State};
{ok, ReqR1} =
cowboy_req:reply(400, [], Error, ReqR),
{ok, ReqR1, State};
{T, {ok, Start, R2}} ->
R3 = [#{name => Name,
resolution => Resolution,
values => mmath_bin:to_list(Data),
metadata => Mdata,
type => <<"metrics">>}
|| #{name := Name,
data := Data,
type := metrics,
metadata := Mdata,
resolution := Resolution} <- R2],
R4 = [#{name => Name,
metadata => Mdata,
values => [#{timestamp => Ts, event => E}
|| {Ts, E} <- Data],
type => <<"events">>}
|| #{name := Name,
metadata := Mdata,
data := Data,
type := events} <- R2],
D = #{start => Start,
query_time => T,
results => R3 ++ R4},
{ContentType, Req3} = content_type(Req2),
send(ContentType, D, Req3, State)
D = encode_reply(Start, T, R2),
{ContentType, ReqR1} = content_type(ReqR),
send(ContentType, D, ReqR1, State)
end
end.
encode_reply(Start, T, R2) ->
R3 = [#{name => Name,
resolution => Resolution,
values => mmath_bin:to_list(Data),
metadata => Mdata,
type => <<"metrics">>}
|| #{name := Name,
data := Data,
type := metrics,
metadata := Mdata,
resolution := Resolution} <- R2],
R4 = [#{name => Name,
metadata => Mdata,
values => [#{timestamp => Ts, event => E}
|| {Ts, E} <- Data],
type => <<"events">>}
|| #{name := Name,
metadata := Mdata,
data := Data,
type := events} <- R2],
D = #{start => Start,
query_time => T,
results => R3 ++ R4},
case R2 of
[#{type := graph,
value := Graph} | _] ->
maps:put(D, graph, Graph);
_ ->
D
end.
content_type(Req) ->
{ok, A, Req1} = cowboy_req:parse_header(<<"accept">>, Req),
{content_type_(A), Req1}.
......@@ -104,3 +107,25 @@ send(_, _D, Req, State) ->
terminate(_Reason, _Req, _State) ->
ok.
build_opts(Req) ->
O0 = case application:get_env(dalmatiner_frontend, log_slow) of
{ok, true} ->
[{timeout, infinity}, log_slow_queries];
_ ->
[{timeout, infinity}]
end,
{O1, R1} = case cowboy_req:qs_val(<<"debug">>, Req) of
{undefined, ReqX} ->
{O0, ReqX};
{<<>>, ReqX} ->
{[debug | O0], ReqX};
{Token, ReqX} ->
{[debug, {token, Token} | O0], ReqX}
end,
case cowboy_req:qs_val(<<"graph">>, R1) of
{undefined, Rx1} ->
{O1, Rx1};
{_, Rx1} ->
{[return_graph | O1], Rx1}
end.
......@@ -8,7 +8,7 @@
{<<"dproto">>,{pkg,<<"dproto">>,<<"0.2.2">>},1},
{<<"dqe">>,
{git,"https://github.com/dalmatinerdb/dqe.git",
{ref,"b29247d5c21718ad0b50f4aa8262aace4724060b"}},
{ref,"ceb5245620fd3206acc3a6611eb3d1dafebcc88f"}},
0},
{<<"dqe_fun">>,{pkg,<<"dqe_fun">>,<<"0.1.11">>},1},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.2.1">>},1},
......@@ -16,7 +16,6 @@
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.3.6">>},1},
{<<"eper">>,{pkg,<<"eper">>,<<"0.94.0">>},0},
{<<"epgsql">>,{pkg,<<"epgsql">>,<<"3.3.0">>},3},
{<<"erlang_localtime">>,{pkg,<<"erlang_localtime">>,<<"1.0.0">>},2},
{<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"1.0.0">>},0},
{<<"fifo_utils">>,{pkg,<<"fifo_utils">>,<<"0.1.30">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
......@@ -28,7 +27,11 @@
{<<"msgpack">>,{pkg,<<"msgpack">>,<<"0.3.5">>},0},
{<<"pgapp">>,{pkg,<<"pgapp">>,<<"0.0.2">>},2},
{<<"poolboy">>,{pkg,<<"poolboy">>,<<"1.5.1">>},2},
{<<"qdate">>,{pkg,<<"qdate">>,<<"0.4.3">>},1},
{<<"qdate">>,
{git,"https://github.com/dalmatinerdb/qdate.git",
{ref,"fcfb8105014b8bef19f50dd89647c0e58dae0903"}},
1},
{<<"qdate_localtime">>,{pkg,<<"qdate_localtime">>,<<"1.1.0">>},2},
{<<"quickrand">>,{pkg,<<"quickrand">>,<<"1.5.4">>},2},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.2.1">>},0},
{<<"recon">>,{pkg,<<"recon">>,<<"2.3.2">>},0},
......@@ -49,7 +52,6 @@
{<<"dqe_idx_pg">>, <<"5B93531BC946E53BED16947ADB01753F54DF6E057AD0B18AD13E603540C9A779">>},
{<<"eper">>, <<"F5FB2DAA0DF8878748E1C598428EDA942A173E5121FF35C1D632129B84593A3A">>},
{<<"epgsql">>, <<"974A578340E52012CBAB820CE756E7ED1DF1BAF0110C59A6753D8337A2CF9454">>},
{<<"erlang_localtime">>, <<"497DFD4D13523D3E0EECDCB8D6D59857CF642A17A6BDC6133FF906FDAF2AEF21">>},
{<<"erlware_commons">>, <<"087467DE5833C0BB5B3CCDD387F9E9C1FB816A75B7A709629BF24B5ED3246C51">>},
{<<"fifo_utils">>, <<"388002C613C627564325ACF739756887DDFC857CB31E1E2451FAD157384903D1">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
......@@ -61,7 +63,7 @@
{<<"msgpack">>, <<"1C46114241011452DEEC8145851745A0BB5B637CEE028D4D4ADB9DC3527AF06A">>},
{<<"pgapp">>, <<"3E104BB777C8455D8B26D1538B67ABE0188EE97B1DF973FD936C2204CB316196">>},
{<<"poolboy">>, <<"6B46163901CFD0A1B43D692657ED9D7E599853B3B21B95AE5AE0A777CF9B6CA8">>},
{<<"qdate">>, <<"6037343CAA1EF8BA8AF13AFD5A2A89CE7695C1E8A12D87702D66624290E3BE76">>},
{<<"qdate_localtime">>, <<"5F6C3ACF10ECC5A7E2EFA3DCD2C863102B962188DBD9E086EC01D29FE029DA29">>},
{<<"quickrand">>, <<"47ADD4755CC5F209CBEFFD6F47C84061196CD7FAD99FD8FD12418EB0D06B939D">>},
{<<"ranch">>, <<"A6FB992C10F2187B46FFD17CE398DDF8A54F691B81768F9EF5F461EA7E28C762">>},
{<<"recon">>, <<"4444C879BE323B1B133EEC5241CB84BD3821EA194C740D75617E106BE4744318">>},
......
......@@ -27,6 +27,7 @@ case $2 in
mkdir -p /data/dalmatinerfe/etc
mkdir -p /data/dalmatinerfe/db
mkdir -p /data/dalmatinerfe/log/sasl
mkdir -p /data/dalmatinerfe/log/query
chown -R $USER:$GROUP /data/dalmatinerfe
if [ -d /tmp/dalmatinerfe ]
then
......
......@@ -15,3 +15,18 @@
[{default, "{{run_user_home}}"},
hidden,
{datatype, string}]}.
%% Directory for query logs to be written to
{mapping, "debug.folder", "dqe.debug_folder",
[{default, "{{platform_log_dir}}/query"},
{datatype, directory}]}.
%% Default time for a query to be considered slow
{mapping, "debug.max_time", "dqe.debug_slow",
[{default, "5s"},
{datatype, {duration, ms}}]}.
%% @doc The path data gets stored into.
{mapping, "debug.log_slow", "dalmatiner_frontend.log_slow",
[{default, "off"},
{datatype, flag}]}.
├─ cowboy─1.0.4
│ └─ cowlib─1.0.2
├─ dalmatiner_frontend─0.3.0
├─ dalmatiner_frontend─0.3.1
├─ dqe─0.4.15
│ ├─ ddb_connection─0.1.20
│ │ ├─ ddb_client─0.2.0
......@@ -17,8 +17,8 @@
│ │ └─ epgsql─3.3.0
│ ├─ hdr_histogram─0.2.0
│ ├─ mmath─0.2.14
│ └─ qdate─0.4.3
│ └─ erlang_localtime─1.0.0
│ └─ qdate─0.4.4
│ └─ qdate_localtime─1.1.0
├─ eper─0.94.0
├─ erlware_commons─1.0.0
│ └─ cf─0.2.2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment