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

Log worker close reason in events #8042

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
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
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
Loading