Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
31451c9
fix |
sanderegg Jul 7, 2025
2805704
async logger trials
sanderegg Jul 7, 2025
e861d0d
async logger
sanderegg Jul 8, 2025
41815e2
add repomix to ignore list
sanderegg Jul 8, 2025
3820a52
use same version
sanderegg Jul 8, 2025
8f06009
removed max queue
sanderegg Jul 8, 2025
5111d4c
initial
sanderegg Jul 8, 2025
03d05a5
too much
sanderegg Jul 8, 2025
d987930
simplify
sanderegg Jul 8, 2025
d3f87d1
refactor
sanderegg Jul 8, 2025
9244c37
cleanup
sanderegg Jul 8, 2025
70c5835
add test
sanderegg Jul 8, 2025
7efa167
this might be working
sanderegg Jul 8, 2025
9843048
cleanup
sanderegg Jul 8, 2025
9eef0e4
initial
sanderegg Jul 8, 2025
8f88d44
almost ready
sanderegg Jul 8, 2025
d58c88b
almost ready
sanderegg Jul 8, 2025
023bc57
use tenacity
sanderegg Jul 8, 2025
1b419b1
simplify
sanderegg Jul 8, 2025
d946a65
minor
sanderegg Jul 8, 2025
ccf5d33
minor
sanderegg Jul 8, 2025
716cfcd
minor
sanderegg Jul 8, 2025
3e242f2
print if UV is installed
sanderegg Jul 8, 2025
c4cdf2f
minor
sanderegg Jul 8, 2025
fcacc20
cleanup
sanderegg Jul 8, 2025
3430474
better integration
sanderegg Jul 8, 2025
dcebbc1
fix
sanderegg Jul 8, 2025
2594842
fix
sanderegg Jul 8, 2025
c6f8e11
rename
sanderegg Jul 9, 2025
fd6fbf8
clean
sanderegg Jul 9, 2025
b7134f3
clean
sanderegg Jul 9, 2025
c270e82
rename
sanderegg Jul 9, 2025
40cafe9
ensure we replace any handlers in the logger
sanderegg Jul 9, 2025
cce07aa
only change needed handler
sanderegg Jul 9, 2025
0964b1a
added a autouse fixture to fix tests when using caplog
sanderegg Jul 9, 2025
80afced
ensure all loggers propagate
sanderegg Jul 9, 2025
ea564b3
done
sanderegg Jul 9, 2025
2df7185
cleanup
sanderegg Jul 9, 2025
e9a37da
simplify
sanderegg Jul 9, 2025
652d04f
autoscaling
sanderegg Jul 9, 2025
0ae5828
agent
sanderegg Jul 9, 2025
47dcfe9
apiserver
sanderegg Jul 9, 2025
fce15f7
catalog
sanderegg Jul 9, 2025
b439f0e
clusters-keeper
sanderegg Jul 9, 2025
c7e00d6
datcore and dask-sidecar
sanderegg Jul 9, 2025
78265ce
director-v2
sanderegg Jul 9, 2025
ce03687
director
sanderegg Jul 9, 2025
ef55858
dynamic-scheduler
sanderegg Jul 9, 2025
deb9fa4
dynamic-sidecar
sanderegg Jul 9, 2025
b5509d0
efs
sanderegg Jul 9, 2025
093f4c4
invitations
sanderegg Jul 9, 2025
0f4eda1
notifications
sanderegg Jul 9, 2025
e610fd1
payments
sanderegg Jul 9, 2025
3dca72a
resources
sanderegg Jul 9, 2025
25496b1
resources
sanderegg Jul 9, 2025
cf97990
storage
sanderegg Jul 9, 2025
5389664
noisy
sanderegg Jul 9, 2025
020a1d7
ensure the correct loglevel is returned
sanderegg Jul 9, 2025
4871eb4
re working application startup
sanderegg Jul 9, 2025
8d8649d
try removing stuff
sanderegg Jul 9, 2025
1f42def
mypy
sanderegg Jul 9, 2025
7e375dd
ensure create_app_ is not removed
sanderegg Jul 9, 2025
4b6105a
change entrypoint
sanderegg Jul 9, 2025
94e762c
change boot script
sanderegg Jul 9, 2025
cd09591
first initial non-blocking in catalog
sanderegg Jul 10, 2025
668a16f
clean
sanderegg Jul 10, 2025
c395d7c
catalog uses async logger
sanderegg Jul 10, 2025
327549d
no need for async
sanderegg Jul 10, 2025
d24dc1c
moved logging lifespan in servicelib
sanderegg Jul 10, 2025
5c0e2bf
rename
sanderegg Jul 10, 2025
011da28
dv-2 now also uses the async logger
sanderegg Jul 10, 2025
c7c50a8
missing ENV
sanderegg Jul 10, 2025
ddc62a6
created shutdown event
sanderegg Jul 10, 2025
61f059a
storage uses async loggers
sanderegg Jul 10, 2025
68a0b6a
correct setup of tracing
sanderegg Jul 10, 2025
9dc0f18
director now has async logger too
sanderegg Jul 10, 2025
2e3a070
changed boot scripts
sanderegg Jul 10, 2025
eefcc3e
agent
sanderegg Jul 10, 2025
29eee79
api-server
sanderegg Jul 10, 2025
11dbf96
autoscaling
sanderegg Jul 10, 2025
530472d
clusters-keeper
sanderegg Jul 10, 2025
3c70f80
datcore-adapter
sanderegg Jul 10, 2025
f610b1a
dynamic-scheduler
sanderegg Jul 10, 2025
79ac626
dynamic-scheduler
sanderegg Jul 10, 2025
0de3c63
dynamic-sidecar
sanderegg Jul 10, 2025
5fa9a1e
relative imports
sanderegg Jul 10, 2025
a1ed743
efs
sanderegg Jul 10, 2025
7f27fca
invitations
sanderegg Jul 10, 2025
9775a8f
notifications
sanderegg Jul 10, 2025
1179058
payments
sanderegg Jul 10, 2025
4ef2c72
rut
sanderegg Jul 10, 2025
555a87c
fix mypy
sanderegg Jul 10, 2025
b17ccdb
fix tests
sanderegg Jul 10, 2025
a82f485
use app factory
sanderegg Jul 10, 2025
f14cabd
hmm
sanderegg Jul 10, 2025
628b50e
docs
sanderegg Jul 10, 2025
04a2d3b
sonar
sanderegg Jul 10, 2025
10e660d
dv-2
sanderegg Jul 10, 2025
dcec94d
fix tests
sanderegg Jul 10, 2025
83f830a
bug fix
sanderegg Jul 10, 2025
43c334c
brought fixture in
sanderegg Jul 10, 2025
dc0223e
align
sanderegg Jul 10, 2025
5a5fced
shellcheck
sanderegg Jul 10, 2025
575ce89
app_factory
sanderegg Jul 10, 2025
ed3894b
adjust fixture
sanderegg Jul 10, 2025
7486db2
reverted
sanderegg Jul 10, 2025
59b20d7
add more filtering
sanderegg Jul 10, 2025
55aca25
info
sanderegg Jul 10, 2025
6800114
fixed test
sanderegg Jul 10, 2025
c4e234d
simplify fixture
sanderegg Jul 10, 2025
3ec8bc7
simplify fixture
sanderegg Jul 10, 2025
0631674
add some docs
sanderegg Jul 10, 2025
72f0b73
cleanup
sanderegg Jul 10, 2025
395e99b
missing dep
sanderegg Jul 10, 2025
ce18732
@GitHK review: rename
sanderegg Jul 11, 2025
8cb3c06
@GitHK review: rename
sanderegg Jul 11, 2025
15914d5
reviews
sanderegg Jul 14, 2025
94e79a2
reviews
sanderegg Jul 14, 2025
ecc9ab0
@pcrespov review: renamed init_app to create_app repo-wide
sanderegg Jul 14, 2025
9d584fa
added docs
sanderegg Jul 14, 2025
7ed8fe5
cleanup
sanderegg Jul 14, 2025
8a014e9
cleanup
sanderegg Jul 14, 2025
f053156
re-use common patterns
sanderegg Jul 14, 2025
1667911
make it same
sanderegg Jul 14, 2025
d7b3caf
cleanup
sanderegg Jul 14, 2025
a7fb29b
cleanup
sanderegg Jul 14, 2025
1d141ef
renaming
sanderegg Jul 14, 2025
fae4400
renaming
sanderegg Jul 14, 2025
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
2 changes: 1 addition & 1 deletion .env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ INVITATIONS_USERNAME=admin
INVITATIONS_TRACING={}

