Commit 99661c47 authored by davecromberge's avatar davecromberge Committed by Heinz N. Gies

Add endpoint for listing metrics by prefix (#21)

* Add endpoints for listing metrics by prefix

* Upgrade dependencies

* Restore dqe dependency to git version
parent 32557ec9
......@@ -43,6 +43,9 @@ start(_StartType, _StartArgs) ->
%% List all metrics in a collection
{"/collections/:collection/metrics/",
dalmatiner_metric_h, []},
%% List metrics in a collection by prefix
{"/collections/:collection/metrics/:prefix",
dalmatiner_metric_h, []},
%% List all namespaces per metric
{"/collections/:collection/metrics/"
":metric/namespaces/",
......
......@@ -8,7 +8,6 @@
init(_Transport, Req, []) ->
{ok, Req, undefined}.
-dialyzer({no_opaque, handle/2}).
handle(Req, State) ->
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req),
......@@ -24,11 +23,38 @@ handle(Req, State) ->
{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)
{Depth, Req3} = cowboy_req:qs_val(<<"depth">>, Req2),
{Prefix, Req4} = cowboy_req:binding(prefix, Req3),
list_metrics(ContentType, Collection, Prefix, Depth, Req4, State)
end.
terminate(_Reason, _Req, _State) ->
ok.
list_metrics(ContentType, Collection, undefined, undefined, Req, State) ->
{ok, Ms} = dqe_idx:metrics(Collection),
list_metrics(ContentType, Ms, Req, State);
list_metrics(ContentType, Collection, Prefix64, DepthBin, Req, State) ->
Prefix = decode_prefix(Prefix64),
Depth = decode_depth(DepthBin),
{ok, Ms} = dqe_idx:metrics(Collection, Prefix, Depth),
Ms1 = [Prefix ++ M || M <- Ms],
list_metrics(ContentType, Ms1, Req, State).
list_metrics(ContentType, Metrics, Req, State) ->
Ms = [[{key, base64:encode(dproto:metric_from_list(M))},
{parts, M}] || M <- Metrics],
dalmatiner_idx_handler:send(ContentType, Ms, Req, State).
decode_depth(undefined) ->
1;
decode_depth(Depth) when is_binary(Depth) ->
list_to_integer(binary_to_list(Depth)).
decode_prefix(undefined) ->
[];
decode_prefix(<<>>) ->
[];
decode_prefix(Prefix64) when is_binary(Prefix64) ->
PrefixBin = base64:decode(Prefix64),
dproto:metric_to_list(PrefixBin).
......@@ -35,5 +35,6 @@ terminate(_Reason, _Req, _State) ->
namespaces(Collection, undefined) ->
dqe_idx:namespaces(Collection);
namespaces(Collection, Metric64) ->
Metric = base64:decode(Metric64),
MetricBin = base64:decode(Metric64),
Metric = dproto:metric_to_list(MetricBin),
dqe_idx:namespaces(Collection, Metric).
......@@ -36,5 +36,6 @@ terminate(_Reason, _Req, _State) ->
tags(Collection, undefined, Namespace) ->
dqe_idx:tags(Collection, Namespace);
tags(Collection, Metric64, Namespace) ->
Metric = base64:decode(Metric64),
MetricBin = base64:decode(Metric64),
Metric = dproto:metric_to_list(MetricBin),
dqe_idx:tags(Collection, Metric, Namespace).
......@@ -38,5 +38,6 @@ terminate(_Reason, _Req, _State) ->
values(Collection, undefined, Namespace, Tag) ->
dqe_idx:values(Collection, Namespace, Tag);
values(Collection, Metric64, Namespace, Tag) ->
Metric = base64:decode(Metric64),
MetricBin = base64:decode(Metric64),
Metric = dproto:metric_to_list(MetricBin),
dqe_idx:values(Collection, Metric, Namespace, Tag).
[{<<"cf">>,{pkg,<<"cf">>,<<"0.2.1">>},3},
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"1.0.4">>},0},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},1},
{<<"ddb_client">>,{pkg,<<"ddb_client">>,<<"0.1.32">>},2},
{<<"ddb_connection">>,{pkg,<<"ddb_connection">>,<<"0.1.13">>},1},
{<<"ddb_client">>,{pkg,<<"ddb_client">>,<<"0.1.33">>},2},
{<<"ddb_connection">>,{pkg,<<"ddb_connection">>,<<"0.1.14">>},1},
{<<"dflow">>,{pkg,<<"dflow">>,<<"0.1.5">>},1},
{<<"dproto">>,{pkg,<<"dproto">>,<<"0.1.25">>},1},
{<<"dqe">>,
{git,"https://github.com/dalmatinerdb/dqe.git",
{ref,"ce43ba1b777162b4839191b4508f6fab8d4825c0"}},
{ref,"e80851f8fb80fe8f89922d4db6b5aaf47b09bd51"}},
0},
{<<"dqe_fun">>,{pkg,<<"dqe_fun">>,<<"0.1.11">>},1},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.1.18">>},1},
{<<"dqe_idx_ddb">>,{pkg,<<"dqe_idx_ddb">>,<<"0.1.14">>},1},
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.2.12">>},1},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.2.1">>},1},
{<<"dqe_idx_ddb">>,{pkg,<<"dqe_idx_ddb">>,<<"0.2.0">>},1},
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.3.1">>},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},
{<<"fifo_utils">>,{pkg,<<"fifo_utils">>,<<"0.1.24">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.8">>},1},
{<<"hdr_histogram">>,{pkg,<<"hdr_histogram">>,<<"0.2.0">>},1},
{<<"jsone">>,{pkg,<<"jsone">>,<<"1.2.6">>},0},
{<<"jsxd">>,{pkg,<<"jsxd">>,<<"0.2.2">>},2},
{<<"jsxd">>,{pkg,<<"jsxd">>,<<"0.2.3">>},2},
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.1">>},0},
{<<"mmath">>,{pkg,<<"mmath">>,<<"0.2.9">>},1},
{<<"msgpack">>,{pkg,<<"msgpack">>,<<"0.3.5">>},0},
......@@ -32,4 +32,4 @@
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.2.1">>},0},
{<<"recon">>,{pkg,<<"recon">>,<<"2.3.2">>},0},
{<<"snappy">>,{pkg,<<"snappy">>,<<"1.1.1">>},2},
{<<"uuid">>,{pkg,<<"uuid_erl">>,<<"1.5.1">>},1}].
{<<"uuid">>,{pkg,<<"uuid_erl">>,<<"1.5.3">>},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