Commit c431d70d authored by Heinz N. Gies's avatar Heinz N. Gies

Add discovery handlers

parent f7b0a0f9
-module(dalmatiner_collection_h).
-export([init/3, handle/2, terminate/3]).
-ignore_xref([init/3, handle/2, terminate/3]).
init(_Transport, Req, []) ->
{ok, Req, undefined}.
-dialyzer({no_opaque, handle/2}).
handle(Req, State) ->
Req0 = cowboy_req:set_resp_header(
<<"access-control-allow-origin">>, <<"*">>, Req),
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req0),
case ContentType of
html ->
F = fun (Socket, Transport) ->
File = code:priv_dir(dalmatiner_frontend) ++
"/static/collection.html",
Transport:sendfile(Socket, File)
end,
Req2 = cowboy_req:set_resp_body_fun(F, Req1),
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State};
_ ->
{ok, Bs} = dqe_idx:collections(),
dalmatiner_idx_handler:send(ContentType, Bs, Req1, State)
end.
terminate(_Reason, _Req, State) ->
{ok, State}.
......@@ -19,6 +19,26 @@ start(_StartType, _StartArgs) ->
{'_', [{"/", dalmatiner_idx_handler, []},
{"/buckets/", dalmatiner_bucket_handler, []},
{"/buckets/[...]", dalmatiner_metric_handler, []},
%% List all collections
{"/collections", dalmatiner_collection_h, []},
%% List all metrics in a collection
{"/collections/:collection/metrics/",
dalmatiner_metric_h, []},
%% List all namespaces
{"/collections/:collection/metrics/"
":metric/namespaces/",
dalmatiner_namespace_h, []},
%% List all tags in a namespace
{"/collections/:collection/metrics/"
":metric/namespaces/:namespace/tags/",
dalmatiner_tag_h, []},
{"/collection/:colleciton/metrics/",
dalmatiner_collection_handler, []},
{"/js/[...]", cowboy_static,
{priv_dir, dalmatiner_frontend, "static/js",
[{mimetypes, cow_mimetypes, web}]}},
......
%% Feel free to use, reuse and abuse the code in this file.
%% @doc POST echo handler.
-module(dalmatiner_metric_handler).
-module(dalmatiner_key_handler).
-export([init/3, handle/2, terminate/3]).
......@@ -21,7 +21,7 @@ handle(Req, State) ->
html ->
F = fun (Socket, Transport) ->
File = code:priv_dir(dalmatiner_frontend) ++
"/static/metric.html",
"/static/key.html",
Transport:sendfile(Socket, File)
end,
Req3 = cowboy_req:set_resp_body_fun(F, Req2),
......
-module(dalmatiner_metric_h).
-export([init/3, handle/2, terminate/3]).
-ignore_xref([init/3, handle/2, terminate/3]).
init(_Transport, Req, []) ->
{ok, Req, undefined}.
-dialyzer({no_opaque, handle/2}).
handle(Req, State) ->
Req0 = cowboy_req:set_resp_header(
<<"access-control-allow-origin">>, <<"*">>, Req),
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req0),
case ContentType of
html ->
F = fun (Socket, Transport) ->
File = code:priv_dir(dalmatiner_frontend) ++
"/static/metric.html",
Transport:sendfile(Socket, File)
end,
Req2 = cowboy_req:set_resp_body_fun(F, Req1),
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State};
_ ->
{Collection, Req2} = cowboy_req:binding(collection, Req1),
{ok, Ms} = dqe_idx:metrics(Collection),
Ms1 = [[{key, base64:encode(M)},
{parts, dproto:metric_to_list(M)}] || M <- Ms],
dalmatiner_idx_handler:send(ContentType, Ms1, Req2, State)
end.
terminate(_Reason, _Req, State) ->
{ok, State}.
-module(dalmatiner_namespace_h).
-export([init/3, handle/2, terminate/3]).
-ignore_xref([init/3, handle/2, terminate/3]).
init(_Transport, Req, []) ->
{ok, Req, undefined}.
-dialyzer({no_opaque, handle/2}).
handle(Req, State) ->
Req0 = cowboy_req:set_resp_header(
<<"access-control-allow-origin">>, <<"*">>, Req),
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req0),
case ContentType of
html ->
F = fun (Socket, Transport) ->
File = code:priv_dir(dalmatiner_frontend) ++
"/static/namespace.html",
Transport:sendfile(Socket, File)
end,
Req2 = cowboy_req:set_resp_body_fun(F, Req1),
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State};
_ ->
{Collection, Req2} = cowboy_req:binding(collection, Req1),
{Metric64, Req3} = cowboy_req:binding(metric, Req2),
Metric = base64:decode(Metric64),
{ok, Ns} = dqe_idx:namespaces(Collection, Metric),
dalmatiner_idx_handler:send(ContentType, Ns, Req3, State)
end.
terminate(_Reason, _Req, State) ->
{ok, State}.
-module(dalmatiner_tag_h).
-export([init/3, handle/2, terminate/3]).
-ignore_xref([init/3, handle/2, terminate/3]).
init(_Transport, Req, []) ->
{ok, Req, undefined}.
-dialyzer({no_opaque, handle/2}).
handle(Req, State) ->
Req0 = cowboy_req:set_resp_header(
<<"access-control-allow-origin">>, <<"*">>, Req),
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req0),
case ContentType of
html ->
F = fun (Socket, Transport) ->
File = code:priv_dir(dalmatiner_frontend) ++
"/static/tag.html",
Transport:sendfile(Socket, File)
end,
Req2 = cowboy_req:set_resp_body_fun(F, Req1),
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State};
_ ->
{Collection, Req2} = cowboy_req:binding(collection, Req1),
{Metric64, Req3} = cowboy_req:binding(metric, Req2),
Metric = base64:decode(Metric64),
{Namespace, Req4} = cowboy_req:binding(namespace, Req3),
{ok, Ts} = dqe_idx:tags(Collection, Metric, Namespace),
dalmatiner_idx_handler:send(ContentType, Ts, Req4, State)
end.
terminate(_Reason, _Req, State) ->
{ok, State}.
......@@ -18,12 +18,6 @@
#{limit => 25,
ignore => []}},
{elvis_style, no_if_expression},
{elvis_style, invalid_dynamic_call,
#{ignore => [%% Meeded for Transport:
dalmatiner_bucket_handler,
dalmatiner_metric_handler,
dalmatiner_idx_handler
]}},
{elvis_style, used_ignored_variable},
{elvis_style, no_behavior_info},
{
......
......@@ -107,12 +107,11 @@
{template, "share/dfe.xml", "share/dfe.xml"},
%% {copy, "_build/prod/lib/fifo_utils/priv/update_config.sh", "share/"},
{template, "schema/dalmatinerfe.schema", "share/schema/00-dalmatiner_frontend.schema"},
{template, "{\{build_dir\}\}/lib/ddb_connection/priv/ddb_connection.schema", "share/schema/01-ddb_connection.schema"},
{template, "{\{build_dir\}\}/lib/dqe/priv/dqe.schema", "share/schema/02-dqe.schema"},
{template, "{\{build_dir\}\}/lib/dqe_idx/priv/dqe_idx.schema", "share/schema/03-dqe_idx.schema"},
{template, "{\{build_dir\}\}/lib/dqe_idx_pg/priv/dqe_idx_pg.schema", "share/schema/04-dqe_idx_pg.schema"},
{template, "\{\{build_dir\}\}/lib/ddb_connection/priv/ddb_connection.schema", "share/schema/01-ddb_connection.schema"},
{template, "\{\{build_dir\}\}/lib/dqe/priv/dqe.schema", "share/schema/02-dqe.schema"},
{template, "\{\{build_dir\}\}/lib/dqe_idx/priv/dqe_idx.schema", "share/schema/03-dqe_idx.schema"},
{template, "\{\{build_dir\}\}/lib/dqe_idx_pg/priv/dqe_idx_pg.schema", "share/schema/04-dqe_idx_pg.schema"},
{template, "schema/erlang_vm.schema", "share/schema/05-vm.schema"},
{template, "schema/lager.schema", "share/schema/06-lager.schema"}
]}]}.
......@@ -7,17 +7,17 @@
{<<"dproto">>,{pkg,<<"dproto">>,<<"0.1.14">>},1},
{<<"dqe">>,
{git,"https://github.com/dalmatinerdb/dqe.git",
{ref,"66a3c6d3d319effea5380c916283b098a658194f"}},
{ref,"9b3e4d41b03443e91d4ce4d97cd003f407476e2f"}},
0},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.1.12">>},1},
{<<"dqe_idx_ddb">>,{pkg,<<"dqe_idx_ddb">>,<<"0.1.9">>},1},
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.1.18">>},1},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.1.14">>},1},
{<<"dqe_idx_ddb">>,{pkg,<<"dqe_idx_ddb">>,<<"0.1.10">>},1},
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.1.25">>},1},
{<<"eper">>,{pkg,<<"eper">>,<<"0.94.0">>},0},
{<<"epgsql">>,{pkg,<<"epgsql">>,<<"3.1.1">>},3},
{<<"erlang_localtime">>,{pkg,<<"erlang_localtime">>,<<"1.0.0">>},2},
{<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"0.20.0">>},2},
{<<"fifo_utils">>,{pkg,<<"fifo_utils">>,<<"0.1.22">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.7">>},1},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.8">>},1},
{<<"hdr_histogram">>,{pkg,<<"hdr_histogram">>,<<"0.2.0">>},1},
{<<"jsone">>,{pkg,<<"jsone">>,<<"1.2.3">>},0},
{<<"lager">>,{pkg,<<"lager">>,<<"2.1.1">>},0},
......
No preview for this file type
......@@ -7,9 +7,9 @@
│ │ └─ poolboy─1.5.1
│ ├─ dflow─0.1.5
│ ├─ dproto─0.1.14
│ ├─ dqe_idx─0.1.12
│ ├─ dqe_idx_ddb─0.1.9
│ ├─ dqe_idx_pg─0.1.18
│ ├─ dqe_idx─0.1.14
│ ├─ dqe_idx_ddb─0.1.10
│ ├─ dqe_idx_pg─0.1.24
│ │ └─ pgapp─0.0.1
│ │ └─ epgsql─3.1.1
│ ├─ hdr_histogram─0.2.0
......@@ -23,7 +23,7 @@
│ └─ quickrand─1.5.1
├─ jsone─1.2.3
├─ lager─2.1.1
│ └─ goldrush─0.1.7
│ └─ goldrush─0.1.8
├─ mmath─0.2.0-alpha3
├─ msgpack─0.3.5
├─ ranch─1.2.1
......
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