Enhance health API endpoint: better parsing HEALTHY_BLOCKS_PERIOD and use it in the response

pull/5904/head
Viktor Baranov 2 years ago
parent 7569dace3c
commit 532010cda1
  1. 1
      CHANGELOG.md
  2. 11
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/health_controller.ex
  3. 8
      config/runtime.exs

@ -3,6 +3,7 @@
### Features
### Fixes
- [#5904](https://github.com/blockscout/blockscout/pull/5904) - Enhance health API endpoint: better parsing HEALTHY_BLOCKS_PERIOD and use it in the response
- [#5809](https://github.com/blockscout/blockscout/pull/5809) - Fix 404 on `/metadata` page
- [#5786](https://github.com/blockscout/blockscout/pull/5786) - Replace `current_path` with `Controller.current_full_path` in two controllers
- [#5807](https://github.com/blockscout/blockscout/pull/5807) - Update Makefile migrate command due to release build

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.API.V1.HealthController do
alias BlockScoutWeb.API.APILogger
alias Explorer.Chain
alias Timex.Duration
def health(conn, _) do
APILogger.log(conn)
@ -39,12 +40,20 @@ defmodule BlockScoutWeb.API.V1.HealthController do
end
def error({:error, number, timestamp}) do
healthy_blocks_period = Application.get_env(:explorer, :healthy_blocks_period)
healthy_blocks_period_formatted =
healthy_blocks_period
|> Duration.from_milliseconds()
|> Duration.to_minutes()
|> trunc()
%{
"healthy" => false,
"error_code" => 5001,
"error_title" => "blocks fetching is stuck",
"error_description" =>
"There are no new blocks in the DB for the last 5 mins. Check the healthiness of Ethereum archive node or the Blockscout DB instance",
"There are no new blocks in the DB for the last #{healthy_blocks_period_formatted} mins. Check the healthiness of Ethereum archive node or the Blockscout DB instance",
"data" => %{
"latest_block_number" => to_string(number),
"latest_block_inserted_at" => to_string(timestamp)

@ -158,6 +158,12 @@ config :ethereum_jsonrpc, EthereumJSONRPC.Geth, debug_trace_transaction_timeout:
disable_indexer = System.get_env("DISABLE_INDEXER")
disable_webapp = System.get_env("DISABLE_WEBAPP")
healthy_blocks_period =
System.get_env("HEALTHY_BLOCKS_PERIOD", "5")
|> Integer.parse()
|> elem(0)
|> :timer.minutes()
config :explorer,
coin: System.get_env("COIN") || "POA",
coin_name: System.get_env("COIN_NAME") || System.get_env("COIN") || "POA",
@ -166,7 +172,7 @@ config :explorer,
"homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg,istanbul,berlin,london,default",
include_uncles_in_average_block_time:
if(System.get_env("UNCLES_IN_AVERAGE_BLOCK_TIME") == "true", do: true, else: false),
healthy_blocks_period: System.get_env("HEALTHY_BLOCKS_PERIOD") || :timer.minutes(5),
healthy_blocks_period: healthy_blocks_period,
realtime_events_sender:
if(disable_webapp != "true",
do: Explorer.Chain.Events.SimpleSender,

Loading…
Cancel
Save