Skip to content

Commit

Permalink
Add overflowed boolean metric
Browse files Browse the repository at this point in the history
  • Loading branch information
general-CbIC committed Mar 25, 2024
1 parent 82de787 commit 4674032
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Using metrics, we see that typically, our application uses 10-20 processes, and
- [ ] Pool size
- [x] Idle workers count
- [x] Busy workers count
- [ ] Is max_overflow used?
- [x] Is max_overflow used?
- [ ] Maximum count of "overflowed" workers
- [ ] Usage time
- [ ] How long are workers busy?
Expand Down
3 changes: 2 additions & 1 deletion lib/poolex/private/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule Poolex.Private.Metrics do
[:poolex, :metrics, :pool_size],
%{
idle_workers_count: debug_info.idle_workers_count,
busy_workers_count: debug_info.busy_workers_count
busy_workers_count: debug_info.busy_workers_count,
overflowed: debug_info.overflow > 0
},
%{pool_id: pool_id}
)
Expand Down
24 changes: 21 additions & 3 deletions test/poolex_metrics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ defmodule PoolexMetricsTest do

@tag telemetry_events: [[:poolex, :metrics, :pool_size]]
test "pool size metrics" do
pool_id = start_pool(worker_module: SomeWorker, workers_count: 5, pool_size_metrics: true)
pool_id =
start_pool(
worker_module: SomeWorker,
workers_count: 5,
pool_size_metrics: true,
max_overflow: 5
)

assert_telemetry_event(
[:poolex, :metrics, :pool_size],
%{idle_workers_count: 5, busy_workers_count: 0},
%{idle_workers_count: 5, busy_workers_count: 0, overflowed: false},
%{pool_id: ^pool_id}
)

Expand All @@ -21,7 +27,19 @@ defmodule PoolexMetricsTest do

assert_telemetry_event(
[:poolex, :metrics, :pool_size],
%{idle_workers_count: 4},
%{idle_workers_count: 4, busy_workers_count: 1, overflowed: false},
%{pool_id: ^pool_id}
)

Enum.each(1..5, fn _ ->
launch_long_task(pool_id)
end)

Metrics.dispatch_pool_size_metrics(pool_id)

assert_telemetry_event(
[:poolex, :metrics, :pool_size],
%{idle_workers_count: 0, busy_workers_count: 6, overflowed: true},
%{pool_id: ^pool_id}
)
end
Expand Down

0 comments on commit 4674032

Please sign in to comment.