fix: Repair /metrics endpoint (#10813)

* fix: Repair /metrics endpoint

* Return back change in the application.ex
np-fix-forever-pending-verification
Victor Baranov 2 months ago committed by GitHub
parent 5e4b8d856d
commit e897070d84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      apps/block_scout_web/test/block_scout_web/controllers/metrics_contoller_test.exs
  2. 21
      apps/indexer/lib/indexer/application.ex
  3. 44
      apps/indexer/lib/indexer/prometheus/collector/filecoin_pending_address_operations_collector.ex

@ -0,0 +1,11 @@
defmodule BlockScoutWeb.MetricsControllerTest do
use BlockScoutWeb.ConnCase
describe "/metrics page" do
test "renders /metrics page", %{conn: conn} do
conn = get(conn, "/metrics")
assert text_response(conn, 200)
end
end
end

@ -14,29 +14,8 @@ defmodule Indexer.Application do
alias Indexer.Memory
alias Prometheus.Registry
@default_prometheus_collectors [
Indexer.Prometheus.Collector.PendingBlockOperations
]
case Application.compile_env(:explorer, :chain_type) do
:filecoin ->
@chain_type_prometheus_collectors [
Indexer.Prometheus.Collector.FilecoinPendingAddressOperations
]
_ ->
@chain_type_prometheus_collectors []
end
@prometheus_collectors @default_prometheus_collectors ++
@chain_type_prometheus_collectors
@impl Application
def start(_type, _args) do
for collector <- @prometheus_collectors do
Registry.register_collector(collector)
end
memory_monitor_options =
case Application.get_env(:indexer, :memory_limit) do
nil -> %{}

@ -1,29 +1,31 @@
defmodule Indexer.Prometheus.Collector.FilecoinPendingAddressOperations do
@moduledoc """
Custom collector to count number of records in filecoin_pending_address_operations table.
"""
if Application.compile_env(:explorer, :chain_type) == :filecoin do
defmodule Indexer.Prometheus.Collector.FilecoinPendingAddressOperations do
@moduledoc """
Custom collector to count number of records in filecoin_pending_address_operations table.
"""
use Prometheus.Collector
use Prometheus.Collector
alias Explorer.Chain.Filecoin.PendingAddressOperation
alias Explorer.Repo
alias Prometheus.Model
alias Explorer.Chain.Filecoin.PendingAddressOperation
alias Explorer.Repo
alias Prometheus.Model
def collect_mf(_registry, callback) do
callback.(
create_gauge(
:filecoin_pending_address_operations,
"Number of records in filecoin_pending_address_operations table",
Repo.aggregate(PendingAddressOperation, :count, timeout: :infinity)
def collect_mf(_registry, callback) do
callback.(
create_gauge(
:filecoin_pending_address_operations,
"Number of records in filecoin_pending_address_operations table",
Repo.aggregate(PendingAddressOperation, :count, timeout: :infinity)
)
)
)
end
end
def collect_metrics(:filecoin_pending_address_operations, count) do
Model.gauge_metrics([{count}])
end
def collect_metrics(:filecoin_pending_address_operations, count) do
Model.gauge_metrics([{count}])
end
defp create_gauge(name, help, data) do
Model.create_mf(name, help, :gauge, __MODULE__, data)
defp create_gauge(name, help, data) do
Model.create_mf(name, help, :gauge, __MODULE__, data)
end
end
end

Loading…
Cancel
Save