Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include zeros for missing queue states in Oban polling metrics #245

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/prom_ex/plugins/oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,25 @@ if Code.ensure_loaded?(Oban) do

config
|> Oban.Repo.all(query)
|> Enum.each(fn {queue, state, count} ->
|> include_zeros_for_missing_queue_states()
|> Enum.each(fn {{queue, state}, count} ->
measurements = %{count: count}
metadata = %{name: normalize_module_name(oban_supervisor), queue: queue, state: state}

:telemetry.execute([:prom_ex, :plugin, :oban, :queue, :length, :count], measurements, metadata)
end)
end

defp include_zeros_for_missing_queue_states(query_result) do
all_queues = Keyword.keys(Oban.config().queues)
all_states = Oban.Job.states()

zeros = for queue <- all_queues, state <- all_states, into: %{}, do: {{to_string(queue), to_string(state)}, 0}
counts = for {queue, state, count} <- query_result, into: %{}, do: {{queue, state}, count}

Map.merge(zeros, counts)
end

defp get_oban_supervisors(opts) do
opts
|> Keyword.get(:oban_supervisors, [Oban])
Expand Down