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

Revert refactor to utils.Log[s] and Cluster.get_logs #4941

Merged
merged 2 commits into from
Jun 21, 2021
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
6 changes: 4 additions & 2 deletions distributed/dashboard/components/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from distributed.diagnostics.task_stream import color_of as ts_color_of
from distributed.diagnostics.task_stream import colors as ts_color_lookup
from distributed.metrics import time
from distributed.utils import Logs, format_time, log_errors, parse_timedelta
from distributed.utils import Log, format_time, log_errors, parse_timedelta

if dask.config.get("distributed.dashboard.export-tool"):
from distributed.dashboard.export_tool import ExportTool
Expand Down Expand Up @@ -2165,7 +2165,9 @@ def update(self):

class SchedulerLogs:
def __init__(self, scheduler):
logs = Logs(scheduler.get_logs())._repr_html_()
logs = Log(
"\n".join(line for level, line in scheduler.get_logs())
)._repr_html_()

self.root = Div(text=logs)

Expand Down
13 changes: 8 additions & 5 deletions distributed/deploy/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from ..core import Status
from ..objects import SchedulerInfo
from ..utils import (
MultiLogs,
Log,
Logs,
format_dashboard_link,
log_errors,
parse_timedelta,
Expand Down Expand Up @@ -209,19 +210,21 @@ def _log(self, log):
print(log)

async def _get_logs(self, cluster=True, scheduler=True, workers=True):
logs = MultiLogs()
logs = Logs()

if cluster:
logs["Cluster"] = self._cluster_manager_logs
logs["Cluster"] = Log(
"\n".join(line[1] for line in self._cluster_manager_logs)
)

if scheduler:
L = await self.scheduler_comm.get_logs()
logs["Scheduler"] = L
logs["Scheduler"] = Log("\n".join(line for level, line in L))

if workers:
d = await self.scheduler_comm.worker_logs(workers=workers)
for k, v in d.items():
logs[k] = v
logs[k] = Log("\n".join(line for level, line in v))

return logs

Expand Down
5 changes: 3 additions & 2 deletions distributed/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from distributed.utils import (
LRU,
All,
Log,
Logs,
LoopRunner,
MultiLogs,
TimeoutError,
_maybe_complex,
deprecated,
Expand Down Expand Up @@ -549,7 +550,7 @@ def test_format_bytes_compat():


def test_logs():
d = MultiLogs({"123": [("INFO", "Hello")], "456": [("INFO", "World!")]})
d = Logs({"123": Log("Hello"), "456": Log("World!")})
text = d._repr_html_()
assert is_valid_xml("<div>" + text + "</div>")
assert "Hello" in text
Expand Down
44 changes: 22 additions & 22 deletions distributed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,8 @@ def parse_ports(port):
is_coroutine_function = iscoroutinefunction


class Log(tuple):
"""A container for a single log entry"""
class Log(str):
"""A container for newline-delimited string of log entries"""

level_styles = {
"WARNING": "font-weight: bold; color: orange;",
Expand All @@ -1279,34 +1279,34 @@ class Log(tuple):
}

def _repr_html_(self):
level, message = self

style = "font-family: monospace; margin: 0;"
style += self.level_styles.get(level, "")

return '<p style="{style}">{message}</p>'.format(
style=html.escape(style),
message=html.escape(message),
)


class Logs(list):
"""A container for a list of log entries"""
logs_html = []
for message in self.split("\n"):
style = "font-family: monospace; margin: 0;"
for level in self.level_styles:
if level in message:
style += self.level_styles[level]
break

logs_html.append(
'<p style="{style}">{message}</p>'.format(
style=html.escape(style),
message=html.escape(message),
)
)

def _repr_html_(self):
return "\n".join(Log(entry)._repr_html_() for entry in self)
return "\n".join(logs_html)


class MultiLogs(dict):
"""A container for a dict mapping strings to lists of log entries"""
class Logs(dict):
"""A container for a dict mapping names to strings of log entries"""

def _repr_html_(self):
summaries = [
"<details>\n"
"<summary style='display:list-item'>{title}</summary>\n"
"{logs}\n"
"</details>".format(title=title, logs=Logs(entries)._repr_html_())
for title, entries in sorted(self.items())
"{log}\n"
"</details>".format(title=title, log=log._repr_html_())
for title, log in sorted(self.items())
]
return "\n".join(summaries)

Expand Down