Repository: general-CbIC/poolex (elixir)

Issue:
Move `get_debug_info/1` under Poolex.Private namespace
This change is to show more clearly that this function should not be used in production.

Pull request:
Move `get_debug_info` to Private namespace
Closes #140

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 900b6df..6e14540 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Changed
+
+- Function `get_debug_info/1` moved from `Poolex` to `Poolex.Private.DebugInfo` (according to the [issue](https://github.com/general-CbIC/poolex/issues/140)).
+
 ## [1.3.0] - 2025-04-26
 
 ### Added
diff --git a/lib/poolex.ex b/lib/poolex.ex
index 1fd42db..58ae043 100644
--- a/lib/poolex.ex
+++ b/lib/poolex.ex
@@ -215,39 +215,6 @@ defmodule Poolex do
     :sys.get_state(name)
   end
 
-  @doc """
-  Returns detailed information about started pool.
-
-  Primarily needed to help with debugging. **Avoid using this function in production.**
-
-  ## Fields
-
-      * `busy_workers_count` - how many workers are busy right now.
-      * `busy_workers_pids` - list of busy workers.
-      * `failed_to_start_workers_count` - how many workers failed to start.
-      * `idle_workers_count` - how many workers are ready to work.
-      * `idle_workers_pids` - list of idle workers.
-      * `max_overflow` - how many workers can be created over the limit.
-      * `overflow` - current count of workers launched over limit.
-      * `waiting_caller_pids` - list of callers processes.
-      * `worker_args` - what parameters are used to start the worker.
-      * `worker_module` - name of a module that describes a worker.
-      * `worker_start_fun` - what function is used to start the worker.
-
-  ## Examples
-
-      iex> Poolex.start(pool_id: :my_pool_3, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
-      iex> debug_info = %Poolex.Private.DebugInfo{} = Poolex.get_debug_info(:my_pool_3)
-      iex> debug_info.busy_workers_count
-      0
-      iex> debug_info.idle_workers_count
-      5
-  """
-  @spec get_debug_info(pool_id()) :: DebugInfo.t()
-  def get_debug_info(pool_id) do
-    GenServer.call(pool_id, :get_debug_info)
-  end
-
   @doc """
   Adds some idle workers to existing pool.
   """
diff --git a/lib/poolex/private/debug_info.ex b/lib/poolex/private/debug_info.ex
index 4fb6f2c..98da582 100644
--- a/lib/poolex/private/debug_info.ex
+++ b/lib/poolex/private/debug_info.ex
@@ -36,4 +36,37 @@ defmodule Poolex.Private.DebugInfo do
           worker_module: module(),
           worker_start_fun: atom()
         }
+
+  @doc """
+  Returns detailed information about started pool.
+
+  Primarily needed to help with debugging. **Avoid using this function in production.**
+
+  ## Fields
+
+      * `busy_workers_count` - how many workers are busy right now.
+      * `busy_workers_pids` - list of busy workers.
+      * `failed_to_start_workers_count` - how many workers failed to start.
+      * `idle_workers_count` - how many workers are ready to work.
+      * `idle_workers_pids` - list of idle workers.
+      * `max_overflow` - how many workers can be created over the limit.
+      * `overflow` - current count of workers launched over limit.
+      * `waiting_caller_pids` - list of callers processes.
+      * `worker_args` - what parameters are used to start the worker.
+      * `worker_module` - name of a module that describes a worker.
+      * `worker_start_fun` - what function is used to start the worker.
+
+  ## Examples
+
+      iex> Poolex.start(pool_id: :my_pool_3, worker_module: Agent, worker_args: [fn -> 0 end], workers_count: 5)
+      iex> debug_info = %Poolex.Private.DebugInfo{} = Poolex.Private.DebugInfo.get_debug_info(:my_pool_3)
+      iex> debug_info.busy_workers_count
+      0
+      iex> debug_info.idle_workers_count
+      5
+  """
+  @spec get_debug_info(Poolex.pool_id()) :: t()
+  def get_debug_info(pool_id) do
+    GenServer.call(pool_id, :get_debug_info)
+  end
 end
diff --git a/lib/poolex/private/metrics.ex b/lib/poolex/private/metrics.ex
index 0db840b..2512817 100644
--- a/lib/poolex/private/metrics.ex
+++ b/lib/poolex/private/metrics.ex
@@ -3,12 +3,14 @@ defmodule Poolex.Private.Metrics do
   Functions for dispatching metrics.
   """
 
+  alias Poolex.Private.DebugInfo
+
   @doc """
   Dispatches metrics with current count of idle workers.
   """
   @spec dispatch_pool_size_metrics(Poolex.pool_id()) :: :ok
   def dispatch_pool_size_metrics(pool_id) do
-    debug_info = Poolex.get_debug_info(pool_id)
+    debug_info = DebugInfo.get_debug_info(pool_id)
 
     :telemetry.execute(
       [:poolex, :metrics, :pool_size],


Test patch:
diff --git a/test/poolex_test.exs b/test/poolex_test.exs
index 364ee0d..61fe33a 100644
--- a/test/poolex_test.exs
+++ b/test/poolex_test.exs
@@ -31,7 +31,7 @@ defmodule PoolexTest do
     test "valid after initialization", %{pool_options: pool_options} do
       pool_name = start_pool(pool_options)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.__struct__ == DebugInfo
       assert debug_info.busy_workers_count == 0
@@ -57,7 +57,7 @@ defmodule PoolexTest do
         )
         |> start_pool()
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_impl == SomeBusyWorkersImpl
       assert debug_info.idle_workers_impl == SomeIdleWorkersImpl
@@ -69,7 +69,7 @@ defmodule PoolexTest do
 
       assert {:ok, :some_result} = Poolex.run(pool_name, fn pid -> GenServer.call(pid, :do_some_work) end)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.__struct__ == DebugInfo
       assert debug_info.busy_workers_count == 0
@@ -97,7 +97,7 @@ defmodule PoolexTest do
         _message -> nil
       end
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.__struct__ == DebugInfo
       assert debug_info.busy_workers_count == 1
@@ -119,7 +119,7 @@ defmodule PoolexTest do
 
       Poolex.run(pool_name, fn pid -> Agent.update(pid, fn _state -> 1 end) end)
 
-      [agent_pid] = Poolex.get_debug_info(pool_name).idle_workers_pids
+      [agent_pid] = DebugInfo.get_debug_info(pool_name).idle_workers_pids
 
       assert 1 == Agent.get(agent_pid, fn state -> state end)
     end
@@ -155,14 +155,14 @@ defmodule PoolexTest do
     test "works on idle workers", %{pool_options: pool_options} do
       pool_name = pool_options |> Keyword.put(:workers_count, 1) |> start_pool()
 
-      [some_worker_pid] = Poolex.get_debug_info(pool_name).idle_workers_pids
+      [some_worker_pid] = DebugInfo.get_debug_info(pool_name).idle_workers_pids
 
       Process.exit(some_worker_pid, :kill)
 
       # To be sure that DOWN message will be handed
       :timer.sleep(1)
 
-      [new_worker_pid] = Poolex.get_debug_info(pool_name).idle_workers_pids
+      [new_worker_pid] = DebugInfo.get_debug_info(pool_name).idle_workers_pids
 
       assert some_worker_pid != new_worker_pid
     end
@@ -183,14 +183,14 @@ defmodule PoolexTest do
         _message -> nil
       end
 
-      [some_worker_pid] = Poolex.get_debug_info(pool_name).busy_workers_pids
+      [some_worker_pid] = DebugInfo.get_debug_info(pool_name).busy_workers_pids
 
       Process.exit(some_worker_pid, :kill)
 
       # To be sure that DOWN message will be handed
       :timer.sleep(1)
 
-      [new_worker_pid] = Poolex.get_debug_info(pool_name).idle_workers_pids
+      [new_worker_pid] = DebugInfo.get_debug_info(pool_name).idle_workers_pids
 
       assert some_worker_pid != new_worker_pid
     end
@@ -200,7 +200,7 @@ defmodule PoolexTest do
 
       launch_long_tasks(pool_name, 2)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.busy_workers_count == 1
       assert length(debug_info.waiting_callers) == 1
 
@@ -210,7 +210,7 @@ defmodule PoolexTest do
       # To be sure that DOWN message will be handed
       :timer.sleep(1)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.busy_workers_count == 1
       assert Enum.empty?(debug_info.waiting_callers)
 
@@ -237,7 +237,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert length(debug_info.waiting_callers) == 10
 
       assert Enum.find(debug_info.waiting_callers, fn %Poolex.Caller{from: {pid, _tag}} ->
@@ -247,7 +247,7 @@ defmodule PoolexTest do
       Process.exit(waiting_caller, :kill)
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert length(debug_info.waiting_callers) == 9
 
       refute Enum.find(debug_info.waiting_callers, fn %Poolex.Caller{from: {pid, _tag}} ->
@@ -267,7 +267,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 1
       assert debug_info.idle_workers_count == 1
@@ -278,7 +278,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 0
       assert debug_info.idle_workers_count == 2
@@ -302,7 +302,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 1
       assert debug_info.idle_workers_count == 0
@@ -311,7 +311,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 0
       assert debug_info.idle_workers_count == 0
@@ -324,7 +324,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 0
       assert debug_info.idle_workers_count == 1
@@ -351,7 +351,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert length(debug_info.waiting_callers) == 1
 
       assert Enum.find(debug_info.waiting_callers, fn %Poolex.Caller{from: {pid, _tag}} ->
@@ -359,7 +359,7 @@ defmodule PoolexTest do
              end)
 
       :timer.sleep(100)
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert Enum.empty?(debug_info.waiting_callers)
       assert debug_info.busy_workers_count == 1
       assert debug_info.idle_workers_count == 0
@@ -381,7 +381,7 @@ defmodule PoolexTest do
 
       :timer.sleep(10)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert Enum.empty?(debug_info.waiting_callers)
       assert debug_info.busy_workers_count == 1
       assert debug_info.idle_workers_count == 0
@@ -449,7 +449,7 @@ defmodule PoolexTest do
       refute_received _
 
       Process.sleep(100)
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.busy_workers_count == 0
       assert debug_info.idle_workers_pids == [worker]
 
@@ -464,7 +464,7 @@ defmodule PoolexTest do
 
       launch_long_tasks(pool_name, 5)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.max_overflow == 5
       assert debug_info.busy_workers_count == 5
       assert debug_info.overflow == 4
@@ -484,7 +484,7 @@ defmodule PoolexTest do
 
       assert result == {:error, :checkout_timeout}
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 1
       assert debug_info.max_overflow == 0
@@ -501,7 +501,7 @@ defmodule PoolexTest do
 
       :timer.sleep(50)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.busy_workers_count == 1
       assert debug_info.idle_workers_count == 0
@@ -511,7 +511,7 @@ defmodule PoolexTest do
     test "allows workers_count: 0", %{pool_options: pool_options} do
       pool_name = pool_options |> Keyword.merge(workers_count: 0, max_overflow: 2) |> start_pool()
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.idle_workers_count == 0
       assert debug_info.idle_workers_pids == []
@@ -530,7 +530,7 @@ defmodule PoolexTest do
       assert_receive {:traceable_start, :foo, worker_pid}
       refute_received {:traceable_end, _, _}
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.idle_workers_count == 0
       assert debug_info.idle_workers_pids == []
@@ -539,7 +539,7 @@ defmodule PoolexTest do
       assert debug_info.overflow == 1
 
       assert_receive {:traceable_end, :foo, ^worker_pid}
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
 
       assert debug_info.idle_workers_count == 0
       assert debug_info.idle_workers_pids == []
@@ -634,9 +634,9 @@ defmodule PoolexTest do
     test "adds idle workers to pool", %{pool_options: pool_options} do
       pool_name = start_pool(pool_options)
 
-      assert %DebugInfo{idle_workers_count: 5} = Poolex.get_debug_info(pool_name)
+      assert %DebugInfo{idle_workers_count: 5} = DebugInfo.get_debug_info(pool_name)
       assert :ok = Poolex.add_idle_workers!(pool_name, 5)
-      assert %DebugInfo{idle_workers_count: 10} = Poolex.get_debug_info(pool_name)
+      assert %DebugInfo{idle_workers_count: 10} = DebugInfo.get_debug_info(pool_name)
     end
 
     test "provides new workers to waiting callers", %{pool_options: pool_options} do
@@ -657,7 +657,7 @@ defmodule PoolexTest do
         _message -> nil
       end
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.busy_workers_count == 0
       assert debug_info.idle_workers_count == 0
       assert Enum.count(debug_info.waiting_callers) == 1
@@ -665,7 +665,7 @@ defmodule PoolexTest do
 
       assert :ok = Poolex.add_idle_workers!(pool_name, 1)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.busy_workers_count == 1
       assert debug_info.idle_workers_count == 0
       assert Enum.empty?(debug_info.waiting_callers)
@@ -689,17 +689,17 @@ defmodule PoolexTest do
     test "removes idle workers from pool", %{pool_options: pool_options} do
       pool_name = start_pool(pool_options)
 
-      assert %DebugInfo{idle_workers_count: 5} = Poolex.get_debug_info(pool_name)
+      assert %DebugInfo{idle_workers_count: 5} = DebugInfo.get_debug_info(pool_name)
       assert :ok = Poolex.remove_idle_workers!(pool_name, 2)
-      assert %DebugInfo{idle_workers_count: 3} = Poolex.get_debug_info(pool_name)
+      assert %DebugInfo{idle_workers_count: 3} = DebugInfo.get_debug_info(pool_name)
     end
 
     test "removes all idle workers when argument is bigger than idle_workers count", %{pool_options: pool_options} do
       pool_name = pool_options |> Keyword.put(:workers_count, 3) |> start_pool()
 
-      assert %DebugInfo{idle_workers_count: 3} = Poolex.get_debug_info(pool_name)
+      assert %DebugInfo{idle_workers_count: 3} = DebugInfo.get_debug_info(pool_name)
       assert :ok = Poolex.remove_idle_workers!(pool_name, 5)
-      assert %DebugInfo{idle_workers_count: 0} = Poolex.get_debug_info(pool_name)
+      assert %DebugInfo{idle_workers_count: 0} = DebugInfo.get_debug_info(pool_name)
     end
 
     test "raises error on non positive workers_count", %{pool_options: pool_options} do
@@ -729,7 +729,7 @@ defmodule PoolexTest do
         )
         |> start_pool()
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.failed_to_start_workers_count == 2
       assert debug_info.idle_workers_count == 3
 
@@ -738,7 +738,7 @@ defmodule PoolexTest do
 
       :timer.sleep(150)
 
-      debug_info = Poolex.get_debug_info(pool_name)
+      debug_info = DebugInfo.get_debug_info(pool_name)
       assert debug_info.failed_to_start_workers_count == 0
       assert debug_info.idle_workers_count == 5
     end