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

Flush logs on signal interrupt #847

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.9.6 (2024-07-30)

### Bug Fixes

- Flush logs when receiving SIGTERM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit



## 0.9.5 (2024-07-23)

### Bug Fixes
Expand Down
6 changes: 5 additions & 1 deletion port_ocean/log/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()


Expand Down
6 changes: 3 additions & 3 deletions port_ocean/ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__


Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions port_ocean/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down