Skip to content

Commit 2d6fef3

Browse files
committed
HEALTHCHECK_APPKEY
1 parent 577436a commit 2d6fef3

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

services/web/server/src/simcore_service_webserver/diagnostics/_healthcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def value(self) -> float:
5555
HEALTH_LAST_REQUESTS_AVG_LATENCY: Final = f"{__name__}.last_requests_avg_latency"
5656
HEALTH_MAX_AVG_RESP_LATENCY: Final = f"{__name__}.max_avg_response_latency"
5757
HEALTH_MAX_TASK_DELAY: Final = f"{__name__}.max_task_delay"
58-
HEALTH_PLUGIN_START_TIME: Final = f"{__name__}.plugin_start_time"
58+
HEALTH_PLUGIN_START_TIME: Final = web.AppKey("HEALTH_PLUGIN_START_TIME", time.time)
5959
HEALTH_START_SENSING_DELAY_SECS: Final = f"{__name__}.start_sensing_delay"
6060

6161

services/web/server/src/simcore_service_webserver/diagnostics/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from ..application_settings import get_application_settings
1111
from ..application_setup import ModuleCategory, app_setup_func
12-
from ..rest.healthcheck import HealthCheck
12+
from ..rest.healthcheck import HEALTHCHECK_APPKEY
1313
from ..rest.plugin import setup_rest
1414
from . import _handlers
1515
from ._healthcheck import (
@@ -52,7 +52,7 @@ def setup_diagnostics(app: web.Application):
5252
setup_monitoring(app)
5353

5454
if settings.DIAGNOSTICS_HEALTHCHECK_ENABLED:
55-
healthcheck: HealthCheck = app[HealthCheck.__name__]
55+
healthcheck = app[HEALTHCHECK_APPKEY]
5656
healthcheck.on_healthcheck.append(_on_healthcheck_async_adapter)
5757

5858
# adds other diagnostic routes: healthcheck, etc

services/web/server/src/simcore_service_webserver/rabbitmq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from .application_setup import ModuleCategory, app_setup_func
1919
from .rabbitmq_settings import RabbitSettings, get_plugin_settings
20-
from .rest.healthcheck import HealthCheck, HealthCheckError
20+
from .rest.healthcheck import HEALTHCHECK_APPKEY, HealthCheckError
2121

2222
_logger = logging.getLogger(__name__)
2323

@@ -46,7 +46,7 @@ async def _rabbitmq_client_cleanup_ctx(app: web.Application) -> AsyncIterator[No
4646
)
4747

4848
# injects healthcheck
49-
healthcheck: HealthCheck = app[HealthCheck.__name__]
49+
healthcheck = app[HEALTHCHECK_APPKEY]
5050
healthcheck.on_healthcheck.append(_on_healthcheck_async_adapter)
5151

5252
yield

services/web/server/src/simcore_service_webserver/rest/_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ..products import products_web
1515
from ..redis import get_redis_scheduled_maintenance_client
1616
from ..utils_aiohttp import envelope_json_response
17-
from .healthcheck import HealthCheck, HealthCheckError
17+
from .healthcheck import HEALTHCHECK_APPKEY, HealthCheckError
1818

1919
_logger = logging.getLogger(__name__)
2020

@@ -30,7 +30,7 @@ async def healthcheck_liveness_probe(request: web.Request):
3030
3131
SEE doc in healthcheck.py
3232
"""
33-
healthcheck: HealthCheck = request.app[HealthCheck.__name__]
33+
healthcheck = request.app[HEALTHCHECK_APPKEY]
3434

3535
try:
3636
# if slots append get too delayed, just timeout
@@ -53,7 +53,7 @@ async def healthcheck_readiness_probe(request: web.Request):
5353
SEE doc in healthcheck.py
5454
"""
5555

56-
healthcheck: HealthCheck = request.app[HealthCheck.__name__]
56+
healthcheck = request.app[HEALTHCHECK_APPKEY]
5757
app_info = healthcheck.get_app_info(request.app)
5858
# NOTE: do NOT run healthcheck here, just return info fast.
5959
return envelope_json_response(app_info)

services/web/server/src/simcore_service_webserver/rest/healthcheck.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Service healthcheck
1+
"""Service healthcheck
22
33
44
## Types of health checks
@@ -43,11 +43,10 @@
4343
Taken from https://docs.docker.com/engine/reference/builder/#healthcheck
4444
"""
4545

46-
4746
import asyncio
4847
import inspect
4948
from collections.abc import Awaitable, Callable
50-
from typing import TypeAlias
49+
from typing import Final, TypeAlias
5150

5251
from aiohttp import web
5352
from aiosignal import Signal
@@ -122,6 +121,9 @@ async def run(self, app: web.Application) -> HealthInfoDict:
122121
heath_report: HealthInfoDict = self.get_app_info(app)
123122
return heath_report
124123

125-
except asyncio.TimeoutError as err:
124+
except TimeoutError as err:
126125
msg = "Service is slowing down"
127126
raise HealthCheckError(msg) from err
127+
128+
129+
HEALTHCHECK_APPKEY: Final = web.AppKey("HEALTHCHECK_APPKEY", HealthCheck)

services/web/server/src/simcore_service_webserver/rest/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ..security.plugin import setup_security
2121
from . import _handlers
2222
from ._utils import get_openapi_specs_path
23-
from .healthcheck import HealthCheck
23+
from .healthcheck import HEALTHCHECK_APPKEY, HealthCheck
2424
from .settings import RestSettings, get_plugin_settings
2525

2626
_logger = logging.getLogger(__name__)
@@ -39,8 +39,8 @@ def setup_rest(app: web.Application):
3939

4040
spec_path = get_openapi_specs_path(api_version_dir=API_VTAG)
4141

42-
app[HealthCheck.__name__] = HealthCheck(app)
43-
_logger.debug("Setup %s", f"{app[HealthCheck.__name__]=}")
42+
app[HEALTHCHECK_APPKEY] = HealthCheck(app)
43+
_logger.debug("Setup %s", f"{app[HEALTHCHECK_APPKEY]=}")
4444

4545
# basic routes
4646
app.add_routes(_handlers.routes)

0 commit comments

Comments
 (0)