Commit Graph

21 Commits

Author SHA1 Message Date
Miro Hrončok 758ba823f2 Replace deprecated Thread.isAlive() with Thread.is_alive()
The isAlive() method of threading.Thread has been removed in Python 3.9.
The is_alive() method is available on Python 2.6+.

See https://bugs.python.org/issue37804

Change-Id: I951b1ae331c3101722fe34babf81d6f82d838380
2020-06-01 12:49:07 +02:00
Tobias Henkel 3d9f47be1d
Properly close streams
When running test cases in the debugger it spits out resource warnings
about non-closed streams [1]. Explicitly closing the streams of the
subprocesses and log streamer fixes this warning. Maybe this even
solves the memory leak we're currently seeing in the executors.

[1] Trace:
/zuul/executor/server.py:1894: ResourceWarning: unclosed file <_io.BufferedReader name=60>
  self.proc = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback

/zuul/executor/server.py:124: ResourceWarning: unclosed file <_io.BufferedReader name=11>
  stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Change-Id: I65f191dc2e50f9c84f5bf6a3967d768d7ebe6b04
2019-02-03 17:16:44 +01:00
Fabien Boucher bc20de95e5 Remove unecessary shebang and exec bit
Change-Id: I54de68b11f055a9269ca5efb8a57f81d57f9d55f
2018-07-26 07:12:24 +00:00
David Shrewsbury 93eb56dfc8 Remove need to start executor as root
Now that we have a finger gateway, we no longer need to start the
executor as root so that the finger streamer on the executor can
bind to port 79 (default port for the finger streamer is changed
from 79 to 7900). Remove that requirement.

Change-Id: I6df685044c4ce81fd263043adba832609da100af
2018-01-10 13:57:16 -05:00
David Shrewsbury 79a66ddab8 Strip \r from build UUID in fingergw
Without stripping this, we won't be able to match UUIDs.

Change-Id: I06b98b7f883433313304bfc3bb21edd5725b94e6
2018-01-03 14:15:43 -05:00
David Shrewsbury fe1f1944a6 Add finger gateway
This adds the zuul-fingergw app that should be run as root (so that
it can connect to the standard finger port 79), but changes user privs
immediately after binding that port.

Common streaming functions have been moved to streamer_utils.py to
be shared among modules.

Support for CommandSocket has been included.

Change-Id: Ia35492fe951e7b9367eeab0b145d96189d72c364
2017-12-13 10:07:37 -05:00
David Shrewsbury 8d06afd8db Switch to threading model of socketserver
In an attempt to maybe get more information as to why the finger
daemon seems to be disappearing on us, try using threads instead
of forks. Alas, there is no spoon.

Change-Id: I473d874037fb81b940bfe71e5d6d1a17b131635f
2017-11-03 10:45:15 -04:00
David Shrewsbury 41172e4b40 Add log streaming logging and exception handling
Add some exception handling around our internal code and some
logging so we can see when exceptions happen.

Change-Id: Iedd4f4df7f7ac9f9ec6b912131d0bf717f63fe58
2017-10-24 09:30:15 -04:00
David Shrewsbury 70798ea74b Fix for pep8 E722 and ignore E741
New flake8 release causes these to suddenly show up.

Change-Id: If7fa5a549a2e1651d0353defcc910374bdd226c2
2017-10-23 10:50:32 -07:00
David Shrewsbury d664da425b Support IPv6 in the finger log streamer
Also change the log streaming tests to use IPv6 addresses
for ZuulWeb.

Change-Id: I1c1e267c967bbd3c1960cb49785e57109dd6be3c
2017-09-08 15:41:28 -04:00
Jenkins e128b517d0 Merge "Add web-based console log streaming" into feature/zuulv3 2017-07-10 20:09:21 +00:00
Monty Taylor 51139a0682 Add web-based console log streaming
zuul now provides socket-based console streaming, which is super cool.
In order to have jenkins parity with web streaming, we need to provide a
websocket (javascript in browsers can't really connect to random ports
on servers)

After surveying the existing python websocket options, basically all of
them are based around twisted, eventlet, gevent or asyncio. It's not
just a thing we can easily deal with from our current webob/paste
structure, because it is a change to the fundamental HTTP handling.
While we could write our own websocket server implementation that was
threaded like the rest of zuul, that's a pretty giant amount of work.

