diff options
author | kballou <kballou@devnulllabs.io> | 2016-03-25 15:52:55 -0600 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2016-03-25 16:27:34 -0600 |
commit | 09977eccf07d6c75c0fcf933c02c009b0afa8541 (patch) | |
tree | 2e292f97f8d12fab17e9e66fb06cdf3dc2d99f77 | |
parent | 43e753753f01bd741c605e442ec34b81af7b33c5 (diff) | |
download | ex_prometheus_io-09977eccf07d6c75c0fcf933c02c009b0afa8541.tar.gz ex_prometheus_io-09977eccf07d6c75c0fcf933c02c009b0afa8541.tar.xz |
Refactor `Query` to use a pluggable http library
* Refactor `lib/ex_prometheus_io/query.ex` use a pluggable client module
* Add stub environment configs, setup `test.exs` to use a test support
module
-rw-r--r-- | config/config.exs | 2 | ||||
-rw-r--r-- | config/dev.exs | 1 | ||||
-rw-r--r-- | config/prod.exs | 1 | ||||
-rw-r--r-- | config/test.exs | 3 | ||||
-rw-r--r-- | lib/ex_prometheus_io/query.ex | 3 |
5 files changed, 9 insertions, 1 deletions
diff --git a/config/config.exs b/config/config.exs index eecc967..f3049ea 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,3 +1,5 @@ use Mix.Config config :ex_prometheus_io, hostname: "prometheus:9090" + +import_config "#{Mix.env}.exs" diff --git a/config/dev.exs b/config/dev.exs new file mode 100644 index 0000000..d2d855e --- /dev/null +++ b/config/dev.exs @@ -0,0 +1 @@ +use Mix.Config diff --git a/config/prod.exs b/config/prod.exs new file mode 100644 index 0000000..d2d855e --- /dev/null +++ b/config/prod.exs @@ -0,0 +1 @@ +use Mix.Config diff --git a/config/test.exs b/config/test.exs new file mode 100644 index 0000000..b43419c --- /dev/null +++ b/config/test.exs @@ -0,0 +1,3 @@ +use Mix.Config + +config :ex_prometheus_io, http_client: ExPrometheusIo.Test.HTTPClient diff --git a/lib/ex_prometheus_io/query.ex b/lib/ex_prometheus_io/query.ex index 20b01a9..0c346b5 100644 --- a/lib/ex_prometheus_io/query.ex +++ b/lib/ex_prometheus_io/query.ex @@ -7,8 +7,9 @@ defmodule ExPrometheusIo.Query do |> send_results(query_ref, owner) end + @http Application.get_env(:ex_prometheus_io, :http_client) || :httpc defp fetch_json(uri) do - {:ok, {_, _, body}} = :httpc.request(uri |> String.to_char_list()) + {:ok, {_, _, body}} = @http.request(uri |> String.to_char_list()) body end |