Setup appsignal
This commit is contained in:
parent
5ca8de5dbe
commit
79257f1cbe
|
@ -15,7 +15,8 @@ config :backend, BackendWeb.Endpoint,
|
||||||
url: [host: "localhost"],
|
url: [host: "localhost"],
|
||||||
secret_key_base: "XL4NKGBN9lZMrQbMEI1KJOlwAt8S7younVJl90TdAgzmwyapr3g7BRYSNYvX0sZ9",
|
secret_key_base: "XL4NKGBN9lZMrQbMEI1KJOlwAt8S7younVJl90TdAgzmwyapr3g7BRYSNYvX0sZ9",
|
||||||
render_errors: [view: BackendWeb.ErrorView, accepts: ~w(json)],
|
render_errors: [view: BackendWeb.ErrorView, accepts: ~w(json)],
|
||||||
pubsub: [name: Backend.PubSub, adapter: Phoenix.PubSub.PG2]
|
pubsub: [name: Backend.PubSub, adapter: Phoenix.PubSub.PG2],
|
||||||
|
instrumenters: [Appsignal.Phoenix.Instrumenter]
|
||||||
|
|
||||||
config :backend, Backend.Repo, queue_target: 5000
|
config :backend, Backend.Repo, queue_target: 5000
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ config :backend, Backend.Repo,
|
||||||
config :backend, Backend.Elasticsearch.Cluster,
|
config :backend, Backend.Elasticsearch.Cluster,
|
||||||
url: System.get_env("ELASTICSEARCH_URL") || "http://localhost:9200"
|
url: System.get_env("ELASTICSEARCH_URL") || "http://localhost:9200"
|
||||||
|
|
||||||
|
config :appsignal, :config, revision: System.get_env("GIT_REV")
|
||||||
|
|
||||||
port = String.to_integer(System.get_env("PORT") || "4000")
|
port = String.to_integer(System.get_env("PORT") || "4000")
|
||||||
|
|
||||||
config :backend, BackendWeb.Endpoint,
|
config :backend, BackendWeb.Endpoint,
|
||||||
|
|
|
@ -7,6 +7,13 @@ defmodule Backend.Application do
|
||||||
import Backend.Util
|
import Backend.Util
|
||||||
|
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
|
:telemetry.attach(
|
||||||
|
"appsignal-ecto",
|
||||||
|
[:backend, :repo, :query],
|
||||||
|
&Appsignal.Ecto.handle_event/4,
|
||||||
|
nil
|
||||||
|
)
|
||||||
|
|
||||||
crawl_worker_count = get_config(:crawl_workers)
|
crawl_worker_count = get_config(:crawl_workers)
|
||||||
|
|
||||||
children = [
|
children = [
|
||||||
|
@ -16,11 +23,15 @@ defmodule Backend.Application do
|
||||||
BackendWeb.Endpoint,
|
BackendWeb.Endpoint,
|
||||||
# Crawler children
|
# Crawler children
|
||||||
:hackney_pool.child_spec(:crawler, timeout: 15000, max_connections: crawl_worker_count),
|
:hackney_pool.child_spec(:crawler, timeout: 15000, max_connections: crawl_worker_count),
|
||||||
{Task,
|
Supervisor.child_spec(
|
||||||
fn ->
|
{Task,
|
||||||
Honeydew.start_queue(:crawl_queue, failure_mode: Honeydew.FailureMode.Abandon)
|
fn ->
|
||||||
Honeydew.start_workers(:crawl_queue, Backend.Crawler, num: crawl_worker_count)
|
Honeydew.start_queue(:crawl_queue, failure_mode: Honeydew.FailureMode.Abandon)
|
||||||
end},
|
Honeydew.start_workers(:crawl_queue, Backend.Crawler, num: crawl_worker_count)
|
||||||
|
end},
|
||||||
|
id: :start_honeydew
|
||||||
|
),
|
||||||
|
Supervisor.child_spec({Task, fn -> HTTPoison.start() end}, id: :start_httpoison),
|
||||||
Backend.Scheduler,
|
Backend.Scheduler,
|
||||||
Backend.Elasticsearch.Cluster
|
Backend.Elasticsearch.Cluster
|
||||||
]
|
]
|
||||||
|
@ -31,6 +42,8 @@ defmodule Backend.Application do
|
||||||
false -> children ++ [Backend.Crawler.StaleInstanceManager]
|
false -> children ++ [Backend.Crawler.StaleInstanceManager]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_appsignal_probes()
|
||||||
|
|
||||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||||
# for other strategies and supported options
|
# for other strategies and supported options
|
||||||
opts = [strategy: :one_for_one, name: Backend.Supervisor]
|
opts = [strategy: :one_for_one, name: Backend.Supervisor]
|
||||||
|
@ -43,4 +56,22 @@ defmodule Backend.Application do
|
||||||
BackendWeb.Endpoint.config_change(changed, removed)
|
BackendWeb.Endpoint.config_change(changed, removed)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp add_appsignal_probes do
|
||||||
|
Appsignal.Probes.register(:crawler, fn ->
|
||||||
|
%{
|
||||||
|
queue: %{
|
||||||
|
count: count,
|
||||||
|
in_progress: in_progress,
|
||||||
|
mnesia: mnesia
|
||||||
|
}
|
||||||
|
} = Honeydew.status(:crawl_queue)
|
||||||
|
|
||||||
|
memory = mnesia |> Map.get(:"honeydew_:crawl_queue") |> Keyword.get(:memory)
|
||||||
|
|
||||||
|
Appsignal.set_gauge("queue_length", count)
|
||||||
|
Appsignal.set_gauge("in_progress", in_progress)
|
||||||
|
Appsignal.set_gauge("mnesia_memory", memory)
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ defmodule Backend.Crawler do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
import Backend.Util
|
import Backend.Util
|
||||||
require Logger
|
require Logger
|
||||||
|
use Appsignal.Instrumentation.Decorators
|
||||||
|
|
||||||
defstruct [
|
defstruct [
|
||||||
# the instance domain (a string)
|
# the instance domain (a string)
|
||||||
|
@ -31,9 +32,9 @@ defmodule Backend.Crawler do
|
||||||
error: String.t() | nil
|
error: String.t() | nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@decorate transaction()
|
||||||
def run(domain) do
|
def run(domain) do
|
||||||
Logger.info("Crawling #{domain}...")
|
Logger.debug("Starting crawl of #{domain}")
|
||||||
HTTPoison.start()
|
|
||||||
|
|
||||||
state = %Crawler{
|
state = %Crawler{
|
||||||
domain: domain,
|
domain: domain,
|
||||||
|
@ -59,11 +60,13 @@ defmodule Backend.Crawler do
|
||||||
|
|
||||||
# Recursive function to check whether `domain` has an API that the head of the api_crawlers list can read.
|
# Recursive function to check whether `domain` has an API that the head of the api_crawlers list can read.
|
||||||
# If so, crawls it. If not, continues with the tail of the api_crawlers list.
|
# If so, crawls it. If not, continues with the tail of the api_crawlers list.
|
||||||
|
@decorate transaction_event()
|
||||||
defp crawl(%Crawler{api_crawlers: [], domain: domain} = state) do
|
defp crawl(%Crawler{api_crawlers: [], domain: domain} = state) do
|
||||||
Logger.debug("Found no compatible API for #{domain}")
|
Logger.debug("Found no compatible API for #{domain}")
|
||||||
Map.put(state, :found_api?, false)
|
Map.put(state, :found_api?, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@decorate transaction_event()
|
||||||
defp crawl(%Crawler{domain: domain, api_crawlers: [curr | remaining_crawlers]} = state) do
|
defp crawl(%Crawler{domain: domain, api_crawlers: [curr | remaining_crawlers]} = state) do
|
||||||
if curr.is_instance_type?(domain) do
|
if curr.is_instance_type?(domain) do
|
||||||
Logger.debug("Found #{curr} instance")
|
Logger.debug("Found #{curr} instance")
|
||||||
|
@ -94,6 +97,7 @@ defmodule Backend.Crawler do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save the state (after crawling) to the database.
|
# Save the state (after crawling) to the database.
|
||||||
|
@decorate transaction_event()
|
||||||
defp save(%Crawler{
|
defp save(%Crawler{
|
||||||
domain: domain,
|
domain: domain,
|
||||||
result: result,
|
result: result,
|
||||||
|
@ -210,6 +214,7 @@ defmodule Backend.Crawler do
|
||||||
|> Repo.insert_all(interactions)
|
|> Repo.insert_all(interactions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@decorate transaction_event()
|
||||||
defp save(%{domain: domain, error: error, allows_crawling?: allows_crawling}) do
|
defp save(%{domain: domain, error: error, allows_crawling?: allows_crawling}) do
|
||||||
error =
|
error =
|
||||||
cond do
|
cond do
|
||||||
|
|
|
@ -16,6 +16,8 @@ defmodule Backend.Crawler.StaleInstanceManager do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def init(_opts) do
|
def init(_opts) do
|
||||||
|
Logger.info("Starting crawler manager...")
|
||||||
|
|
||||||
instance_count =
|
instance_count =
|
||||||
Instance
|
Instance
|
||||||
|> where([i], not is_nil(i.version))
|
|> where([i], not is_nil(i.version))
|
||||||
|
|
|
@ -16,7 +16,11 @@ defmodule Backend.Release do
|
||||||
end
|
end
|
||||||
|
|
||||||
def index do
|
def index do
|
||||||
|
# TODO: this isn't the right way to handle this.
|
||||||
|
# See https://github.com/danielberkompas/elasticsearch-elixir/issues/76
|
||||||
|
Application.ensure_all_started(@app)
|
||||||
Index.hot_swap(Cluster, "instances")
|
Index.hot_swap(Cluster, "instances")
|
||||||
|
:init.stop()
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback(repo, version) do
|
def rollback(repo, version) do
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule BackendWeb.Endpoint do
|
defmodule BackendWeb.Endpoint do
|
||||||
use Phoenix.Endpoint, otp_app: :backend
|
use Phoenix.Endpoint, otp_app: :backend
|
||||||
|
use Appsignal.Phoenix
|
||||||
|
|
||||||
socket("/socket", BackendWeb.UserSocket,
|
socket("/socket", BackendWeb.UserSocket,
|
||||||
websocket: true,
|
websocket: true,
|
||||||
|
|
|
@ -20,7 +20,7 @@ defmodule Backend.MixProject do
|
||||||
def application do
|
def application do
|
||||||
[
|
[
|
||||||
mod: {Backend.Application, []},
|
mod: {Backend.Application, []},
|
||||||
extra_applications: [:logger, :runtime_tools, :mnesia, :gollum, :ex_twilio]
|
extra_applications: [:logger, :runtime_tools, :mnesia, :gollum, :ex_twilio, :appsignal]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,7 +53,8 @@ defmodule Backend.MixProject do
|
||||||
{:idna, "~> 5.1.2", override: true},
|
{:idna, "~> 5.1.2", override: true},
|
||||||
{:swoosh, "~> 0.23.3"},
|
{:swoosh, "~> 0.23.3"},
|
||||||
{:ex_twilio, "~> 0.7.0"},
|
{:ex_twilio, "~> 0.7.0"},
|
||||||
{:elasticsearch, "~> 1.0"}
|
{:elasticsearch, "~> 1.0"},
|
||||||
|
{:appsignal, "~> 1.10.1"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
%{
|
%{
|
||||||
|
"appsignal": {:hex, :appsignal, "1.10.11", "5df2546d6ea15e392a4384b175ebc1bb33f4ccf8fe9872c11542d3ae2043ff88", [:make, :mix], [{:decorator, "~> 1.2.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.2.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, ">= 1.1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"artificery": {:hex, :artificery, "0.4.2", "3ded6e29e13113af52811c72f414d1e88f711410cac1b619ab3a2666bbd7efd4", [:mix], [], "hexpm"},
|
"artificery": {:hex, :artificery, "0.4.2", "3ded6e29e13113af52811c72f414d1e88f711410cac1b619ab3a2666bbd7efd4", [:mix], [], "hexpm"},
|
||||||
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
|
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
|
||||||
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
|
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
@ -10,6 +11,7 @@
|
||||||
"crontab": {:hex, :crontab, "1.1.7", "b9219f0bdc8678b94143655a8f229716c5810c0636a4489f98c0956137e53985", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
|
"crontab": {:hex, :crontab, "1.1.7", "b9219f0bdc8678b94143655a8f229716c5810c0636a4489f98c0956137e53985", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"db_connection": {:hex, :db_connection, "2.1.0", "122e2f62c4906bf2e49554f1e64db5030c19229aa40935f33088e7d543aa79d0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
|
"db_connection": {:hex, :db_connection, "2.1.0", "122e2f62c4906bf2e49554f1e64db5030c19229aa40935f33088e7d543aa79d0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
|
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
|
||||||
|
"decorator": {:hex, :decorator, "1.2.4", "31dfff6143d37f0b68d0bffb3b9f18ace14fea54d4f1b5e4f86ead6f00d9ff6e", [:mix], [], "hexpm"},
|
||||||
"distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
|
"distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"ecto": {:hex, :ecto, "3.1.7", "fa21d06ef56cdc2fdaa62574e8c3ba34a2751d44ea34c30bc65f0728421043e5", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
"ecto": {:hex, :ecto, "3.1.7", "fa21d06ef56cdc2fdaa62574e8c3ba34a2751d44ea34c30bc65f0728421043e5", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ecto_sql": {:hex, :ecto_sql, "3.1.6", "1e80e30d16138a729c717f73dcb938590bcdb3a4502f3012414d0cbb261045d8", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0 or ~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
"ecto_sql": {:hex, :ecto_sql, "3.1.6", "1e80e30d16138a729c717f73dcb938590bcdb3a4502f3012414d0cbb261045d8", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0 or ~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
|
Loading…
Reference in a new issue