diff --git a/apps/block_scout_web/test/block_scout_web/controllers/metrics_contoller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/metrics_contoller_test.exs new file mode 100644 index 0000000000..e9ea7e7e55 --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/controllers/metrics_contoller_test.exs @@ -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 diff --git a/apps/indexer/lib/indexer/application.ex b/apps/indexer/lib/indexer/application.ex index 78d05b37b0..cb7b9a99f8 100644 --- a/apps/indexer/lib/indexer/application.ex +++ b/apps/indexer/lib/indexer/application.ex @@ -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 -> %{} diff --git a/apps/indexer/lib/indexer/prometheus/collector/filecoin_pending_address_operations_collector.ex b/apps/indexer/lib/indexer/prometheus/collector/filecoin_pending_address_operations_collector.ex index 2078412575..207990ca45 100644 --- a/apps/indexer/lib/indexer/prometheus/collector/filecoin_pending_address_operations_collector.ex +++ b/apps/indexer/lib/indexer/prometheus/collector/filecoin_pending_address_operations_collector.ex @@ -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