Skip to content

Commit

Permalink
Add scheduler log tab to performance reports (#4909)
Browse files Browse the repository at this point in the history
Adds a tab to the performance report with the logs of the scheduler. Note that these are all the logs currently contained in the scheduler's log deque. and not just the logs generated in the performance_report context:
  • Loading branch information
charlesbluca authored Jun 16, 2021
1 parent 42d631d commit 6340b5b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
10 changes: 9 additions & 1 deletion distributed/dashboard/components/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
value,
)
from bokeh.models.widgets import DataTable, TableColumn
from bokeh.models.widgets.markups import Div
from bokeh.palettes import Viridis11
from bokeh.plotting import figure
from bokeh.themes import Theme
Expand Down Expand Up @@ -69,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 format_time, log_errors, parse_timedelta
from distributed.utils import Logs, 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 @@ -2162,6 +2163,13 @@ def update(self):
self.source.data.update(data)


class SchedulerLogs:
def __init__(self, scheduler):
logs = Logs(scheduler.get_logs())._repr_html_()

self.root = Div(text=logs)


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

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

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

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

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

return logs

Expand Down
7 changes: 7 additions & 0 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6939,6 +6939,11 @@ def profile_to_figure(state):
sysmon = SystemMonitor(self, last_count=last_count, sizing_mode="stretch_both")
sysmon.update()

# Scheduler logs
from distributed.dashboard.components.scheduler import SchedulerLogs

logs = SchedulerLogs(self)

from bokeh.models import Div, Panel, Tabs

import distributed
Expand Down Expand Up @@ -6997,12 +7002,14 @@ def profile_to_figure(state):
)
bandwidth_types = Panel(child=bandwidth_types.root, title="Bandwidth (Types)")
system = Panel(child=sysmon.root, title="System")
logs = Panel(child=logs.root, title="Scheduler Logs")

tabs = Tabs(
tabs=[
html,
task_stream,
system,
logs,
compute,
workers,
scheduler,
Expand Down
1 change: 1 addition & 0 deletions distributed/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6374,6 +6374,7 @@ async def f(stacklevel):
assert "Dask Performance Report" in data
assert "x = da.random" in data
assert "Threads: 4" in data
assert "distributed.scheduler - INFO - Clear task state" in data
assert dask.__version__ in data

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


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


class Log(str):
"""A container for logs"""
class Log(tuple):
"""A container for a single log entry"""

level_styles = {
"WARNING": "font-weight: bold; color: orange;",
"CRITICAL": "font-weight: bold; color: orangered;",
"ERROR": "font-weight: bold; color: crimson;",
}

def _repr_html_(self):
return "<pre><code>\n{log}\n</code></pre>".format(
log=html.escape(self.rstrip())
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(dict):
"""A container for multiple logs"""
class Logs(list):
"""A container for a list of log entries"""

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


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

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

Expand Down

0 comments on commit 6340b5b

Please sign in to comment.