Skip to content

Commit f7c7f5d

Browse files
committed
@sanderegg review: renames
1 parent 2a33aa9 commit f7c7f5d

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

services/catalog/src/simcore_service_catalog/core/application.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
from servicelib.fastapi.prometheus_instrumentation import (
99
initialize_prometheus_instrumentation,
1010
)
11+
from servicelib.fastapi.tracing import initialize_tracing
1112
from starlette.middleware.base import BaseHTTPMiddleware
1213

1314
from .._meta import (
1415
API_VERSION,
1516
API_VTAG,
17+
APP_NAME,
1618
PROJECT_NAME,
1719
SUMMARY,
1820
)
@@ -62,6 +64,9 @@ def create_app() -> FastAPI:
6264
app.state.settings = settings
6365

6466
# MIDDLEWARES
67+
if settings.CATALOG_TRACING:
68+
initialize_tracing(app, settings.CATALOG_TRACING, APP_NAME)
69+
6570
if settings.CATALOG_PROMETHEUS_INSTRUMENTATION_ENABLED:
6671
initialize_prometheus_instrumentation(app)
6772

services/catalog/src/simcore_service_catalog/core/events.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,64 +23,66 @@
2323
_logger = logging.getLogger(__name__)
2424

2525

26-
def flush_started_banner() -> None:
26+
def _flush_started_banner() -> None:
2727
# WARNING: this function is spied in the tests
2828
print(APP_STARTED_BANNER_MSG, flush=True) # noqa: T201
2929

3030

31-
def flush_finished_banner() -> None:
31+
def _flush_finished_banner() -> None:
32+
# WARNING: this function is spied in the tests
3233
print(APP_FINISHED_BANNER_MSG, flush=True) # noqa: T201
3334

3435

35-
async def _setup_app(app: FastAPI) -> AsyncIterator[State]:
36-
flush_started_banner()
36+
async def _banners_lifespan(_) -> AsyncIterator[State]:
37+
_flush_started_banner()
38+
yield {}
39+
_flush_finished_banner()
40+
3741

42+
async def _main_lifespan(app: FastAPI) -> AsyncIterator[State]:
3843
settings: ApplicationSettings = app.state.settings
3944

4045
yield {
4146
PostgresLifespanState.POSTGRES_SETTINGS: settings.CATALOG_POSTGRES,
4247
"prometheus_instrumentation_enabled": settings.CATALOG_PROMETHEUS_INSTRUMENTATION_ENABLED,
4348
}
4449

45-
flush_finished_banner()
4650

47-
48-
async def _setup_prometheus_instrumentation_adapter(
51+
async def _prometheus_instrumentation_lifespan(
4952
app: FastAPI, state: State
5053
) -> AsyncIterator[State]:
51-
enabled = state.get("prometheus_instrumentation_enabled", False)
52-
if enabled:
54+
if state.get("prometheus_instrumentation_enabled", False):
5355
async for prometheus_state in lifespan_prometheus_instrumentation(app):
5456
yield prometheus_state
5557

5658

5759
def create_app_lifespan():
58-
# app lifespan
59-
app_lifespan = LifespanManager()
60-
app_lifespan.add(_setup_app)
61-
6260
# WARNING: order matters
61+
app_lifespan = LifespanManager()
62+
app_lifespan.add(_main_lifespan)
6363

64-
# - postgres lifespan
64+
# - postgres
6565
app_lifespan.add(postgres_database_lifespan)
6666
app_lifespan.add(database_lifespan)
6767

68-
# - rabbitmq lifespan
68+
# - rabbitmq
6969
app_lifespan.add(rabbitmq_lifespan)
7070

71-
# - rpc api routes lifespan
71+
# - rpc api routes
7272
app_lifespan.add(rpc_api_lifespan)
7373

74-
# - director lifespan
74+
# - director
7575
app_lifespan.add(director_lifespan)
7676

77-
# - function services lifespan
77+
# - function services
7878
app_lifespan.add(function_services_lifespan)
7979

80-
# - background task lifespan
80+
# - background task
8181
app_lifespan.add(background_task_lifespan)
8282

83-
# - prometheus instrumentation lifespan
84-
app_lifespan.add(_setup_prometheus_instrumentation_adapter)
83+
# - prometheus instrumentation
84+
app_lifespan.add(_prometheus_instrumentation_lifespan)
85+
86+
app_lifespan.add(_banners_lifespan)
8587

8688
return app_lifespan

services/catalog/tests/unit/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def spy_app(mocker: MockerFixture) -> AppLifeSpanSpyTargets:
118118
return AppLifeSpanSpyTargets(
119119
on_startup=mocker.spy(
120120
simcore_service_catalog.core.events,
121-
"flush_started_banner",
121+
"_flush_started_banner",
122122
),
123123
on_shutdown=mocker.spy(
124124
simcore_service_catalog.core.events,
125-
"flush_finished_banner",
125+
"_flush_finished_banner",
126126
),
127127
)
128128

0 commit comments

Comments
 (0)