diff options
author | kballou <kballou@devnulllabs.io> | 2016-03-22 15:54:49 -0600 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2016-03-22 16:40:21 -0600 |
commit | cf50bcf5adacca9fdb204eec346e5994ca08ad4b (patch) | |
tree | 40f212b3c5d4ee033576d1a9077cbf2b40a73932 /lib | |
parent | 7c902cfadff18e93d181d3b4c0e91b68316104f4 (diff) | |
download | ex_prometheus_io-cf50bcf5adacca9fdb204eec346e5994ca08ad4b.tar.gz ex_prometheus_io-cf50bcf5adacca9fdb204eec346e5994ca08ad4b.tar.xz |
Refactor: internally pass tuples
This removes the need for 3 different method heads for `process/4`, the
internal query functions will handle building a correct url for processing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ex_prometheus_io.ex | 6 | ||||
-rw-r--r-- | lib/ex_prometheus_io/query.ex | 26 |
2 files changed, 9 insertions, 23 deletions
diff --git a/lib/ex_prometheus_io.ex b/lib/ex_prometheus_io.ex index 43604ea..9eb7c1c 100644 --- a/lib/ex_prometheus_io.ex +++ b/lib/ex_prometheus_io.ex @@ -11,17 +11,17 @@ defmodule ExPrometheusIo do end def range(query, start_ts, end_ts, step, _opts \\ []) do - query_opts = [query, start_ts, end_ts, step] + query_opts = {query, start_ts, end_ts, step} spawn_query(:range, query_opts) end def series(matches, _opts \\ []) when is_list(matches) do - spawn_query(:series, [matches]) + spawn_query(:series, {matches}) end defp spawn_query(query, query_opts, _opts \\ []) do query_ref = make_ref() - query_opts = [query | query_opts] ++ [query_ref, self()] + query_opts = [query, query_opts, query_ref, self()] {:ok, pid} = Task.Supervisor.start_child( ExPrometheusIo.QuerySupervisor, ExPrometheusIo.Query, diff --git a/lib/ex_prometheus_io/query.ex b/lib/ex_prometheus_io/query.ex index 140d0a9..20b01a9 100644 --- a/lib/ex_prometheus_io/query.ex +++ b/lib/ex_prometheus_io/query.ex @@ -1,24 +1,10 @@ defmodule ExPrometheusIo.Query do - def process(:query, query, query_ref, owner) do - build_url(:query, query) - |> fetch_json() - |> Poison.decode - |> send_results(query_ref, owner) - end - - def process(:range, query, start_ts, end_ts, step, query_ref, owner) do - build_url(:range, {query, start_ts, end_ts, step}) - |> fetch_json() - |> Poison.decode - |> send_results(query_ref, owner) - end - - def process(:series, matches, query_ref, owner) do - build_url(:series, matches) - |> fetch_json() - |> Poison.decode - |> send_results(query_ref, owner) + def process(query, query_opts, query_ref, owner) do + build_url(query, query_opts) + |> fetch_json() + |> Poison.decode + |> send_results(query_ref, owner) end defp fetch_json(uri) do @@ -48,7 +34,7 @@ defmodule ExPrometheusIo.Query do <> "&step=#{step}" end - def query_params(:series, matches) when is_list(matches) do + def query_params(:series, {matches}) when is_list(matches) do matches |> Enum.map(fn(match) -> "match[]=#{match}" end) |> Enum.join("&") |