Skip to content

Add timestamp to secondary status for traning job logs #427

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

Merged
merged 2 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 11 additions & 12 deletions src/sagemaker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,17 @@ def secondary_training_status_message(job_description, prev_description):
if prev_description_secondary_transitions is not None else 0
current_transitions = job_description['SecondaryStatusTransitions']

if len(current_transitions) == prev_transitions_num:
return current_transitions[-1]['StatusMessage']
else:
transitions_to_print = current_transitions[prev_transitions_num - len(current_transitions):]
status_strs = []
for transition in transitions_to_print:
message = transition['StatusMessage']
time_str = datetime.utcfromtimestamp(
time.mktime(transition['StartTime'].timetuple())).strftime('%Y-%m-%d %H:%M:%S')
status_strs.append('{} {} - {}'.format(time_str, transition['Status'], message))

return '\n'.join(status_strs)
transitions_to_print = current_transitions[-1:] if len(current_transitions) == prev_transitions_num else \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you replace this \ ?

it probably makes sense to split this and add a comment on what the intended state on each branch is? its not very obvious.
https://github.com/google/styleguide/blob/gh-pages/pyguide.md#32-line-length

current_transitions[prev_transitions_num - len(current_transitions):]

status_strs = []
for transition in transitions_to_print:
message = transition['StatusMessage']
time_str = datetime.utcfromtimestamp(
time.mktime(job_description['LastModifiedTime'].timetuple())).strftime('%Y-%m-%d %H:%M:%S')
status_strs.append('{} {} - {}'.format(time_str, transition['Status'], message))

return '\n'.join(status_strs)


def download_folder(bucket_name, prefix, target, sagemaker_session):
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_secondary_training_status_changed_empty():

def test_secondary_training_status_message_status_changed():
now = datetime.now()
TRAINING_JOB_DESCRIPTION_1['SecondaryStatusTransitions'][-1]['StartTime'] = now
TRAINING_JOB_DESCRIPTION_1['LastModifiedTime'] = now
expected = '{} {} - {}'.format(
datetime.utcfromtimestamp(time.mktime(now.timetuple())).strftime('%Y-%m-%d %H:%M:%S'),
STATUS,
Expand All @@ -157,13 +157,18 @@ def test_secondary_training_status_message_status_changed():

def test_secondary_training_status_message_status_not_changed():
now = datetime.now()
TRAINING_JOB_DESCRIPTION_1['SecondaryStatusTransitions'][-1]['StartTime'] = now
assert secondary_training_status_message(TRAINING_JOB_DESCRIPTION_1, TRAINING_JOB_DESCRIPTION_2) == MESSAGE
TRAINING_JOB_DESCRIPTION_1['LastModifiedTime'] = now
expected = '{} {} - {}'.format(
datetime.utcfromtimestamp(time.mktime(now.timetuple())).strftime('%Y-%m-%d %H:%M:%S'),
STATUS,
MESSAGE
)
assert secondary_training_status_message(TRAINING_JOB_DESCRIPTION_1, TRAINING_JOB_DESCRIPTION_2) == expected


def test_secondary_training_status_message_prev_missing():
now = datetime.now()
TRAINING_JOB_DESCRIPTION_1['SecondaryStatusTransitions'][-1]['StartTime'] = now
TRAINING_JOB_DESCRIPTION_1['LastModifiedTime'] = now
expected = '{} {} - {}'.format(
datetime.utcfromtimestamp(time.mktime(now.timetuple())).strftime('%Y-%m-%d %H:%M:%S'),
STATUS,
Expand Down