LOG_FORMAT_LOCAL_DEV_ENABLED=1
LOG_FILTER_MAPPING='{"gunicorn.access":[" /v0/ ", " /v0/health "], "uvicorn.access":[" / "]}'
LOG_FILTER_MAPPING='{"gunicorn.access":[" /v0/ ", " /v0/health "], "uvicorn.access":[" / ", " /v0/ "]}'

NOTIFICATIONS_LOGLEVEL=INFO
NOTIFICATIONS_TRACING={}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ locust_report/
nosetests.xml
test_failures/


# Translations
*.mo
*.pot
Expand Down Expand Up @@ -182,3 +181,6 @@ tests/public-api/osparc_python_wheels/*

# osparc-config repo files
repo.config

# repomix
.repomix/*
1 change: 1 addition & 0 deletions packages/aws-library/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"pytest_simcore.aws_ssm_service",
"pytest_simcore.environment_configs",
"pytest_simcore.file_extra",
"pytest_simcore.logging",
"pytest_simcore.pydantic_models",
"pytest_simcore.pytest_global_environs",
"pytest_simcore.repository_paths",
Expand Down
1 change: 1 addition & 0 deletions packages/celery-library/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"pytest_simcore.docker_compose",
"pytest_simcore.docker_swarm",
"pytest_simcore.environment_configs",
"pytest_simcore.logging",
"pytest_simcore.rabbit_service",
"pytest_simcore.redis_service",
"pytest_simcore.repository_paths",
Expand Down
2 changes: 1 addition & 1 deletion packages/notifications-library/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def product_data(
return ProductData( # type: ignore
product_name=product_name,
display_name=product["display_name"],
vendor_display_inline=f"{vendor.get('name','')}, {vendor.get('address','')}",
vendor_display_inline=f"{vendor.get('name', '')}, {vendor.get('address', '')}",
support_email=product["support_email"],
homepage_url=vendor.get("url"),
ui=product_ui,
Expand Down
42 changes: 42 additions & 0 deletions packages/pytest-simcore/src/pytest_simcore/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# In conftest.py or test_logging_utils.py
import contextlib
import logging
from collections.abc import Iterator
from contextlib import contextmanager

import pytest
from pytest_mock import MockerFixture
from servicelib.logging_utils import async_loggers


@pytest.fixture(autouse=True)
def preserve_caplog_for_async_logging(mocker: MockerFixture) -> None:
# Patch async_loggers to preserve caplog handlers,
# and pytest logs in general as pytest captures logs in a special way
# that is not compatible with the queue handler used in async logging.
original_setup = async_loggers

@contextmanager
def patched_async_loggers(**kwargs) -> Iterator[None]:
# Find caplog's handler in root logger
root_logger = logging.getLogger()
caplog_handlers = [
h for h in root_logger.handlers if "LogCaptureHandler" in f"{type(h)}"
]

with original_setup(**kwargs):
# After setup, restore caplog handlers alongside queue handler
for handler in caplog_handlers:
if handler not in root_logger.handlers:
root_logger.addHandler(handler)
yield

methods_to_patch = [
"servicelib.logging_utils.async_loggers",
"servicelib.fastapi.logging_lifespan.async_loggers",
"tests.test_logging_utils.async_loggers",
]
for method in methods_to_patch:
with contextlib.suppress(AttributeError, ModuleNotFoundError):
Copy link
Member

Choose a reason for hiding this comment

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

what is this suppress for? shouldnt will allow to fail if e.g. we change the name of themodules etc?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I need to rework that one. I tried to cover all cases, but I see that this might backfire. will think about it further

# Patch the method to use our patched version
mocker.patch(method, patched_async_loggers)
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import contextlib
from collections.abc import Iterator
from typing import Final
from collections.abc import AsyncIterator, Callable, Iterator
from typing import Final, TypeAlias

from common_library.errors_classes import OsparcErrorMixin
from fastapi import FastAPI
from fastapi_lifespan_manager import State

from ..logging_utils import log_context

Lifespan: TypeAlias = Callable[[FastAPI], AsyncIterator[None]]


class LifespanError(OsparcErrorMixin, RuntimeError): ...

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import logging
from collections.abc import AsyncIterator, Awaitable, Callable
from contextlib import AsyncExitStack

from fastapi import FastAPI
from settings_library.tracing import TracingSettings

from ..logging_utils import (
LogLevelInt,
async_loggers,
log_context,
)
from ..logging_utils_filtering import LoggerName, MessageSubstring
from .lifespan_utils import Lifespan

_logger = logging.getLogger(__name__)


def create_logging_lifespan(
*,
log_format_local_dev_enabled: bool,
logger_filter_mapping: dict[LoggerName, list[MessageSubstring]],
tracing_settings: TracingSettings | None,
log_base_level: LogLevelInt,
noisy_loggers: tuple[str, ...] | None,
) -> Lifespan:
"""Returns a FastAPI-compatible lifespan handler to set up async logging."""
exit_stack = AsyncExitStack()
exit_stack.enter_context(
async_loggers(
log_base_level=log_base_level,
noisy_loggers=noisy_loggers,
log_format_local_dev_enabled=log_format_local_dev_enabled,
logger_filter_mapping=logger_filter_mapping,
tracing_settings=tracing_settings,
)
)

async def _logging_lifespan(app: FastAPI) -> AsyncIterator[None]:
assert app is not None, "app must be provided"
yield
with log_context(_logger, logging.INFO, "Re-enable Blocking logger"):
await exit_stack.aclose()

return _logging_lifespan


def create_logging_shutdown_event(
*,
log_format_local_dev_enabled: bool,
logger_filter_mapping: dict[LoggerName, list[MessageSubstring]],
tracing_settings: TracingSettings | None,
log_base_level: LogLevelInt,
noisy_loggers: tuple[str, ...] | None,
) -> Callable[[], Awaitable[None]]:
"""retruns a fastapi-compatible shutdown event handler to be used with old style lifespan
handlers. This is useful for applications that do not use the new async lifespan
handlers introduced in fastapi 0.100.0.

Note: This function is for backwards compatibility only and will be removed in the future.
setup_logging_lifespan should be used instead for new style lifespan handlers.
"""
exit_stack = AsyncExitStack()
exit_stack.enter_context(
async_loggers(
log_base_level=log_base_level,
noisy_loggers=noisy_loggers,
log_format_local_dev_enabled=log_format_local_dev_enabled,
logger_filter_mapping=logger_filter_mapping,
tracing_settings=tracing_settings,
)
)

async def _on_shutdown_event() -> None:
with log_context(_logger, logging.INFO, "Re-enable Blocking logger"):
await exit_stack.aclose()

return _on_shutdown_event
Loading
Loading