Instead, we can run an async-based server that's just for the
websockets, so that we're not all of a sudden putting async code into
the rest of zuul and winding up frankensteined. Since this is new code,
using asyncio and python3 seems like an excellent starting place.

aiohttp supports running a websocket server in a thread. It also
supports doing other HTTP/REST calls, so by going aiohttp we can set
ourselves up for a single answer for the HTTP tier.

In order to keep us from being an open socket relay, we'll expect two
parameters as the first message on the websocket - what's the zuul build
uuid, and what log file do we want to stream. (the second thing,
multiple log files, isn't supported yet by the rest of zuul, but one can
imagine a future where we'd like to support that too, so it's in the
protocol) The websocket server will then ask zuul over gearman for the
IP and port associated with the build and logfile and will start
streaming it to the socket.

Ultimately we'll want the status page to make links of the form:

  /console.html?uuid=<uuid>&logfile=console.log

and we'll want to have apache map the websocket server to something like
/console.

Co-Authored-By: Monty Taylor <mordred@inaugust.com>

Change-Id: Idd0d3f9259e81fa9a60d7540664ce8d5ad2c298f
2017-07-10 10:32:28 -04:00
Monty Taylor 3466c79801
Avoid decode/encode in the finger log stream server
Change-Id: I396c4d95f6c713ebf4fc51c3253aa23ff82fecd1
2017-06-30 15:32:32 -05:00
David Shrewsbury c1aafc482c Remove py2 SocketServer import
Python 2.x support has been removed.

Change-Id: Ifc5c6b6169f83c97b5dc818f1a7a7690eceaa22e
2017-06-19 10:16:05 -04:00
David Shrewsbury a289b7402f Stop streaming from server when log file removed
The current streaming code will never terminate the streaming (unless
the client initiates the termination). Let's change it so that we stop
streaming when the log file is removed (job finishes). Also, no need to
check for log truncation since that doesn't happen for these logs.

Change-Id: I73f04ffe998e88b89aa660be05e645d3defb87cc
2017-06-13 16:11:37 -04:00
David Shrewsbury 4dfcf54336 Correct location of ansible log file
The ansible output file will be under UUID/work/logs directory.

Change-Id: Ia2d86e5ad8d9984a9c9ef378a9cfb941a96546f4
2017-06-08 15:56:06 -04:00
Monty Taylor 936c72aa74
Strip double-timestamps from output log
ansible-playbook uses basicConfig at the top of the command, which
essentially takes over everything if you send things to log_path.

Instead, go ahead and log things ourselves so that our log lines can all
look consistent (and so that we can easily html-ify) We pass in the
location via an environment variable since we're not using the log_dir
option in ansible.cfg.

As of this patch, there will be less output. A follow up will add back
the missing callback plugin bits.

Change-Id: Ic3ff57bba7a3a23dc5d0055e8e9888f24641f7d5
2017-06-07 14:42:41 -05:00
James E. Blair 4e6f7018a3 Use a select loop on log streamer socket reads
This lets us protect against long commands (as before), as well
as set a 10 second timeout for a client to send a job uuid for
log streaming.

This should fix a potential hang in the test runner where a
request handler process would stick around forever.

Change-Id: I8c1f21c349e72892237b3b93d867ebbd41f77b0a
2017-06-06 13:48:17 -07:00
David Shrewsbury 27a7c0c537 Fix log streamer closing
For some reason, it can (rarely) happen that the socket used by the log
streamer is already closed when we are in server_close(). Since
our intent is to close it anyway, do not raise an exception on an
already closed socket.

Change-Id: I5828f6351341bac5e55ae2211e8a3b3f94032899
2017-06-01 15:55:47 -04:00
David Shrewsbury 5dfab6d9b6 Fix log streamer for py35
Change-Id: I142eaa04972ae1e09900ada1040eca422b5875b7
2017-05-31 09:39:17 -04:00
David Shrewsbury eb8564702c Add a finger protocol log streamer
This will be started along side the the executor process, similar
to how the scheduler and gearman server are linked.

This will require starting the process as the root user so that we
can grab the finger port properly. The process listening on the
finger port will drop its privileges to the designated user after
grabbing the socket. The executor will also drop its privileges
to the same user after starting the log streamer.

Change-Id: Ib52585cafbd073ccdb7f87432888ce15c7a66f67
2017-05-31 08:19:06 -04:00