Skip to content

Commit

Permalink
Use agent.ex instead of agent.json, drop Poison dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkreeftmeijer committed Feb 14, 2017
1 parent ccb0788 commit d677a59
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 43 deletions.
28 changes: 28 additions & 0 deletions agent.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Appsignal.Agent do
def version, do: "f81fe90"

def triples do
%{
"x86_64-linux" => %{
checksum: "5336a1fe0e59e542095463698f5acd2038ecd9899544284f68bc8a312c66a1ef",
download_url: "https://appsignal-agent-releases.global.ssl.fastly.net/f81fe90/appsignal-x86_64-linux-all-static.tar.gz"
},
"i686-linux" => %{
checksum: "84b72b1dd43e8e58af11658d13b57508a8975bf347f0625d56bd7e69ed7ad382",
download_url: "https://appsignal-agent-releases.global.ssl.fastly.net/f81fe90/appsignal-i686-linux-all-static.tar.gz"
},
"x86-linux" => %{
checksum: "84b72b1dd43e8e58af11658d13b57508a8975bf347f0625d56bd7e69ed7ad382",
download_url: "https://appsignal-agent-releases.global.ssl.fastly.net/f81fe90/appsignal-i686-linux-all-static.tar.gz"
},
"x86_64-darwin" => %{
checksum: "2a7179ab79ad28af88bed8db37cbd52b3a8065393f476ae9b5e3d7b027020b72",
download_url: "https://appsignal-agent-releases.global.ssl.fastly.net/f81fe90/appsignal-x86_64-darwin-all-static.tar.gz"
},
"universal-darwin" => %{
checksum: "2a7179ab79ad28af88bed8db37cbd52b3a8065393f476ae9b5e3d7b027020b72",
download_url: "https://appsignal-agent-releases.global.ssl.fastly.net/f81fe90/appsignal-x86_64-darwin-all-static.tar.gz"
}
}
end
end
25 changes: 0 additions & 25 deletions agent.json

This file was deleted.

4 changes: 1 addition & 3 deletions lib/appsignal/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ defmodule Appsignal.Config do
defp true?(true), do: true
defp true?(_), do: false


@agent_version Poison.decode!(File.read!("agent.json"))["version"]
@agent_version Appsignal.Agent.version
@language_integration_version Mix.Project.config[:version]


defp write_to_environment(config) do
System.put_env("APPSIGNAL_ACTIVE", Atom.to_string(config[:active]))
System.put_env("APPSIGNAL_APP_PATH", List.to_string(:code.priv_dir(:appsignal))) # FIXME - app_path should not be necessary
Expand Down
10 changes: 8 additions & 2 deletions lib/mix/tasks/appsignal.diagnose.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Mix.Tasks.Appsignal.Diagnose do
host_information()
empty_line()

load_agent_config()
start_appsignal_in_diagnose_mode()

configuration()
Expand All @@ -42,8 +43,7 @@ defmodule Mix.Tasks.Appsignal.Diagnose do
IO.puts " Language: Elixir"
IO.puts " Package version: #{Appsignal.Mixfile.project[:version]}"

agent_info = Poison.decode!(File.read!(Path.expand("../../../agent.json", __DIR__)))
IO.puts " Agent version: #{agent_info["version"]}"
IO.puts " Agent version: #{Appsignal.Agent.version}"
IO.puts " Nif loaded: #{yes_or_no(Appsignal.Nif.loaded?)}"
end

Expand All @@ -59,6 +59,12 @@ defmodule Mix.Tasks.Appsignal.Diagnose do
end
end

defp load_agent_config do
unless Code.ensure_loaded?(Appsignal.Agent) do
{_, _} = Code.eval_file("agent.ex")
end
end

defp start_appsignal_in_diagnose_mode do
System.put_env "APPSIGNAL_DIAGNOSE", "true"
{:ok, _} = Application.ensure_all_started(:appsignal)
Expand Down
6 changes: 5 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ defmodule Mix.Tasks.Compile.Appsignal do

def run(_args) do
{_, _} = Code.eval_file("mix_helpers.exs")

unless Code.ensure_loaded?(Appsignal.Agent) do
{_, _} = Code.eval_file("agent.ex")
end

case Mix.Appsignal.Helper.verify_system_architecture() do
{:ok, arch} ->
:ok = Mix.Appsignal.Helper.ensure_downloaded(arch)
Expand Down Expand Up @@ -71,7 +76,6 @@ defmodule Appsignal.Mixfile do

