From fa61649d74d0462c5da70078fc869ccf265be4d1 Mon Sep 17 00:00:00 2001 From: "R.J. Osborne" Date: Tue, 20 Mar 2018 11:54:46 -0400 Subject: [PATCH 1/5] updated dependencies --- README.md | 2 +- mix.exs | 6 +++--- mix.lock | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f7c1e4a..7c61f0c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed ```elixir def deps do - [{:graphitex, "~> 0.1.0"}] + [{:graphitex, "~> 0.3.0"}] end ``` diff --git a/mix.exs b/mix.exs index 457375f..02e9a9c 100644 --- a/mix.exs +++ b/mix.exs @@ -42,9 +42,9 @@ defmodule Graphitex.Mixfile do # Type "mix help deps" for more examples and options defp deps do [ - {:ex_doc, ">= 0.0.0", only: :dev}, - {:credo, only: ~w(test dev)a}, - {:mix_test_watch, "~> 0.2.5", only: ~w(dev test)a}, + {:ex_doc, "~> 0.18.3", only: :dev}, + {:credo, "~> 0.8.10", only: ~w(test dev)a}, + {:mix_test_watch, "~> 0.5.0", only: ~w(dev test)a}, ] end end diff --git a/mix.lock b/mix.lock index 44a5ae1..f83e001 100644 --- a/mix.lock +++ b/mix.lock @@ -1,9 +1,11 @@ -%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, +%{ + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, "connection": {:git, "https://github.com/fishcakez/connection.git", "5b794fda9ec2cd41eae2887011381cfdb2cfb93e", []}, - "credo": {:hex, :credo, "0.7.3", "9827ab04002186af1aec014a811839a06f72aaae6cd5eed3919b248c8767dbf3", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"}, + "credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, + "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"}, - "mix_test_watch": {:hex, :mix_test_watch, "0.2.6", "9fcc2b1b89d1594c4a8300959c19d50da2f0ff13642c8f681692a6e507f92cab", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}} + "mix_test_watch": {:hex, :mix_test_watch, "0.5.0", "2c322d119a4795c3431380fca2bca5afa4dc07324bd3c0b9f6b2efbdd99f5ed3", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"}, + "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, +} From 893313ba4adee80d01c52091f9f79ad08af79ba9 Mon Sep 17 00:00:00 2001 From: "R.J. Osborne" Date: Tue, 20 Mar 2018 13:11:33 -0400 Subject: [PATCH 2/5] Fixed ts method signature problem --- lib/graphitex.ex | 2 +- lib/graphitex/client.ex | 21 +++++++++++++++++---- test/graphitex_test.exs | 12 ++++++++++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/graphitex.ex b/lib/graphitex.ex index 0091738..e9fa95e 100644 --- a/lib/graphitex.ex +++ b/lib/graphitex.ex @@ -21,7 +21,7 @@ defmodule Graphitex do defdelegate metric_batch(msgs), to: Graphitex.Client def now do - :os.system_time(:seconds) + :os.system_time(:seconds) / 1 end end diff --git a/lib/graphitex/client.ex b/lib/graphitex/client.ex index d742985..2d21310 100644 --- a/lib/graphitex/client.ex +++ b/lib/graphitex/client.ex @@ -15,18 +15,31 @@ defmodule Graphitex.Client do @doc """ Add a node and the service it provides to the directory. """ + @spec metric(number, [String.t], Float.t) :: nil + def metric(value, namespace, ts) when is_list(namespace) and is_float(ts) do + metric({value, Enum.join(namespace, "."), ts}) + end + + @spec metric(number, [String.t], number) :: nil + def metric(value, namespace, ts) when is_list(namespace) and is_number(ts) do + metric({value, Enum.join(namespace, "."), Float.round(ts / 1, 1)}) + end + + @spec metric(number, binary|String.t, Float.t) :: nil + def metric(value, namespace, ts) when is_float(ts) do + metric({value, namespace, Float.round(ts, 1)}) + end + @spec metric(number, [String.t]) :: nil def metric(value, namespace) when is_list(namespace) do metric({value, Enum.join(namespace, ".")}) end + @spec metric(number, binary) :: nil def metric(value, namespace) when is_binary(namespace) do metric({value, namespace}) end - @spec metric(number, binary|String.t, Float.t) :: nil - def metric(value, namespace, ts) when is_float(ts) do - metric({value, namespace, Float.round(ts, 1)}) - end + @spec metric({number, binary|String.t, Float.t}) :: nil def metric(measurement) do GenServer.cast(@name, {:metric, pack_msg(measurement)}) diff --git a/test/graphitex_test.exs b/test/graphitex_test.exs index 31207c7..b2d1ef4 100644 --- a/test/graphitex_test.exs +++ b/test/graphitex_test.exs @@ -10,6 +10,14 @@ defmodule GraphitexTest do assert :ok == Graphitex.metric(4, [:aws, :node1, :avg_cpu]) end + test "collect metric atom tags and a Graphitex.now()" do + assert :ok == Graphitex.metric(4, [:aws, :node1, :avg_cpu], Graphitex.now()) + end + + test "collect metric atom tags and an :os.system_time(:seconds)" do + assert :ok == Graphitex.metric(4, [:aws, :node1, :avg_cpu], :os.system_time(:seconds)) + end + test "batch send" do batch = [ {4, "client.transactions.east"}, @@ -21,8 +29,8 @@ defmodule GraphitexTest do test "stream batch" do 1..10 - |> Enum.map(fn n -> - :ok = Graphitex.metric(n, "aws.node1.load") + |> Enum.each(fn (x) -> + :ok = Graphitex.metric(x, "aws.node1.load") end) end end From 75b012d11e5754faee20217a87f5e7adbb730cdf Mon Sep 17 00:00:00 2001 From: "R.J. Osborne" Date: Tue, 20 Mar 2018 13:25:50 -0400 Subject: [PATCH 3/5] updated travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b394f7a..abf3eda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,10 @@ sudo: false language: elixir elixir: - 1.3.1 - - 1.4.0-rc.1 + - 1.6.4 otp_release: - 18.2 - 19.1 + - 20.3 after_script: - MIX_ENV=test From 50d9988bc5393cf079ad6cdebbb2986131c4a6a3 Mon Sep 17 00:00:00 2001 From: "R.J. Osborne" Date: Tue, 20 Mar 2018 13:32:13 -0400 Subject: [PATCH 4/5] Pulled back to the commonly-running and available OTP 19.1 release --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index abf3eda..449b4a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ elixir: - 1.3.1 - 1.6.4 otp_release: - - 18.2 - 19.1 - - 20.3 after_script: - MIX_ENV=test From f00b83d037601194f37bf9b08335cd7ba31f2932 Mon Sep 17 00:00:00 2001 From: "R.J. Osborne" Date: Wed, 25 Apr 2018 18:49:40 -0400 Subject: [PATCH 5/5] Make sure the host is a charlist --- lib/graphitex/client.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/graphitex/client.ex b/lib/graphitex/client.ex index 2d21310..e99b5b3 100644 --- a/lib/graphitex/client.ex +++ b/lib/graphitex/client.ex @@ -80,7 +80,7 @@ defmodule Graphitex.Client do def connect(state) do port = Application.get_env(:graphitex, :port, 2003) - host = Application.get_env(:graphitex, :host) + host = host() opts = [:binary, active: false] Logger.info fn -> "Connecting to carbon at #{host}:#{port}" end {:ok, socket} = :gen_tcp.connect(host, port, opts) @@ -88,6 +88,14 @@ defmodule Graphitex.Client do %{state | socket: socket} end + defp host() do + host = Application.get_env(:graphitex, :host) + case is_binary(host) do + true -> String.to_charlist(host) + false -> host + end + end + def terminate({:error, :closed}, state) do state end