Skip to content

Commit

Permalink
Add tests for log rotation in ray serve.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Pisoni <andreapiso@gmail.com>
  • Loading branch information
andreapiso committed Jan 22, 2023
1 parent 4f4e939 commit 4ff53d2
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions python/ray/serve/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
from ray._private.test_utils import wait_for_condition


def set_logging_config(monkeypatch, max_bytes, backup_count):
monkeypatch.setenv("RAY_ROTATION_MAX_BYTES", str(max_bytes))
monkeypatch.setenv("RAY_ROTATION_BACKUP_COUNT", str(backup_count))

def test_log_rotation_config(monkeypatch, ray_shutdown):
# This test should be executed before any test that uses
# the shared serve_instance, as environment variables
# for log rotation need to be set before ray.init
logger = logging.getLogger("ray.serve")
max_bytes = 100
backup_count = 3
set_logging_config(monkeypatch, max_bytes, backup_count)
ray.init(num_cpus=1)

@serve.deployment
class Handle:
def __call__(self):
handlers = logger.handlers
res = {}
for handler in handlers:
if isinstance(handler, logging.handlers.RotatingFileHandler):
res['max_bytes'] = handler.maxBytes
res['backup_count'] = handler.backupCount
return res

handle = serve.run(Handle.bind())
rotation_config = ray.get(handle.remote())
assert rotation_config['max_bytes'] == max_bytes
assert rotation_config['backup_count'] == backup_count



def test_handle_access_log(serve_instance):
name = "handler"

Expand Down

0 comments on commit 4ff53d2

Please sign in to comment.