Instrument all queries with NewRelic

pull/2/head
Doc Ritezel 7 years ago
parent bc5fb6ea45
commit 90f14052db
  1. 3
      config/config.exs
  2. 3
      config/prod.exs
  3. 2
      lib/explorer/address.ex
  4. 2
      lib/explorer/fetcher.ex
  5. 8
      lib/explorer/repo.ex
  6. 34
      lib/explorer/skipped_blocks.ex
  7. 4
      lib/explorer_web/controllers/address_controller.ex
  8. 8
      lib/explorer_web/controllers/block_controller.ex
  9. 8
      lib/explorer_web/controllers/chain_controller.ex
  10. 10
      lib/explorer_web/controllers/transaction_controller.ex
  11. 7
      mix.exs
  12. 10
      mix.lock

@ -31,6 +31,9 @@ config :ethereumex,
host: "localhost",
port: 8545
config :new_relixir,
active: false
config :ex_cldr,
default_locale: "en",
locales: ["en"],

@ -38,7 +38,8 @@ config :explorer, Explorer.Repo,
# Configure New Relic
config :new_relixir,
application_name: System.get_env("NEW_RELIC_APP_NAME"),
license_key: System.get_env("NEW_RELIC_LICENSE_KEY")
license_key: System.get_env("NEW_RELIC_LICENSE_KEY"),
active: true
# Configure Web3
config :ethereumex,

@ -4,7 +4,7 @@ defmodule Explorer.Address do
use Ecto.Schema
import Ecto.Changeset
alias Explorer.Address
alias Explorer.Repo
alias Explorer.Repo.NewRelic, as: Repo
@timestamps_opts [type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}]

@ -3,7 +3,7 @@ defmodule Explorer.Fetcher do
alias Explorer.Address
alias Explorer.Block
alias Explorer.FromAddress
alias Explorer.Repo
alias Explorer.Repo.NewRelic, as: Repo
alias Explorer.ToAddress
alias Explorer.Transaction

@ -10,4 +10,12 @@ defmodule Explorer.Repo do
def init(_, opts) do
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
end
defmodule NewRelic do
use NewRelixir.Plug.Repo, repo: Explorer.Repo
def paginate(queryable, opts \\ []) do
Explorer.Repo.paginate(queryable, opts)
end
end
end

@ -1,30 +1,26 @@
defmodule Explorer.SkippedBlocks do
@moduledoc """
Fill in older blocks that were skipped during processing.
"""
import Ecto.Query, only: [from: 2, limit: 2]
alias Explorer.Block
alias Explorer.Repo
alias Ecto.Adapters.SQL
import Ecto.Query, only: [limit: 2]
alias Explorer.Repo.NewRelic, as: Repo
@moduledoc false
@query """
SELECT missing_numbers.number AS missing_number
FROM generate_series($1, 0, -1) missing_numbers(number)
LEFT OUTER JOIN blocks ON (blocks.number = missing_numbers.number)
WHERE blocks.id IS NULL
LIMIT $2;
"""
@missing "SELECT generate_series(?, 0, -1) AS missing_number"
def first, do: first(1)
def first(count) do
SQL.query!(Repo, @query, [latest_block_number(), count]).rows
|> Enum.map(&List.first/1)
|> Enum.map(&Integer.to_string/1)
|> Enum.shuffle
blocks = from b in Block,
right_join: missing_number in fragment(@missing, ^latest_block_number()),
on: b.number == fragment("missing_number"),
limit: ^count,
where: is_nil(b.id),
select: fragment("missing_number")
Repo.all(blocks) |> Enum.map(&Integer.to_string/1)
end
def latest_block_number do
(Block |> Block.latest |> limit(1) |> Repo.one || Block.null)
|> Map.fetch!(:number)
block = Repo.one(Block |> Block.latest |> limit(1)) || Block.null
block.number
end
end

@ -1,9 +1,11 @@
defmodule ExplorerWeb.AddressController do
use ExplorerWeb, :controller
import Ecto.Query
alias Explorer.Address
alias Explorer.Repo
alias Explorer.AddressForm
alias Explorer.Repo.NewRelic, as: Repo
def show(conn, params) do
address = Address

@ -1,11 +1,11 @@
defmodule ExplorerWeb.BlockController do
alias Explorer.Block
alias Explorer.BlockForm
alias Explorer.Repo
use ExplorerWeb, :controller
import Ecto.Query
use ExplorerWeb, :controller
alias Explorer.Block
alias Explorer.BlockForm
alias Explorer.Repo.NewRelic, as: Repo
def index(conn, params) do
blocks = from b in Block,

@ -1,11 +1,11 @@
defmodule ExplorerWeb.ChainController do
alias Explorer.Block
alias Explorer.Transaction
alias Explorer.Repo
use ExplorerWeb, :controller
import Ecto.Query
use ExplorerWeb, :controller
alias Explorer.Block
alias Explorer.Repo.NewRelic, as: Repo
alias Explorer.Transaction
def show(conn, _params) do
blocks = from b in Block,

