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

Print scheduler call stack when SIGUSR2 received #47311

Merged
merged 6 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 10 additions & 0 deletions airflow/jobs/scheduler_job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def _log_memory_usage(self, signum: int, frame: FrameType | None) -> None:
)

def _debug_dump(self, signum: int, frame: FrameType | None) -> None:
import threading
from traceback import extract_stack

if not _is_parent_process():
# Only the parent process should perform the debug dump.
return
Expand All @@ -261,6 +264,13 @@ def _debug_dump(self, signum: int, frame: FrameType | None) -> None:
executor.debug_dump()
self.log.info("-" * 80)

id2name = {th.ident: th.name for th in threading.enumerate()}
for threadId, stack in sys._current_frames().items():
self.log.info("Stack Trace for Scheduler Job Runner on thread: %s", id2name[threadId])
callstack = extract_stack(f=stack, limit=10)
self.log.info("\n\t".join(map(repr, callstack)))
self.log.info("-" * 80)

def _executable_task_instances_to_queued(self, max_tis: int, session: Session) -> list[TI]:
"""
Find TIs that are ready for execution based on conditions.
Expand Down
5 changes: 4 additions & 1 deletion tests/jobs/test_scheduler_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,17 @@ def test_executor_events_processed(self, mock_executors, configure_testing_dag_b
for executor in scheduler_job.executors:
executor.get_event_buffer.assert_called_once()

def test_executor_debug_dump(self, mock_executors):
@patch("traceback.extract_stack")
def test_executor_debug_dump(self, patch_traceback_extract_stack, mock_executors):
scheduler_job = Job()
self.job_runner = SchedulerJobRunner(job=scheduler_job, num_runs=1)
self.job_runner._debug_dump(1, mock.MagicMock())

for executor in scheduler_job.executors:
executor.debug_dump.assert_called_once()

patch_traceback_extract_stack.assert_called()

def test_find_executable_task_instances_backfill(self, dag_maker):
dag_id = "SchedulerJobTest.test_find_executable_task_instances_backfill"
task_id_1 = "dummy"
Expand Down