From 558cd3984e00868a9c1aeedbc9d64e39d07c37fa Mon Sep 17 00:00:00 2001 From: omribarouch Date: Tue, 30 Jul 2024 11:31:33 +0300 Subject: [PATCH 1/4] flush logs on signal interrupt --- port_ocean/log/logger_setup.py | 6 +++++- port_ocean/ocean.py | 4 ++-- port_ocean/run.py | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/port_ocean/log/logger_setup.py b/port_ocean/log/logger_setup.py index 9dbf7c1f03..789cbfe729 100644 --- a/port_ocean/log/logger_setup.py +++ b/port_ocean/log/logger_setup.py @@ -9,6 +9,7 @@ from port_ocean.config.settings import LogLevelType from port_ocean.log.handlers import HTTPMemoryHandler from port_ocean.log.sensetive import sensitive_log_filter +from port_ocean.utils.signal import signal_handler def setup_logger(level: LogLevelType, enable_http_handler: bool) -> None: @@ -53,7 +54,10 @@ def _http_loguru_handler(level: LogLevelType) -> None: ) logger.configure(patcher=exception_deserializer) - queue_listener = QueueListener(queue, HTTPMemoryHandler()) + http_memory_handler = HTTPMemoryHandler() + signal_handler.register(http_memory_handler.flush) + + queue_listener = QueueListener(queue, http_memory_handler) queue_listener.start() diff --git a/port_ocean/ocean.py b/port_ocean/ocean.py index bb9b2556a9..7dc4655193 100644 --- a/port_ocean/ocean.py +++ b/port_ocean/ocean.py @@ -97,14 +97,14 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: @asynccontextmanager async def lifecycle(_: FastAPI) -> AsyncIterator[None]: try: - init_signal_handler() await self.integration.start() await self._setup_scheduled_resync() yield None - signal_handler.exit() except Exception: logger.exception("Integration had a fatal error. Shutting down.") sys.exit("Server stopped") + finally: + signal_handler.exit() self.fast_api_app.router.lifespan_context = lifecycle await self.fast_api_app(scope, receive, send) diff --git a/port_ocean/run.py b/port_ocean/run.py index 0c683fbbfd..3ec4262f3f 100644 --- a/port_ocean/run.py +++ b/port_ocean/run.py @@ -13,6 +13,7 @@ from port_ocean.log.logger_setup import setup_logger from port_ocean.ocean import Ocean from port_ocean.utils.misc import get_spec_file, load_module +from port_ocean.utils.signal import init_signal_handler def _get_default_config_factory() -> None | Type[BaseModel]: @@ -33,6 +34,7 @@ def run( ) -> None: application_settings = ApplicationSettings(log_level=log_level, port=port) + init_signal_handler() setup_logger( application_settings.log_level, enable_http_handler=application_settings.enable_http_logging, From 99792ac1f2425411c3fd985ee298049defde6dd4 Mon Sep 17 00:00:00 2001 From: omribarouch Date: Tue, 30 Jul 2024 12:10:31 +0300 Subject: [PATCH 2/4] bump version --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9ee3d4473..3a7c95083e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm +## 0.9.6 (2024-07-30) + +### Bug Fixes + +- Flush logs when receiving SIGTERM + + ## 0.9.5 (2024-07-23) ### Bug Fixes diff --git a/pyproject.toml b/pyproject.toml index ac091480ba..8423475a88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "port-ocean" -version = "0.9.5" +version = "0.9.6" description = "Port Ocean is a CLI tool for managing your Port projects." readme = "README.md" homepage = "https://app.getport.io" From a2f981d00a242014ea4f78ef04e2380f72718cf3 Mon Sep 17 00:00:00 2001 From: omribarouch Date: Tue, 30 Jul 2024 13:26:09 +0300 Subject: [PATCH 3/4] fixed lint --- port_ocean/ocean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port_ocean/ocean.py b/port_ocean/ocean.py index 7dc4655193..7020664308 100644 --- a/port_ocean/ocean.py +++ b/port_ocean/ocean.py @@ -22,7 +22,7 @@ from port_ocean.log.sensetive import sensitive_log_filter from port_ocean.middlewares import request_handler from port_ocean.utils.repeat import repeat_every -from port_ocean.utils.signal import signal_handler, init_signal_handler +from port_ocean.utils.signal import signal_handler from port_ocean.version import __integration_version__ From 99fbc46f625c60e2aac2cabf34ce1ba09ace4015 Mon Sep 17 00:00:00 2001 From: omribarouch Date: Tue, 30 Jul 2024 17:21:25 +0300 Subject: [PATCH 4/4] cr fixes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a7c95083e..26ba65fcab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Bug Fixes -- Flush logs when receiving SIGTERM +- Flush all remaining buffered logs when exiting application ## 0.9.5 (2024-07-23)