[autoscaler] Improve Logtimer log messages (#8753)

This commit is contained in:
Ian Rodney 2020-06-04 18:07:27 -07:00 committed by GitHub
parent c1a97c8c04
commit d452932740
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View file

@ -5,13 +5,19 @@ logger = logging.getLogger(__name__)
class LogTimer:
def __init__(self, message):
def __init__(self, message, show_status=False):
self._message = message
self._show_status = show_status
def __enter__(self):
self._start_time = datetime.datetime.utcnow()
def __exit__(self, *_):
def __exit__(self, *error_vals):
td = datetime.datetime.utcnow() - self._start_time
logger.info(self._message +
" [LogTimer={:.0f}ms]".format(td.total_seconds() * 1000))
status = ""
if self._show_status:
status = "failed" if any(error_vals) else "succeeded"
logger.info(" ".join([
self._message, status,
"[LogTimer={:.0f}ms]".format(td.total_seconds() * 1000)
]))

View file

@ -423,16 +423,19 @@ class NodeUpdater:
# Run init commands
self.provider.set_node_tags(
self.node_id, {TAG_RAY_NODE_STATUS: STATUS_SETTING_UP})
with LogTimer(self.log_prefix +
"Initialization commands completed"):
with LogTimer(
self.log_prefix + "Initialization commands",
show_status=True):
for cmd in self.initialization_commands:
self.cmd_runner.run(cmd)
with LogTimer(self.log_prefix + "Setup commands completed"):
with LogTimer(
self.log_prefix + "Setup commands", show_status=True):
for cmd in self.setup_commands:
self.cmd_runner.run(cmd)
with LogTimer(self.log_prefix + "Ray start commands completed"):
with LogTimer(
self.log_prefix + "Ray start commands", show_status=True):
for cmd in self.ray_start_commands:
self.cmd_runner.run(cmd)