Skip to content

Commit

Permalink
Log worker close reason in events (#8042)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter authored Jul 31, 2023
1 parent 9a9d2c3 commit d8cbc12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion distributed/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ async def test_remove_worker_by_name_from_scheduler(s, a, b):
)


@gen_cluster(config={"distributed.scheduler.events-cleanup-delay": "10 ms"})
@gen_cluster(config={"distributed.scheduler.events-cleanup-delay": "500 ms"})
async def test_clear_events_worker_removal(s, a, b):
assert a.address in s.events
assert a.address in s.workers
Expand Down Expand Up @@ -1755,6 +1755,12 @@ async def test_close_worker(s, a, b):

await asyncio.sleep(0.2)
assert len(s.workers) == 1
events = s.get_events(a.address)
assert any(
"reason" in msg
for _, msg in events
if "closing-worker" in msg.get("action", "")
)


@pytest.mark.slow
Expand Down
6 changes: 6 additions & 0 deletions distributed/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,12 @@ async def close( # type: ignore

disable_gc_diagnosis()

try:
self.log_event(self.address, {"action": "closing-worker", "reason": reason})
except Exception:
# This can happen when the Server is not up yet
logger.exception("Failed to log closing event")

try:
logger.info("Stopping worker at %s. Reason: %s", self.address, reason)
except ValueError: # address not available if already closed
Expand Down

0 comments on commit d8cbc12

Please sign in to comment.