defp deps do
[
{:poison, "~> 2.1"},
{:httpoison, "~> 0.10.0"},
{:decorator, "~> 1.0"},
{:phoenix, "~> 1.2.0", optional: true, only: [:prod, :test_phoenix]},
Expand Down
10 changes: 4 additions & 6 deletions mix_helpers.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ defmodule Mix.Appsignal.Helper do
end

def ensure_downloaded(arch) do

info = Poison.decode!(File.read!("agent.json"))
arch_config = info["triples"][arch]
version = info["version"]
arch_config = Appsignal.Agent.triples[arch]
version = Appsignal.Agent.version

System.put_env("LIB_DIR", priv_dir())

unless has_file("appsignal-agent") and has_file("appsignal.h") and has_file("appsignal_extension.so") do

File.mkdir_p!(priv_dir())
try do
download_and_extract(arch_config["download_url"], version, arch_config["checksum"])
download_and_extract(arch_config[:download_url], version, arch_config[:checksum])
catch
{:checksum_mismatch, filename, _, _} ->
File.rm!(filename)
try do
download_and_extract(arch_config["download_url"], version, arch_config["checksum"])
download_and_extract(arch_config[:download_url], version, arch_config[:checksum])
catch
{:checksum_mismatch, filename, calculated, expected} ->
raise Mix.Error, message: """
Expand Down
8 changes: 4 additions & 4 deletions test/appsignal/error_handler/error_extracter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ defmodule Appsignal.ErrorHandler.ErrorExtracterTest do
assert "Badarg error" == m
end

@undefined_error_extract %Protocol.UndefinedError{description: "", protocol: Enumerable, value: {:error, {%Poison.SyntaxError{message: "Unexpected token: <\", token: \"<"}, [{Poison.Parser, :parse!, 2, [file: 'lib/poison/parser.ex', line: 56]}, {Poison, :decode!, 2, [file: 'lib/poison.ex', line: 83]}, {HTTPoison.Base, :response, 6, [file: 'lib/httpoison/base.ex', line: 413]}, {WebApp.Backend, :request!, 5, [file: 'web/support/backend.ex', line: 3]}, {WebApp.Backend, :get, 2, [file: 'web/support/backend.ex', line: 161]}, {WebApp.Backend, :search_deals_uncached, 1, [file: 'web/support/backend.ex', line: 105]}, {:depcache, :memo, 5, [file: '/home/user/ap/deps/depcache/src/depcache.erl', line: 100]}, {WebApp.AppChannel, :handle_in, 3, [file: 'web/channels/app_channel.ex', line: 41]}]}}}
@undefined_error_extract %Protocol.UndefinedError{description: "", protocol: Enumerable, value: {:error, {%RuntimeError{}, []}}}

test "Protocol.UndefinedError extract" do
{r, m} = ErrorHandler.extract_reason_and_message(@undefined_error_extract, "JSON error")
assert "Poison.SyntaxError" == r
assert "JSON error: Unexpected token: <\", token: \"<" == m
{r, m} = ErrorHandler.extract_reason_and_message(@undefined_error_extract, "Exception")
assert "RuntimeError" == r
assert "Exception: runtime error" == m
end

@undefined_error %Protocol.UndefinedError{description: "", protocol: Enumerable, value: {:error, {%Protocol.UndefinedError{description: "", protocol: Enumerable, value: {:error, :foo}}, [{Enumerable, :impl_for!, 1, [file: 'lib/enum.ex', line: 1]}, {Enumerable, :reduce, 3, [file: 'lib/enum.ex', line: 116]}, {Enum, :reduce, 3, [file: 'lib/enum.ex', line: 1636]}, {Enum, :sort, 2, [file: 'lib/enum.ex', line: 1969]}, {:depcache, :memo, 5, [file: '/home/user/ap/deps/depcache/src/depcache.erl', line: 100]}, {WebApp.AppChannel, :collect_places_map, 1, [file: 'web/channels/app_channel.ex', line: 148]}, {WebApp.AppChannel, :handle_in, 3, [file: 'web/channels/app_channel.ex', line: 58]}, {Phoenix.Channel.Server, :"-handle_info/2-fun-4-", 4, [file: 'lib/phoenix/channel/server.ex', line: 226]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 615]}, {:gen_server, :handle_msg, 5, [file: 'gen_server.erl', line: 681]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}}
Expand Down
7 changes: 5 additions & 2 deletions test/mix/tasks/appsignal_diagnose_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ defmodule Mix.Tasks.Appsignal.DiagnoseTest do
Plug.Conn.resp(conn, 200, "")
end

unless Code.ensure_loaded?(Appsignal.Agent) do
{_, _} = Code.eval_file("agent.ex")
end

on_exit :reset_config, fn ->
Application.put_env(:appsignal, :config, original_config)
end
Expand All @@ -42,8 +46,7 @@ defmodule Mix.Tasks.Appsignal.DiagnoseTest do
assert String.contains? output, "Language: Elixir"
assert String.contains? output, "Package version: #{Appsignal.Mixfile.project[:version]}"

agent_info = Poison.decode!(File.read!("agent.json"))
agent_version = agent_info["version"]
agent_version = Appsignal.Agent.version
assert agent_version
assert String.contains? output, "Agent version: #{agent_version}"
end
Expand Down

0 comments on commit d677a59

Please sign in to comment.