diff --git a/agent.ex b/agent.ex new file mode 100644 index 000000000..e5c972ecf --- /dev/null +++ b/agent.ex @@ -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 diff --git a/agent.json b/agent.json deleted file mode 100644 index f3082f8b4..000000000 --- a/agent.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "version": "f81fe90", - "triples": { - "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" - } - } -} diff --git a/lib/appsignal/config.ex b/lib/appsignal/config.ex index 78d8b3836..06465648b 100644 --- a/lib/appsignal/config.ex +++ b/lib/appsignal/config.ex @@ -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 diff --git a/lib/mix/tasks/appsignal.diagnose.ex b/lib/mix/tasks/appsignal.diagnose.ex index 85f0fe7f4..a4634b714 100644 --- a/lib/mix/tasks/appsignal.diagnose.ex +++ b/lib/mix/tasks/appsignal.diagnose.ex @@ -16,6 +16,7 @@ defmodule Mix.Tasks.Appsignal.Diagnose do host_information() empty_line() + load_agent_config() start_appsignal_in_diagnose_mode() configuration() @@ -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 @@ -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) diff --git a/mix.exs b/mix.exs index 371f3d710..0575f9ddb 100644 --- a/mix.exs +++ b/mix.exs @@ -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) @@ -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]}, diff --git a/mix_helpers.exs b/mix_helpers.exs index 22a7a281f..57ece675c 100644 --- a/mix_helpers.exs +++ b/mix_helpers.exs @@ -18,10 +18,8 @@ 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()) @@ -29,12 +27,12 @@ defmodule Mix.Appsignal.Helper 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: """ diff --git a/test/appsignal/error_handler/error_extracter_test.exs b/test/appsignal/error_handler/error_extracter_test.exs index a005deadc..e147eb68a 100644 --- a/test/appsignal/error_handler/error_extracter_test.exs +++ b/test/appsignal/error_handler/error_extracter_test.exs @@ -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]}]}}} diff --git a/test/mix/tasks/appsignal_diagnose_test.exs b/test/mix/tasks/appsignal_diagnose_test.exs index c1eca55f6..f6a2af73c 100644 --- a/test/mix/tasks/appsignal_diagnose_test.exs +++ b/test/mix/tasks/appsignal_diagnose_test.exs @@ -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 @@ -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