Move block number out of prose and into metadata

Realtime block number will set `Logger.metadata(block_number: ...)` for
each block number is fetches separately after getting the `newHead`
websocket message.
pull/1214/head
Luke Imhoff 6 years ago
parent 9153d0767b
commit 0243726f9b
  1. 2
      apps/block_scout_web/config/config.exs
  2. 2
      apps/ethereum_jsonrpc/config/config.exs
  3. 2
      apps/explorer/config/config.exs
  4. 2
      apps/indexer/config/config.exs
  5. 16
      apps/indexer/lib/indexer/block/realtime/fetcher.ex
  6. 16
      apps/indexer/lib/indexer/logger.ex
  7. 6
      config/config.exs

@ -48,7 +48,7 @@ config :ex_cldr,
config :logger, :block_scout_web, config :logger, :block_scout_web,
# keep synced with `config/config.exs` # keep synced with `config/config.exs`
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
metadata: ~w(application fetcher request_id)a, metadata: ~w(application fetcher request_id block_number)a,
metadata_filter: [application: :block_scout_web] metadata_filter: [application: :block_scout_web]
config :spandex_phoenix, tracer: BlockScoutWeb.Tracer config :spandex_phoenix, tracer: BlockScoutWeb.Tracer

@ -17,7 +17,7 @@ config :ethereum_jsonrpc, EthereumJSONRPC.Tracer,
config :logger, :ethereum_jsonrpc, config :logger, :ethereum_jsonrpc,
# keep synced with `config/config.exs` # keep synced with `config/config.exs`
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
metadata: ~w(application fetcher request_id)a, metadata: ~w(application fetcher request_id block_number)a,
metadata_filter: [application: :ethereum_jsonrpc] metadata_filter: [application: :ethereum_jsonrpc]
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom

@ -50,7 +50,7 @@ config :explorer,
config :logger, :explorer, config :logger, :explorer,
# keep synced with `config/config.exs` # keep synced with `config/config.exs`
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
metadata: ~w(application fetcher request_id)a, metadata: ~w(application fetcher request_id block_number)a,
metadata_filter: [application: :explorer] metadata_filter: [application: :explorer]
config :spandex_ecto, SpandexEcto.EctoLogger, config :spandex_ecto, SpandexEcto.EctoLogger,

@ -19,7 +19,7 @@ config :indexer, Indexer.Tracer,
config :logger, :indexer, config :logger, :indexer,
# keep synced with `config/config.exs` # keep synced with `config/config.exs`
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
metadata: ~w(application fetcher request_id)a, metadata: ~w(application fetcher request_id block_number)a,
metadata_filter: [application: :indexer] metadata_filter: [application: :indexer]
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom

@ -159,8 +159,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
@decorate trace(name: "fetch", resource: "Indexer.Block.Realtime.Fetcher.fetch_and_import_block/3", tracer: Tracer) @decorate trace(name: "fetch", resource: "Indexer.Block.Realtime.Fetcher.fetch_and_import_block/3", tracer: Tracer)
def fetch_and_import_block(block_number_to_fetch, block_fetcher, reorg?, retry \\ 3) do def fetch_and_import_block(block_number_to_fetch, block_fetcher, reorg?, retry \\ 3) do
Logger.metadata(fetcher: :block_realtime) Indexer.Logger.metadata(fn ->
if reorg? do if reorg? do
# give previous fetch attempt (for same block number) a chance to finish # give previous fetch attempt (for same block number) a chance to finish
# before fetching again, to reduce block consensus mistakes # before fetching again, to reduce block consensus mistakes
@ -168,6 +167,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
end end
do_fetch_and_import_block(block_number_to_fetch, block_fetcher, retry) do_fetch_and_import_block(block_number_to_fetch, block_fetcher, retry)
end, fetcher: :block_realtime, block_number: block_number_to_fetch)
end end
@decorate span(tracer: Tracer) @decorate span(tracer: Tracer)
@ -179,16 +179,12 @@ defmodule Indexer.Block.Realtime.Fetcher do
Task.Supervisor.start_child(TaskSupervisor, ConsensusEnsurer, :perform, args) Task.Supervisor.start_child(TaskSupervisor, ConsensusEnsurer, :perform, args)
end end
Logger.debug(fn -> Logger.debug("Fetched and imported.")
["fetched and imported block ", to_string(block_number_to_fetch)]
end)
{:ok, %{inserted: _, errors: [_ | _] = errors}} -> {:ok, %{inserted: _, errors: [_ | _] = errors}} ->
Logger.error(fn -> Logger.error(fn ->
[ [
"failed to fetch block ", "failed to fetch block: ",
to_string(block_number_to_fetch),
": ",
inspect(errors), inspect(errors),
". Block will be retried by catchup indexer." ". Block will be retried by catchup indexer."
] ]
@ -199,8 +195,6 @@ defmodule Indexer.Block.Realtime.Fetcher do
[ [
"failed to fetch ", "failed to fetch ",
to_string(step), to_string(step),
" for block ",
to_string(block_number_to_fetch),
": ", ": ",
inspect(reason), inspect(reason),
". Block will be retried by catchup indexer." ". Block will be retried by catchup indexer."
@ -232,8 +226,6 @@ defmodule Indexer.Block.Realtime.Fetcher do
[ [
"failed to insert ", "failed to insert ",
to_string(step), to_string(step),
" for block ",
to_string(block_number_to_fetch),
": ", ": ",
inspect(failed_value), inspect(failed_value),
". Block will be retried by catchup indexer." ". Block will be retried by catchup indexer."

@ -1,8 +1,22 @@
defmodule Indexer.Logger do defmodule Indexer.Logger do
@moduledoc """ @moduledoc """
Helpers for formatting `Logger` data as `t:iodata/0`. Helpers for `Logger`.
""" """
@doc """
Sets `keyword` in `Logger.metadata/1` around `fun`.
"""
def metadata(fun, keyword) when is_function(fun, 0) and is_list(keyword) do
metadata_before = Logger.metadata()
try do
Logger.metadata(keyword)
fun.()
after
Logger.reset_metadata(metadata_before)
end
end
@doc """ @doc """
The PID and its registered name (if it has one) as `t:iodata/0`. The PID and its registered name (if it has one) as `t:iodata/0`.
""" """

@ -32,19 +32,19 @@ config :logger,
config :logger, :console, config :logger, :console,
# Use same format for all loggers, even though the level should only ever be `:error` for `:error` backend # Use same format for all loggers, even though the level should only ever be `:error` for `:error` backend
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
metadata: ~w(application fetcher request_id)a metadata: ~w(application fetcher request_id block_number)a
config :logger, :ecto, config :logger, :ecto,
# Use same format for all loggers, even though the level should only ever be `:error` for `:error` backend # Use same format for all loggers, even though the level should only ever be `:error` for `:error` backend
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
metadata: ~w(application fetcher request_id)a, metadata: ~w(application fetcher request_id block_number)a,
metadata_filter: [application: :ecto] metadata_filter: [application: :ecto]
config :logger, :error, config :logger, :error,
# Use same format for all loggers, even though the level should only ever be `:error` for `:error` backend # Use same format for all loggers, even though the level should only ever be `:error` for `:error` backend
format: "$dateT$time $metadata[$level] $message\n", format: "$dateT$time $metadata[$level] $message\n",
level: :error, level: :error,
metadata: ~w(application fetcher request_id)a metadata: ~w(application fetcher request_id block_number)a
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.

Loading…
Cancel
Save