Skip to content

qa/workunit: register WatchedProcess to fail fast - #71030

Merged
shraddhaag merged 2 commits into
ceph:mainfrom
shraddhaag:wip-shraddhaag-workunit-watchdog
Aug 20, 2026
Merged

shraddhaag merged 2 commits into
ceph:mainfrom
shraddhaag:wip-shraddhaag-workunit-watchdog

Conversation

@shraddhaag

@shraddhaag shraddhaag commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Issue

Teuthology jobs that are implemented as a workunit keep running even after encountering a daemon failure for a long time (~ 3 hours per job). This is both time and resource intensive unnecessarily.

Solution

This PR registers a Workunit as a WatchedProcess. This is beneficial for the following reasons:

  1. Watchdog can kill the registered workunit once it barks, thus failing fast incase of a failure.
  2. The actual reason for the failure can be surfaced from within the workunit instead of an ambiguous failure reason.

By default, all workunits have wactchdog disabled. This can be enabled by doing the following:

        tasks:
        - workunit:
            watchdog: true
            clients:
            ...

For cephadm tasks:

        overrides:
            cephadm:
                watchdog_setup: true

Scope

This PR enables the above setting for rados_api_tests.yaml in crimson-rados suite. The above instrumentation can be used to enable this behaviour in all workunits spanning across different suites.

Time Saved

Timing per job:

Job Time to Completion Time Spent in Job After Watchdog Barked Link
Before this change 3 hour 13 mins 2 hours 50 mins ref
After this change 20 mins 2 mins 9 sec ref

Fixes: https://tracker.ceph.com/issues/79644

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • [] Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@shraddhaag
shraddhaag marked this pull request as ready for review August 13, 2026 12:41

@perezjosibm perezjosibm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor comments but I am not sure if apply, thanks

Comment thread qa/tasks/workunit.py
if watchdog:
watched = WorkunitProcess(remote, role, workunit,
workunit_path)
ctx.ceph[cluster].watched_processes.append(watched)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering whether this list always exists, or we need to check it does?

@shraddhaag shraddhaag Aug 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It always exists in watchdog implementation, please see:

self.watched_processes = ctx.ceph[config["cluster"]].watched_processes

Comment thread qa/tasks/workunit.py
for line in self._remote.sh('ps -eo sess=,args=', quiet=True).splitlines():
sess, _, args = line.strip().partition(' ')
if self._pattern in args and sess.isdigit() and sess != '0':
return sess

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the PID of the process to be watched is saved somewhere else

Comment thread qa/tasks/workunit.py
return
self._remote.run(
args=['sudo', 'pkill', '-KILL', '-s', sess],
check_status=False,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid question: by killing the session do we always ensure we kill the underlying (remote) process PID? Unless the watchdog is the one that kills the (remote) PID 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply killing the script by PID is unfortunately not enough in this case, here is the full explanation: #71030 (comment)

Comment thread qa/tasks/workunit.py
label="workunit test {workunit}".format(workunit=workunit)
)
except Exception:
if watched is not None and watched.exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am understanding correctly, a test failure has precedence over a watchdog bark, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not stop the workunit on a test failure. The test should keep on executing even if a test fails. The only case were we would want to stop is if a daemon aborts. In this case, continuing to run the tests is useless as the cluster itself is now broken.

Comment thread qa/tasks/workunit.py
Comment on lines +55 to +76
def _session(self):
"""
The session the workunit's ssh command runs in, or None if it has
already gone. This is needed to terminate the process session if
the watchdog barks.
"""
for line in self._remote.sh('ps -eo sess=,args=', quiet=True).splitlines():
sess, _, args = line.strip().partition(' ')
if self._pattern in args and sess.isdigit() and sess != '0':
return sess
return None

def stop(self):
log.debug('Stopping %s: %s', self._name, self._exception)
sess = self._session()
if sess is None:
log.debug('%s has already gone', self._name)
return
self._remote.run(
args=['sudo', 'pkill', '-KILL', '-s', sess],
check_status=False,
)

