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

Celery #41

Merged
merged 104 commits into from Jun 10, 2020
Merged

Celery #41

merged 104 commits into from Jun 10, 2020

Conversation

andyneff
Copy link
Member

@andyneff andyneff commented Jun 2, 2020

Finalize working support for celery executor and multiprocess logging

Breaks

  • terra.settings.terra.zone can be misrepresented in ThreadPoolExecutor, resulting in log messages appearing to come from the wrong zone.

Added

  • Added settings.terra.zone to settings
  • Added zone to logging
  • Added color formatter to logging
  • Added Debug4 level to logging
  • Added terra.tests.demo app and service for testing config file in.
  • Terra demo app auto added to celery apps
  • TERRA_KEEP_TEMP_DIR env var to keep temp autogenerated files for debugging
  • Celery has a fourth zone known as task_controller for the celery worker's
    parent
  • Executors have a volume map translation too
  • Task kwargs and returns values are can have map translation applied to them
  • ConfigurationWarning
  • Each run of a terra app gets assigned a UUID, settings.terra.uuid
  • All multi processing processes use a TCP server for sending logs, using
    settings.logging.server.hostname and settings.logging.server.port
  • Settings can be pickled
  • terra.logging.LogRecordStreamHandler to log out to TCP
  • terra.logging.LogRecordSocketReceiver to run a threaded server to receive TCP
    log messages
  • Terra's own task class, terra.task.TerraTask

Changes

  • TERRA_CELERY_MAIN_NAME is now auto deteremined by default. It only has to be
    set if the main App CLI is a built-in (aka compiled python module) which is
    not typical.
  • Computes are now responsible for configuring and reconfiguring the logger for
    controller and runners zones
  • Executors are now responsible for configuring and reconfiguring the logger
    for task zones
  • Executor and compute volume maps are stored in settings now.
  • Settings files dumped during processing contain the uuid, to make determining
    which run is which easier.
  • All executors (including thread/process) inherit from
    terra.executor.base.BaseExecutor
  • Celery CLI is no longer called directly, instead terra.executor.celery should
    be called
  • Celery logging facilities are disabled, only terra logging used now
  • terra.logging.get_logger -> terra.logging.getLogger
  • Default format includes hostname and zone.
  • Runner and tasks no longer output log messages to stderr. Instead the master
    controller will output the runner's and task's messages (received via TCP)
    itself, to stderr.
  • Uncaught exceptions stack traces now have a header with the hostname and zone
  • Uncaught exceptions are no longer printed twice due to logging
  • logging file_handler -> main_log_handler
  • hostname, zone, and other logging settings set with filters instead of
    formatters or "extra" variables, it is a more universal entrypoint for adding
    values
  • Tasks should now be decorated with terra.task.shared_task

Bug Fixes

  • Fixed new? bug on CI with flake8 being run in the wrong directory, not finding
    the config file all of a sudden
  • Fixed typos in Redis command secret file variable names, causing the wrong
    variable to be used
  • Added celery as a dependency of terra
  • Removed invalid password characters from auto generated redis password
  • Docker compute use non-TTY containers, to fix a stdout nl/cr bug
  • Remove duplicated volumes in singularity
  • Not setting the virtualenv_dir in virtualenv compute now issues a warning
  • Fixed tilde expantion in settings.
  • Celery shutdown uses a tuple of self._futures to create a copy of futures and
    prevent a race condition
  • Catch file not existing when deleting tmp_file

Testing

  • Check to see if any test permanently modifies os.environ by accident
  • Refactors test cases so settings, logging and other specical cases are all
    handled by Test Cases classes in terra.tests.utils
  • TestSettingsUnconfiguredCase prepares terra.core.settings, but leaves it
    unconfigured
  • TestSettingsConfiguredCase, same as TestSettingsUnconfiguredCase, but
    configures it using an empty dictionary.
  • TestLoggerCase - An Unconfigured Settings case, that uses a modified temp dir
    function so that all temp files are created in the test dir, preventing /tmp
    from being spammed with temp terra log files. Also mocks the TCP server so the
    TCP server thread is not actually started.
  • TestComputeCase - Allows for a compute backend to be loaded
  • TestExecutorCase - Allows for an executor backend to be loaded.
  • TestSignalCase - Enables signals. By default, signals are disabled for all
    unit tests.
  • TestLoggerConfigureCase - Test logging with settings configured and signals
    enabled, but TCP Server is still disabled.

andyneff and others added 30 commits March 19, 2020 16:41
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
- Even supports the setting context manager
- Added FORKED_BY_MULTIPROCESSING in hopes of Windows support?
- Added TERRA_IS_CELERY_WORKER so I can know if I'm a worker
- The main logger is now setup by the Executor, so in the future
  ProcessPool and celery can support their own logging schemes

Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Set terra.zone for tasks universally
- Now executor settings are auto translated from runner to exectutor,
  instead of from master controller to executor. This clears the path to
  more consistent behavior when it comes to passing in arguments.
- Task args and kwargs that match the same suffix patterns settings so,
  will now be auto translated from runner to task. This should make for
  a more seemless transaction to task, as long as the variable names are
  right.
- Executor and compute both have a volume map store in the settings now.
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Auto translate arguments to task functions
Fix resetting zone on exception [skipci]
- Temporary directors have a meaningful suffix
- TERRA_KEEP_TEMP_DIR added for debuging
- TERRA_CELERY_MAIN_NAME is automatic now
- config.json.orig removed, as no longer needed
- Fixed a duplicate volume_map bug

Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
- Once celery task logs are received, sucess will just be a spam message
- The rest of the message are updated to reflect their severity

Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Return values in celery get volume translations
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Add the -T flag to `docker-compose`  which disables its tty allocation [1] (the inverse of docker's -t flag). This prevents the staircase formatting we were observing when printing (not just logging) messages received by the master controler's Listner (which is running in a background thread). Because this container runs in the forground, it can change the tty's settings. This is a problem because it looks like the container disables opost (which postprocess output) in the tty, which screws up the formatting done with onlcr [2].

Also, we don't need a tty because logging to stdout/stderr directly in these processes is not threadsafe.

A simple example of this error can be seen with the 'Sending and receiving logging events across a network' example in the python logging cookbook, which sets up a handler on the server to listen for messages and a handler on the client to send them. Start the server with

$ python3 server.py &

and the client with:

$ docker run -i --rm -v /home/sgrichar/terra/terra_dsm/external/terra:/src python:3 python3 /src/client.py

which looks as expected; compared to this, which doesn't:

$ docker run -it --rm -v /home/sgrichar/terra/terra_dsm/external/terra:/src python:3 python3 /src/client.py

[1] moby/moby#8513
[2] https://unix.stackexchange.com/a/242814/332869
[3] https://docs.python.org/3/howto/logging-cookbook.html#sending-and-receiving-logging-events-across-a-network
…ontroller. Currently the process hangs and does not exit once the tasks are done
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Justfile Outdated Show resolved Hide resolved
Justfile Outdated Show resolved Hide resolved
terra.env Outdated Show resolved Hide resolved
andyneff and others added 10 commits June 8, 2020 13:30
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
Signed-off-by: Andy Neff <andy@visionsystemsinc.com>
@andyneff andyneff merged commit 009b13e into master Jun 10, 2020
@andyneff andyneff deleted the celery branch June 23, 2020 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants