-
Notifications
You must be signed in to change notification settings - Fork 81
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
Logs in DHaaL are confusing #2734
Comments
Current flow of logs in DHaaL:
graph TD;
subgraph Outputs
terminal{{python console}}
web{{web console}}
end
style terminal fill:#ccc
style web fill:#ccc
dh(dh log buffer)
dh--->web
stdout(process stdout)
stdout-->terminal
sysstdout0(Python's original sys.stdout)
sysstdout0-->stdout;
systemout0(Java's original System.out)
systemout0--> stdout;
sysstdout(sys.stdout reference)
%% sysstdout --> sysstdout0
systemout(System.out reference)
%% systemout --> systemout0
pylogadapter(PythonLogAdapter)
pylogadapter-->systemout1
sysstdout-->pylogadapter
systemout1(dh general system.out replacement)
%% systemout1-->dh %% disabled today
systemout1-->systemout0
systemout-->systemout1
subgraph Use cases
usesystemout["System.out("test")"]
usesysstdout["print("test")"]
usedhlog["log.info().append("test")"]
style usesystemout fill: #fff
style usesysstdout fill: #fff
style usedhlog fill: #fff
end
usesystemout-->systemout
usesysstdout-->sysstdout
usedhlog-->dh
Simple change to enable stdout/err to make it to the web UI:
graph TD;
subgraph Outputs
terminal{{python console}}
web{{web console}}
end
style terminal fill:#ccc
style web fill:#ccc
dh(dh log buffer)
dh--->web
stdout(process stdout)
stdout-->terminal
sysstdout0(Python's original sys.stdout)
sysstdout0-->stdout;
systemout0(Java's original System.out)
systemout0--> stdout;
sysstdout(sys.stdout reference)
%% sysstdout --> sysstdout0
systemout(System.out reference)
%% systemout --> systemout0
pylogadapter(PythonLogAdapter)
pylogadapter-->systemout1
sysstdout-->pylogadapter
systemout1(dh general system.out replacement)
systemout1-->|previously missing| dh
systemout1-->systemout0
systemout-->systemout1
subgraph Use cases
usesystemout["System.out("test")"]
usesysstdout["print("test")"]
usedhlog["log.info().append("test")"]
style usesystemout fill: #fff
style usesysstdout fill: #fff
style usedhlog fill: #fff
end
usesystemout-->systemout
usesysstdout-->sysstdout
usedhlog-->dh
Simple change to enable DH logs to write to stderr (preferred over stdout in case there is a process watching output). Not diagrammed at this time because it is more than a little hard to read.
Potential changes to avoid future surprises:
graph TD;
subgraph Outputs
terminal{{python console}}
web{{web console}}
end
style terminal fill:#ccc
style web fill:#ccc
dh(dh log buffer)
dh--->web
stdout(process stdout)
stdout-->terminal
sysstdout0(Python's original sys.stdout)
sysstdout0-->stdout;
systemout0(Java's original System.out)
systemout0--> stdout;
sysstdout(sys.stdout reference)
%% sysstdout --> sysstdout0
systemout(System.out reference)
%% systemout --> systemout0
pystreamtee(dh python StreamTee)
pystreamtee-->sysstdout0
sysstdout-->pystreamtee
systemout1(dh general system.out replacement)
systemout1-->dh
%%systemout1-->systemout0 % Removed in this step
systemout-->sysstdout
pystreamtee-->systemout1
subgraph Use cases
usesystemout["System.out("test")"]
usesysstdout["print("test")"]
usedhlog["log.info().append("test")"]
style usesystemout fill: #fff
style usesysstdout fill: #fff
style usedhlog fill: #fff
end
usesystemout-->systemout
usesysstdout-->sysstdout
usedhlog-->dh
Fix for #2723
class TeeStream(io.TextIOBase):
encoding = 'utf-8'
closed = False
def __init__(self, stream, write_func, flush_func, close_func):
"""
Creates a new TeeStream to let output be written from out place, but be sent to
multiple places.
Ideally, the stream would be passed as more funcs, but we have to manage correctly
propagating certain non-java details like encoding and isatty.
:param stream: the underlying python stream to use as a prototype
:param write_func: a function to call when data should be written
:param flush_func: a function to call when data should be flushed
:param close_func: a function to call when the stream should be closed
"""
self.stream = stream
self.write_func = write_func
self.flush_func = flush_func
self.close_func = close_func
if stream.encoding is not None:
# Read this in the constructor, since encoding is read as an attr, not a method
self.encoding = stream.encoding
def isatty(self):
return self.stream.isatty()
def fileno(self):
return self.stream.fileno()
def write(self, string):
self.write_func(string)
self.stream.write(string)
def flush(self):
self.close_func()
self.stream.flush()
def close(self):
self.closed = True
self.stream.close() Current flow of logs in Java jetty/netty servers with python enabled
While this implementation supports the features we want and is internally consistent, it would now be inconsistent with the fixes proposed above (fixing isatty/fileno/encoding/etc, as well as requiring a different implementation. As such, I suggest instead the following changes:
Note that this approach would preclude 0-many concurrent python sessions (and while jpy doesn't support that today, the underlying c library does), so we should be cautious in considering this. |
Split off from #2453
From the original issue, linked above:
Roughly, there are two kinds of logs in Deephaven - stdout/stderr which will be written mostly by script code or handle some basic app logging, and Deephaven logs, which is configurable at startup or at runtime but almost exclusively runs from inside the server or engine. Stdout/err should almost always write to the python console, whether it is interactive or not, and both should write to the web console. Additionally, Deephaven logs should generally be written to stderr (not stdout) so a long-running batch script or server can see its output.
Likely will be fixed along with #2723.
The text was updated successfully, but these errors were encountered: