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

cylc clean 2: remote clean #4017

Merged
merged 22 commits into from
Jan 20, 2021
Merged

cylc clean 2: remote clean #4017

merged 22 commits into from
Jan 20, 2021

Conversation

MetRonnie
Copy link
Member

@MetRonnie MetRonnie commented Dec 24, 2020

These changes partially address #3887

  1. Remove stopped workflows on all filesystems

Clean on remote hosts in addition to local filesystem. This is done by getting the platforms from the workflow database and then looking up the install targets for those platforms from global.cylc.

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Appropriate tests are included (unit and functional).
  • Appropriate change log entry included.
  • Documentation will be handled by Document cylc clean cylc-doc#256
  • No dependency changes.

until all platforms for that install target have been exhausted
- Ensure DB is closed using a try...finally statement in a couple of 
places where it was lacking
- Refactor checking of the DB compatibility slightly
Fixes a bug where if log and share symlink dirs were the same, but 
share/cycle was different, then share/cycle's target wouldn't get 
removed
Plus: in CylcSuiteDAO, make db_file_name arg non-optional, as it will
raise an exception anyway if not given
@MetRonnie MetRonnie added this to the cylc-8.0b0 milestone Dec 24, 2020
@MetRonnie MetRonnie self-assigned this Dec 24, 2020
@MetRonnie MetRonnie changed the title cylc clean II: attack of the cleans cylc clean 2: remote clean Dec 24, 2020
@MetRonnie
Copy link
Member Author

tests/f/cylc-clean/01-remote.t .. skipped: 'tree' command not available on remote host _remote_background_indep_tcp

@oliver-sanders tree is installed on the GitHub Actions runner but not on the remote host. Is there a way to install tree on the host? (I take it this is to do with Docker?)

cylc/flow/rundb.py Outdated Show resolved Hide resolved
Move initial checking of whether a workflow can be cleaned to its own
function
@oliver-sanders
Copy link
Member

Will push later, but still need to figure out how to get the remote functional test to run on GH Actions: #4017 (comment)

If you need the tree command installed on the remote platform (so you can ssh <host> tree <dir>) then this diff aught to do it:

diff --git a/dockerfiles/cylc-dev/Dockerfile b/dockerfiles/cylc-dev/Dockerfile
index 257dd9e70..dee4f4914 100644
--- a/dockerfiles/cylc-dev/Dockerfile
+++ b/dockerfiles/cylc-dev/Dockerfile
@@ -33,7 +33,7 @@ COPY "$CYLC_FLOW_DIR" "cylc"
 RUN apt-get update && \
     # build-deps: build-essential
     # run deps: procps, rsync
-    apt-get -qq -y install build-essential procps rsync && \
+    apt-get -qq -y install build-essential procps rsync tree && \
     # install conda stuff
     conda init bash && \
     . ./usr/local/etc/profile.d/conda.sh && \

@MetRonnie
Copy link
Member Author

tests/f/cylc-clean/01-remote.t is passing now on Actions

@MetRonnie

This comment has been minimized.

@MetRonnie MetRonnie marked this pull request as ready for review January 5, 2021 18:10
Copy link
Member

@wxtim wxtim left a comment

Choose a reason for hiding this comment

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

Add myself as a reviewer. GH broken.

@wxtim wxtim self-requested a review January 6, 2021 17:02
Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

Looks good, no problems in testing.

The logging is a little odd, the "Removing directory" notices come through as warnings, looks like I get one per install-target but no information as to where it is coming from.

$ cylc clean generic
2021-01-06T15:46:21Z INFO - Cleaning on install target: _remote_background_indep_poll
	(platform: _remote_background_indep_poll)
2021-01-06T15:46:21Z INFO - Cleaning on install target: _remote_background_indep_tcp
	(platform: _remote_background_indep_tcp)
2021-01-06T15:46:21Z WARNING - 2021-01-06T15:46:21Z INFO - Removing directory:
	/root/cylc-run/generic
	
2021-01-06T15:46:21Z WARNING - 2021-01-06T15:46:21Z INFO - Removing directory:
	/root/cylc-run/generic
	
2021-01-06T15:46:21Z INFO - Removing directory: /Users/oliver/cylc-run/generic

We will probably want to clean multiple platforms in parallel for 8.0.0 so reporting remote logging is tricky, can just log in the event of error.

CHANGES.md Outdated Show resolved Hide resolved
cylc/flow/scripts/clean.py Outdated Show resolved Hide resolved
cylc/flow/suite_files.py Outdated Show resolved Hide resolved
cylc/flow/scripts/clean.py Outdated Show resolved Hide resolved
Copy link
Member

@wxtim wxtim left a comment

Choose a reason for hiding this comment

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

  • Read code - Nothing obvious stands out, minor comments.
  • Read tests.
  • Checked-out and poked at. Satisfied it works in the desired way with some of my test workflows.

@oliver-sanders
Copy link
Member

I've noticed too on exvcylcdev that everything that comes back from the Popen subprocess is in stderr instead of stdout for some reason, so it gets logged as a warning.

