-
Notifications
You must be signed in to change notification settings - Fork 179
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
feat: Broadcast plan over port 3238 #3756
Changes from 6 commits
6b28b64
b8e9257
a029cf0
4d47847
0443d41
4cf3112
b654679
0f90721
8e3e326
568f5ce
0517f7c
4d5611b
cc1d15d
74175a5
34faa38
2b99ef3
5e7e2bc
45a4459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,10 @@ | |
|
||
_runner: Runner | None = None | ||
|
||
_enable_broadcast: bool = False | ||
_broadcast_addr: str = "127.0.0.1" | ||
_broadcast_port: int = 3238 | ||
|
||
_instance: ClassVar[DaftContext | None] = None | ||
_lock: ClassVar[threading.Lock] = threading.Lock() | ||
|
||
|
@@ -197,6 +201,31 @@ | |
return _DaftContext | ||
|
||
|
||
def broadcast_metrics( | ||
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. This should really be more of a "enable dashboard" function |
||
enable: bool = True, | ||
addr: str = "127.0.0.1", | ||
port: int = 3238, | ||
) -> DaftContext: | ||
"""Enable (or disable) the broadcasting of Daft metrics over the given address. | ||
|
||
This enables the Daft Dashboard to collect and display the data which is sent to it as Daft executes queries. | ||
|
||
Args: | ||
enable: Whether or not to enable broadcasting Daft metrics. | ||
addr: The IP address on which to broadcast the metrics. | ||
port: The port on which to broadcast the metrics. | ||
|
||
Returns: | ||
DaftContext: Daft context after enabling or disabling metrics broadcasting. | ||
""" | ||
ctx = get_context() | ||
with ctx._lock: | ||
ctx._enable_broadcast = enable | ||
ctx._broadcast_addr = addr | ||
ctx._broadcast_port = port | ||
return ctx | ||
|
||
|
||
def set_runner_ray( | ||
address: str | None = None, | ||
noop_if_initialized: bool = False, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,28 @@ | |
else: | ||
return self._result_cache.value | ||
|
||
def explain_broadcast(self): | ||
raunakab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Broadcast the mermaid-formatted plan on the given port (assuming metrics-broadcasting is enabled).""" | ||
import socket | ||
|
||
from daft.dataframe.display import MermaidFormatter | ||
|
||
ctx = get_context() | ||
with ctx._lock: | ||
raunakab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not ctx._enable_broadcast: | ||
return | ||
|
||
addr = ctx._broadcast_addr | ||
port = ctx._broadcast_port | ||
|
||
is_cached = self._result_cache is not None | ||
instance = MermaidFormatter(builder=self.__builder, show_all=True, simple=False, is_cached=is_cached) | ||
raunakab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
text: str = instance._repr_markdown_() | ||
|
||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | ||
sock.connect((addr, port)) | ||
raunakab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sock.sendall(text.encode("utf-8")) | ||
|
||
@DataframePublicAPI | ||
def explain( | ||
self, show_all: bool = False, format: str = "ascii", simple: bool = False, file: Optional[io.IOBase] = None | ||
|
@@ -177,6 +199,7 @@ | |
file (Optional[io.IOBase]): Location to print the output to, or defaults to None which defaults to the default location for | ||
print (in Python, that should be sys.stdout) | ||
""" | ||
self.explain_broadcast() | ||
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. Is this correct? Why would be broadcast to the dashboard if we're not executing a query 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. Hmm, I was thinking if a user just wanted to see what plan would be produced without executing a query, they could also use the dashboard UI to view the query plan. In this case, the UI would show:
|
||
is_cached = self._result_cache is not None | ||
if format == "mermaid": | ||
from daft.dataframe.display import MermaidFormatter | ||
|
@@ -2818,6 +2841,7 @@ | |
DataFrame: DataFrame with materialized results. | ||
""" | ||
self._materialize_results() | ||
self.explain_broadcast() | ||
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. Maybe consider making this a decorator for all "execution" methods ( 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. Sounds good. A decorator makes sense here. Will update in the coming commit. 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. Updated to use decorator instead. 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. I will need to add this to more APIs. Do we have an exhaustive list somewhere of all the APIs we would want to add this decorator to? |
||
|
||
assert self._result is not None | ||
dataframe_len = len(self._result) | ||
|
@@ -2889,6 +2913,7 @@ | |
n: number of rows to show. Defaults to 8. | ||
""" | ||
dataframe_display = self._construct_show_display(n) | ||
self.explain_broadcast() | ||
try: | ||
from IPython.display import display | ||
|
||
|
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.
Please put this behind a DashboardConfig dataclass?