-
Notifications
You must be signed in to change notification settings - Fork 94
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
cat-log: list out/err files when available via tailer #6480
Open
oliver-sanders
wants to merge
3
commits into
cylc:8.4.x
Choose a base branch
from
oliver-sanders:cat-log-list-tailable-files
base: 8.4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+139
−14
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cat-log: List log files which are availably via a configured tailer/viewer command. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,28 +596,51 @@ | |
cmd.append('--prepend-path') | ||
cmd.append(workflow_id) | ||
# TODO: Add Intelligent Host selection to this | ||
proc = None | ||
with suppress(KeyboardInterrupt): | ||
# (Ctrl-C while tailing) | ||
# NOTE: This will raise NoHostsError if the platform is not | ||
# contactable | ||
remote_cylc_cmd( | ||
proc = remote_cylc_cmd( | ||
cmd, | ||
platform, | ||
capture_process=False, | ||
capture_process=(mode == 'list-dir'), | ||
manage=(mode == 'tail'), | ||
text=False | ||
text=(mode == 'list-dir'), | ||
) | ||
if ( | ||
mode == 'list-dir' | ||
and os.path.exists( | ||
os.path.join( | ||
local_log_dir, | ||
'job-activity.log' | ||
) | ||
) | ||
): | ||
# add the local-only job-activity.log file to the remote-list | ||
print('job-activity.log') | ||
|
||
# add and missing items to file listing results | ||
if isinstance(proc, Popen): | ||
# i.e: if mode=='list-dir' and ctrl+c not pressed | ||
out, err = proc.communicate() | ||
MetRonnie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
files = out.splitlines() | ||
|
||
# add files which can be accessed via a tailer | ||
if live_job_id is not None: | ||
if ( | ||
# NOTE: only list the file if it can be viewed in | ||
# both modes | ||
(platform['out tailer'] and platform['out viewer']) | ||
and 'job.out' not in files | ||
): | ||
files.append('job.out') | ||
if ( | ||
(platform['err tailer'] and platform['err viewer']) | ||
and 'job.err' not in files | ||
): | ||
files.append('job.err') | ||
|
||
# add the job-activity.log file which is always local | ||
if os.path.exists( | ||
os.path.join(local_log_dir, 'job-activity.log') | ||
): | ||
files.append('job-activity.log') | ||
|
||
files.sort() | ||
print('\n'.join(files)) | ||
print(err, file=sys.stderr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently on 8.4.0 the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully fixed. |
||
sys.exit(proc.returncode) | ||
|
||
else: | ||
# Local task job or local job log. | ||
logpath = os.path.join(local_log_dir, options.filename) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
#------------------------------------------------------------------------------- | ||
# Test "cylc cat-log" with custom out/err tailers | ||
export REQUIRE_PLATFORM='loc:remote runner:background fs:indep comms:tcp' | ||
. "$(dirname "$0")/test_header" | ||
#------------------------------------------------------------------------------- | ||
set_test_number 12 | ||
#------------------------------------------------------------------------------- | ||
# run the workflow | ||
TEST_NAME="${TEST_NAME_BASE}-validate" | ||
install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" | ||
run_ok "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" | ||
workflow_run_ok "${TEST_NAME_BASE}-run" cylc play -N "${WORKFLOW_NAME}" | ||
#------------------------------------------------------------------------------- | ||
# change the platform the task ran on to the remote platform | ||
sqlite3 \ | ||
"${HOME}/cylc-run/${WORKFLOW_NAME}/log/db" \ | ||
"UPDATE task_jobs SET platform_name = '${CYLC_TEST_PLATFORM}' WHERE name = 'foo' and cycle = '1';" | ||
#------------------------------------------------------------------------------- | ||
# test cylc cat-log --mode=list-dir will not list job.out / err | ||
# (no tailer / viewer configured) | ||
create_test_global_config "" " | ||
[platforms] | ||
[[$CYLC_TEST_PLATFORM]] | ||
out tailer = | ||
err tailer = | ||
out viewer = | ||
err viewer = | ||
" | ||
TEST_NAME="${TEST_NAME_BASE}-list-dir-no-tailers" | ||
run_ok "${TEST_NAME}" cylc cat-log "${WORKFLOW_NAME}//1/foo" -m 'list-dir' | ||
# the job.out and job.err filees | ||
grep_fail "job.out" "${TEST_NAME}.stdout" | ||
grep_fail "job.err" "${TEST_NAME}.stdout" | ||
#------------------------------------------------------------------------------- | ||
# test cylc cat-log --mode=list-dir lists the tailed files | ||
# (both tailer and viewer configured) | ||
create_test_global_config "" " | ||
[platforms] | ||
[[$CYLC_TEST_PLATFORM]] | ||
out tailer = echo OUT | ||
err tailer = echo ERR | ||
out viewer = echo OUT | ||
err viewer = echo ERR | ||
" | ||
# test cylc cat-log --mode=list-dir lists the tailed files | ||
TEST_NAME="${TEST_NAME_BASE}-list-dir-with-tailers" | ||
run_ok "${TEST_NAME}" cylc cat-log "${WORKFLOW_NAME}//1/foo" -m 'list-dir' | ||
# the job.out and job.err filees | ||
grep_ok "job.out" "${TEST_NAME}.stdout" | ||
grep_ok "job.err" "${TEST_NAME}.stdout" | ||
#------------------------------------------------------------------------------- | ||
# test cylc cat-log runs the custom tailers | ||
TEST_NAME="${TEST_NAME_BASE}-cat-out" | ||
run_ok "${TEST_NAME}" cylc cat-log "${WORKFLOW_NAME}//1/foo" -f o -m t | ||
grep_ok "OUT" "${TEST_NAME}.stdout" | ||
run_ok "${TEST_NAME}" cylc cat-log "${WORKFLOW_NAME}//1/foo" -f e -m t | ||
grep_ok "ERR" "${TEST_NAME}.stdout" | ||
#------------------------------------------------------------------------------- | ||
purge | ||
exit |
25 changes: 25 additions & 0 deletions
25
tests/functional/cylc-cat-log/12-remote-out-err-tailer/flow.cylc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[scheduler] | ||
[[events]] | ||
abort on stall timeout = True | ||
stall timeout = PT2M | ||
|
||
[scheduling] | ||
[[graph]] | ||
R1 = foo | ||
|
||
[runtime] | ||
[[foo]] | ||
script = """ | ||
# wait for the started message to be received | ||
cylc__job__poll_grep_workflow_log -E 'foo.*running' | ||
|
||
# remove the out/err files | ||
rm "${CYLC_TASK_LOG_DIR}/job.out" | ||
rm "${CYLC_TASK_LOG_DIR}/job.err" | ||
|
||
# stop the workflow, orphaning this job | ||
cylc stop --now --now "${CYLC_WORKFLOW_ID}" 2>/dev/null >/dev/null | ||
|
||
# suppress any subsequent messages | ||
rm "${CYLC_WORKFLOW_RUN_DIR}/.service/contact" | ||
""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.