Hmmm, what does the ret-code say? Would be good to include that in the logging (note we can use the debug level).

@MetRonnie
Copy link
Member Author

ret_code is 0 but I've noticed that the LOG.info gets added to the bottom of the blurb in err:

\nWelcome to the Met Office\n\nWARNING: exvcylcdev.......in accordance with the Monitoring policy.\n\n2021-01-12T10:49:59Z INFO - Removing directory: ~/cylc-run/temp5\n

@oliver-sanders
Copy link
Member

If out and error are coming out funny might be worth checking the function that constructs the SSH command. You may need to tell it to capture/return stdout/err.

@MetRonnie
Copy link
Member Author

Turns out LOG.info() always ends up in stderr! E.g. try

cylc run --no-detach my_flow > /dev/null

and all the logging will still get printed, or try

cylc run --no-detach my_flow 2> /dev/null

and none of the logging will get printed


By default, no destination is set for any logging messages. You can specify a destination (such as console or file) by using basicConfig() as in the tutorial examples. If you call the functions debug(), info(), warning(), error() and critical(), they will check to see if no destination is set; and if one is not set, they will set a destination of the console (sys.stderr) and a default format for the displayed message before delegating to the root logger to do the actual message output.

from https://docs.python.org/3/howto/logging.html#advanced-logging-tutorial

@MetRonnie
Copy link
Member Author

More on this:

# Set up stream logging for CLI. Note:
# 1. On choosing STDERR: Log messages are diagnostics, so STDERR is the
# better choice for the logging stream. This allows us to use STDOUT
# for verbosity agnostic outputs.
# 2. Suite server programs will remove this handler when it becomes a
# daemon.
if options.debug or options.verbose:
LOG.setLevel(logging.DEBUG)
else:
LOG.setLevel(logging.INFO)
# Remove NullHandler before add the StreamHandler
RSYNC_LOG.setLevel(logging.INFO)
while LOG.handlers:
LOG.handlers[0].close()
LOG.removeHandler(LOG.handlers[0])
errhandler = logging.StreamHandler(sys.stderr)
errhandler.setFormatter(CylcLogFormatter(
timestamp=options.log_timestamp))
LOG.addHandler(errhandler)

@hjoliver
Copy link
Member

# 1. On choosing STDERR: Log messages are diagnostics, so STDERR is the 
#    better choice for the logging stream. This allows us to use STDOUT 
#    for verbosity agnostic outputs.

That's correct, IMO. (Although I had kind of forgotten about it!)

@MetRonnie
Copy link
Member Author

Ok - logging verbosity, remote timeout and concurrency of ssh commands should be addressed now

@oliver-sanders
Copy link
Member

Looking good.

Should demote the missing database warning as a missing database is not an error (e.g. flow not run or remote flow installation) suggest:

INFO: No database - only this platform will be cleaned

@oliver-sanders
Copy link
Member

@hjoliver I think this is good to go now if you want to take a poke.

@MetRonnie
Copy link
Member Author

Should demote the missing database warning as a missing database is not an error (e.g. flow not run or remote flow installation)

Updated the latest commit

@MetRonnie
Copy link
Member Author

The tests have passed, however test (ubuntu-latest, 3.7, tests/f tests/k, 1/1, _remote_background_indep_poll _remote_at_indep_poll) took a fair bit longer than usual so that run just timed out before the coverage was uploaded. Might have to increase the GH workflow timeout

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

Might have to increase the GH workflow timeout

Dammit, just when I though things were stable, will keep an eye out.

Looks good to me. Going to leave for @hjoliver to merge. Will need to rebase squash pre-merge.

@MetRonnie
Copy link
Member Author

Will need to rebase squash pre-merge.

How come? I tried to keep my commits logically grouped. I can try to squash them down more before merging if needed, but I think it would pay to keep some of the changes separate

@oliver-sanders
Copy link
Member

oliver-sanders commented Jan 15, 2021

Tis how we work, most of the commits here document the process of how this branch came to be, this information doesn't really have any value going forward. We aren't going to go back and revert one commit and knowing that one feature was developed slightly earlier than another isn't useful info to anyone. The extra commits do, however, bloat the repo and make bisects longer.

Some (I think predominantly agile) projects use "squash and merge" for all PRs to strip out unnecessary commits, makes sense as the most important information to preserve the is the link to the PR, the history and purpose of the branch should be documented there. We don't because our PRs often do multiple things (we aren't very agile).

(btw we don't use commits as a measure of work or play number games)

@MetRonnie
Copy link
Member Author

preserve the is the link to the PR, the history and purpose of the branch should be documented there

I don't know why that didn't occur to me before 👍

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

Looks great 🎉

Please merge after tidying the commit history as suggested by @oliver-sanders (duh - he suggested squash and merge 🤦 )

@hjoliver hjoliver merged commit 8aba48f into cylc:master Jan 20, 2021
@MetRonnie MetRonnie deleted the cylc-clean branch January 20, 2021 10:22
@MetRonnie MetRonnie linked an issue Jan 20, 2021 that may be closed by this pull request
@MetRonnie MetRonnie mentioned this pull request Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cylc clean
4 participants