Skip to content

Commit

Permalink
add was_leader metadata to oban.peer.election event
Browse files Browse the repository at this point in the history
  • Loading branch information
notslang committed Sep 16, 2024
1 parent 83d2fc1 commit 6cc44c0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/oban/peers/global.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule Oban.Peers.Global do
:telemetry.span([:oban, :peer, :election], meta, fn ->
locked? = :global.set_lock(key(state), nodes(), 0)

{locked?, %{meta | leader: locked?}}
{locked?, %{was_leader: meta.leader}, %{meta | leader: locked?}}
end)

if locked?, do: notify_lock(state.conf)
Expand Down
4 changes: 2 additions & 2 deletions lib/oban/peers/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ defmodule Oban.Peers.Postgres do

case Repo.transaction(state.conf, fun, retry: 1) do
{:ok, state} ->
{state, %{meta | leader: state.leader?}}
{state, %{was_leader: meta.leader}, %{meta | leader: state.leader?}}

{:error, :rollback} ->
# The peer maintains its current `leader?` status on rollback—this may cause
# inconsistency if the leader encounters an error and multiple rollbacks happen in
# sequence. That tradeoff is acceptable because the situation is unlikely and less of
# an issue than crashing the peer.
{state, meta}
{state, %{was_leader: meta.leader}, meta}
end
end)

Expand Down
3 changes: 2 additions & 1 deletion lib/oban/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ defmodule Oban.Telemetry do
| event | measures | metadata |
| ------------ | -------------- | -------------------------------------------------------------- |
| `:start` | `:system_time` | `:conf`, `:leader`, `:peer`, |
| `:stop` | `:duration` | `:conf`, `:leader`, `:peer`, |
| `:stop` | `:duration` | `:conf`, `:leader`, `:peer`, `:was_leader`, |
| `:exception` | `:duration` | `:conf`, `:leader`, `:peer`, `:kind`, `:reason`, `:stacktrace` |
#### Metadata
* `:conf`, `:kind`, `:reason`, `:stacktrace` — see the explanation in notifier metadata above
* `:leader` — whether the peer is the current leader
* `:was_leader` — whether the peer was the leader before the election occurred
* `:peer` — the module used for peering
## Queue Shutdown Events
Expand Down

0 comments on commit 6cc44c0

Please sign in to comment.