@ -1,12 +1,12 @@
defmodule ExplorerWeb.TransactionController do
alias Explorer.Block
alias Explorer.Repo
alias Explorer.Transaction
alias Explorer.TransactionForm
use ExplorerWeb, :controller
import Ecto.Query
use ExplorerWeb, :controller
alias Explorer.Block
alias Explorer.Repo.NewRelic, as: Repo
alias Explorer.Transaction
alias Explorer.TransactionForm
def index(conn, params) do
transactions = from t in Transaction,

@ -35,12 +35,13 @@ defmodule Explorer.Mixfile do
defp elixirc_paths, do: ["lib"]
# Specifies extra applications to start per environment
defp extra_applications(:prod), do: [:phoenix_pubsub_redis, :new_relixir, :exq, :exq_ui | extra_applications()]
defp extra_applications(:prod), do: [:phoenix_pubsub_redis, :exq, :exq_ui | extra_applications()]
defp extra_applications(:dev), do: [:exq, :exq_ui | extra_applications()]
defp extra_applications(_), do: extra_applications()
defp extra_applications, do: [
:scrivener_ecto, :scrivener_html, :ex_cldr, :ex_jasmine, :ethereumex,
:timex, :timex_ecto, :crontab, :set_locale, :logger, :runtime_tools
:timex, :timex_ecto, :crontab, :set_locale, :logger, :runtime_tools,
:new_relixir
]
# Specifies your project dependencies.
@ -64,7 +65,7 @@ defmodule Explorer.Mixfile do
{:junit_formatter, ">= 0.0.0", only: [:test], runtime: false},
{:math, "~> 0.3.0"},
{:mock, "~> 0.3.0", only: [:test], runtime: false},
{:new_relixir, "~> 0.4.0", only: [:prod]},
{:new_relixir, "~> 0.4"},
{:phoenix, "~> 1.3.0"},
{:phoenix_ecto, "~> 3.2"},
{:phoenix_html, "~> 2.10"},

@ -1,4 +1,5 @@
%{"abnf2": {:hex, :abnf2, "0.1.2", "6f8792b8ac3288dba5fc889c2bceae9fe78f74e1a7b36bea9726ffaa9d7bef95", [:mix], [], "hexpm"},
%{
"abnf2": {:hex, :abnf2, "0.1.2", "6f8792b8ac3288dba5fc889c2bceae9fe78f74e1a7b36bea9726ffaa9d7bef95", [:mix], [], "hexpm"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm"},
@ -36,7 +37,7 @@
"mime": {:hex, :mime, "1.2.0", "78adaa84832b3680de06f88f0997e3ead3b451a440d183d688085be2d709b534", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"new_relixir": {:hex, :new_relixir, "0.4.0", "32e15de5dc21bd9823040d3d7fe62cd931755a06de2163e02b79a703179ea102", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:hackney, "~> 1.10", [hex: :hackney, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
"new_relixir": {:hex, :new_relixir, "0.4.1", "55907ef2b968cf9c9278c58e43d1d68f756d21101fa552639c566c5536280915", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:hackney, "~> 1.10", [hex: :hackney, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix": {:hex, :phoenix, "1.3.0", "1c01124caa1b4a7af46f2050ff11b267baa3edb441b45dbf243e979cd4c5891b", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_ecto": {:hex, :phoenix_ecto, "3.3.0", "702f6e164512853d29f9d20763493f2b3bcfcb44f118af2bc37bb95d0801b480", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_html": {:hex, :phoenix_html, "2.10.5", "4f9df6b0fb7422a9440a73182a566cb9cbe0e3ffe8884ef9337ccf284fc1ef0a", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
@ -46,7 +47,7 @@
"plug": {:hex, :plug, "1.4.4", "279b547662272cd835a8ca089717201dd3be51bb4705354eaf1b0346744acc82", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.13.3", "c277cfb2a9c5034d445a722494c13359e361d344ef6f25d604c2353185682bfc", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"postgrex": {:hex, :postgrex, "0.13.4", "f58e319c5451bfda86ba6a45ce6dca311193d0a9861323d0d16e8d02e25adc41", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"quantum": {:hex, :quantum, "2.2.1", "a8f2ef38b68121833651617ed0c01b348582542dee11730d553acdc57a7d0f7c", [:mix], [{:calendar, "~> 0.17", [hex: :calendar, repo: "hexpm", optional: true]}, {:crontab, "~> 1.1", [hex: :crontab, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.12.2", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:timex, "~> 3.1.13", [hex: :timex, repo: "hexpm", optional: true]}], "hexpm"},
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
"react_phoenix": {:hex, :react_phoenix, "0.5.1", "962e1e46ce0ad6e0c9f007ee5f602a6c3758c3a808ce990134b6ed155d60b46d", [:mix], [{:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
@ -63,4 +64,5 @@
"tzdata": {:hex, :tzdata, "0.5.16", "13424d3afc76c68ff607f2df966c0ab4f3258859bbe3c979c9ed1606135e7352", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
"wallaby": {:hex, :wallaby, "0.19.2", "358bbff251e3555e02566280d1795132da792969dd58ff89963536d013058719", [:mix], [{:httpoison, "~> 0.12", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm"}}
"wallaby": {:hex, :wallaby, "0.19.2", "358bbff251e3555e02566280d1795132da792969dd58ff89963536d013058719", [:mix], [{:httpoison, "~> 0.12", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm"},
}

Loading…
Cancel
Save