From 905195f4611a6ae0beebd75f1fac457dae83c998 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Fri, 11 Dec 2020 16:43:04 +0100 Subject: [PATCH 1/6] develop Define log.api_trafic config entry (False by default). --- OpenCast/__init__.py | 4 +++- OpenCast/config.py | 1 + OpenCast/infra/io/server.py | 7 +++++-- template/config.yml | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/OpenCast/__init__.py b/OpenCast/__init__.py index 3f07b20e..95704965 100644 --- a/OpenCast/__init__.py +++ b/OpenCast/__init__.py @@ -25,7 +25,9 @@ def run_server(logger, infra_facade): try: - infra_facade.server.start(settings["server.host"], settings["server.port"]) + infra_facade.server.start( + settings["server.host"], settings["server.port"], settings["log.api_trafic"] + ) except Exception as e: logger.error( "Server exception caught", error=e, traceback=traceback.format_exc() diff --git a/OpenCast/config.py b/OpenCast/config.py index db4b751e..2005bd16 100644 --- a/OpenCast/config.py +++ b/OpenCast/config.py @@ -19,6 +19,7 @@ default="INFO", is_in=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], ), + Validator("LOG.API_TRAFIC", default=False, is_in=[True, False]), Validator("SERVER.HOST", default="0.0.0.0"), Validator("SERVER.PORT", default=2020), Validator("DATABASE.FILE", default="opencast.db"), diff --git a/OpenCast/infra/io/server.py b/OpenCast/infra/io/server.py index 141379da..16fa18ad 100644 --- a/OpenCast/infra/io/server.py +++ b/OpenCast/infra/io/server.py @@ -31,10 +31,13 @@ def __init__(self, app): def route(self, method, route, handle): route = self.app.router.add_route(method, route, handle) - def start(self, host, port): + def start(self, host, port, log_trafic: bool): self._logger.info("Started", host=host, port=port) - web.run_app(self.app, host=host, port=port, access_log_class=AccessLogger) + options = {} + if log_trafic is True: + options["access_log_class"] = AccessLogger + web.run_app(self.app, host=host, port=port, **options) def make_web_socket(self): ws = web.WebSocketResponse() diff --git a/template/config.yml b/template/config.yml index 79e526ed..c714478c 100644 --- a/template/config.yml +++ b/template/config.yml @@ -1,7 +1,10 @@ default: log: # The level of the module's logger + # One of [CRITICAL, ERROR, WARNING, INFO, DEBUG] level: DEBUG + # Log requests/responses from the API + api_trafic: False server: # The IP from where the service is accessible From ae4c841b06da49ef5547f322649a6a6455b12d38 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 31 Mar 2021 09:47:41 +0200 Subject: [PATCH 2/6] Queue front when streaming a video --- OpenCast/app/workflow/player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenCast/app/workflow/player.py b/OpenCast/app/workflow/player.py index c7c68753..9c674474 100644 --- a/OpenCast/app/workflow/player.py +++ b/OpenCast/app/workflow/player.py @@ -185,7 +185,7 @@ def on_enter_QUEUEING(self): self._app_facade, self._data_facade, self.video, - queue_front=False, + queue_front=True, ) self._observe_start(workflow) From 1cb4edf1d4dbad279b256225fb0fcd3d992a34a5 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 31 Mar 2021 09:52:45 +0200 Subject: [PATCH 3/6] Ignore files generated by nvim --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 986f5f38..1ef1b2d6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ coverage.xml /.coverage /library /config.yml +.vim/ +tags From c6698d2be1993c42df35ed87207253dfb3e8d607 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 31 Mar 2021 13:02:52 +0200 Subject: [PATCH 4/6] Set log level to debug on the CI's tests. --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5051786c..b5e43d82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,8 @@ jobs: run: ./setup.sh --ci # - name: Test + env: + OPENCAST_LOG__LEVEL: DEBUG run: ./OpenCast.sh test all --coverage # - name: Coverage upload From 4df9bbcf24fa90bee5a1b341468c41756f01c845 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 31 Mar 2021 13:16:46 +0200 Subject: [PATCH 5/6] Inject real logger instead of mock in main tests --- test/unit/test_main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/test_main.py b/test/unit/test_main.py index 8152ff61..937c56ca 100644 --- a/test/unit/test_main.py +++ b/test/unit/test_main.py @@ -2,6 +2,7 @@ from test.shared.infra.facade_mock import InfraFacadeMock from test.util import TestCase from unittest.mock import Mock +import structlog from OpenCast import run_init_workflow, run_server from OpenCast.app.workflow.factory import WorkflowFactory @@ -10,20 +11,19 @@ class MainTest(TestCase): def test_run_server(self): - logger = Mock() + logger = structlog.get_logger("OpenCast") infra_facade = InfraFacadeMock() self.assertTrue(run_server(logger, infra_facade)) def test_run_server_with_exception(self): - logger = Mock() + logger = structlog.get_logger("OpenCast") infra_facade = InfraFacadeMock() - def start_server(): + def start_server(*args, **kwargs): raise Exception("") infra_facade.server.start.side_effect = start_server self.assertFalse(run_server(logger, infra_facade)) - logger.error.assert_called_once() def test_run_init_workflow_success(self): app_facade = AppFacadeMock() From c8739c885b8882bdc56145cb9999f6cef8337732 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 31 Mar 2021 13:28:03 +0200 Subject: [PATCH 6/6] Add config entry missing from the template file --- template/config.yml | 1 + test/unit/test_main.py | 1 + 2 files changed, 2 insertions(+) diff --git a/template/config.yml b/template/config.yml index c714478c..9262be30 100644 --- a/template/config.yml +++ b/template/config.yml @@ -36,3 +36,4 @@ default: testing: log: level: CRITICAL + api_trafic: False diff --git a/test/unit/test_main.py b/test/unit/test_main.py index 937c56ca..2160539d 100644 --- a/test/unit/test_main.py +++ b/test/unit/test_main.py @@ -2,6 +2,7 @@ from test.shared.infra.facade_mock import InfraFacadeMock from test.util import TestCase from unittest.mock import Mock + import structlog from OpenCast import run_init_workflow, run_server