@shraddhaag shraddhaag Aug 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To stop execution, simply killing the script was not sufficient here due to the child processes being spawned by workunit, which inherit its stdout and stderr. The way to get around it, is by killing the process group. That is also not sufficient here as timeout(1) calls setpgid() which leaves the test binary in a group of its own. I verified this on a run:

 PID   PPID   PGID    SID  STAT  ARGS
 37515  28778  37515  37515  Ss   timeout 3h .../rados/test.sh --crimson
 37542  37515  37515  37515  S    bash .../rados/test.sh --crimson
 37546  37542  37546  37515  S    timeout 5400 ceph_test_rados_api_aio
 37547  37546  37546  37515  Sl   ceph_test_rados_api_aio

Session ID is common across the script and all its child processes and hence that is what is used to stop the script (and the child processes) in the event of a failure.

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shraddhaag looks good! Just 1 note that I added that I think we should add before merging

Comment thread qa/tasks/workunit.py
subdir=config.get('subdir'),
timeout=timeout,
cleanup=cleanup,
watchdog=watchdog,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that we also handle the client: all options. With the current changes, we will not send any watchdog to the client all option

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, I've taken care of that! Thanks Nitzan :)

@shraddhaag
shraddhaag force-pushed the wip-shraddhaag-workunit-watchdog branch from 6c8cfb3 to bb08408 Compare August 17, 2026 02:31

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Before this commit, workunit did not implement WatchedProcess.
If a daemon fails and watchdog barks, the workunit would still keep
running against a broken cluster. This lead to long running jobs,
which ideally should have been terminated as soon as the watchdog
barked.

This commit registers Workunit as a WatchedProcess. This is beneficial
for the following reasons:

1. Watchdog can kill the registered workunit once it barks, thus
failing fast incase of a failure.
2. The actual reason for the failure can be surfaced from within the
workunit  instead of an ambiguous failure reason.

By default, all workunits have wactchdog disabled. This can be enabled
by setting watchdog:true (and for cephadm: watchdog_setup:true).

Signed-off-by: Shraddha Agrawal <[email protected]>
This commit enables watchdog in the workunit that runs rados_api_tests
in the crimson-rados teuthology test suite.

This is done such that if an OSD aborts and doesn't recover within the
watchdog confirgured timeout (here: 300s), we can abort the test at that
point, instead of continuing to run the rados_api_tests with their 5400s
timeout per test.

In case the tests fail and a daemon aborts, the tests now complete
within 30 mins instead of running for 3 hours.

Signed-off-by: Shraddha Agrawal <[email protected]>
@shraddhaag
shraddhaag force-pushed the wip-shraddhaag-workunit-watchdog branch from bb08408 to 1d38a2c Compare August 20, 2026 04:06
@shraddhaag
shraddhaag merged commit 4c81b2c into ceph:main Aug 20, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/32344528802

shraddhaag added a commit that referenced this pull request Aug 27, 2026
This commit enables the workunit's watchdog introduced in
#71030 in all workunit tasks in
crimson-raods suite. This will help these tasks fail fast in the
event of a failure, instead of running for long hours, hogging
resources.

Signed-off-by: Shraddha Agrawal <[email protected]>
viliam-durina pushed a commit to viliam-durina/ceph that referenced this pull request Sep 2, 2026
This commit enables the workunit's watchdog introduced in
ceph#71030 in all workunit tasks in
crimson-raods suite. This will help these tasks fail fast in the
event of a failure, instead of running for long hours, hogging
resources.

Signed-off-by: Shraddha Agrawal <[email protected]>
kabicin pushed a commit to kabicin/ceph that referenced this pull request Sep 29, 2026
This commit enables the workunit's watchdog introduced in
ceph#71030 in all workunit tasks in
crimson-raods suite. This will help these tasks fail fast in the
event of a failure, instead of running for long hours, hogging
resources.

Signed-off-by: Shraddha Agrawal <[email protected]>
dparmar18 pushed a commit to dparmar18/ceph that referenced this pull request Oct 5, 2026
This commit enables the workunit's watchdog introduced in
ceph#71030 in all workunit tasks in
crimson-raods suite. This will help these tasks fail fast in the
event of a failure, instead of running for long hours, hogging
resources.

Signed-off-by: Shraddha Agrawal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants