From 1e257e901864c3bd88f76a3d6454a78f4a113dc8 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Wed, 31 Dec 2025 15:28:17 +0300 Subject: [PATCH] remove faststream healthcheck additional checker --- docs/introduction/configuration.md | 6 ------ .../bootstrappers/faststream_bootstrapper.py | 8 +------- tests/test_faststream_bootstrap.py | 16 ---------------- 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/docs/introduction/configuration.md b/docs/introduction/configuration.md index 99a434d..904de41 100644 --- a/docs/introduction/configuration.md +++ b/docs/introduction/configuration.md @@ -127,9 +127,3 @@ Additional params: - `health_checks_path` - `health_checks_include_in_schema` - -### Health checks FastStream - -Additional params: - -- `health_checks_additional_checker` - additional coroutine to check service health diff --git a/lite_bootstrap/bootstrappers/faststream_bootstrapper.py b/lite_bootstrap/bootstrappers/faststream_bootstrapper.py index 8bacbd9..f45ae30 100644 --- a/lite_bootstrap/bootstrappers/faststream_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/faststream_bootstrapper.py @@ -55,7 +55,6 @@ class FastStreamConfig(HealthChecksConfig, LoggingConfig, OpentelemetryConfig, P application: "AsgiFastStream" = dataclasses.field(default_factory=lambda: AsgiFastStream()) opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = None - health_checks_additional_checker: typing.Callable[[], typing.Coroutine[bool, typing.Any, typing.Any]] | None = None @dataclasses.dataclass(kw_only=True, slots=True, frozen=True) @@ -84,12 +83,7 @@ async def _define_health_status(self) -> bool: if not self.bootstrap_config.application or not self.bootstrap_config.application.broker: return False - additional_check = ( - await self.bootstrap_config.health_checks_additional_checker() - if self.bootstrap_config.health_checks_additional_checker - else True - ) - return additional_check and await self.bootstrap_config.application.broker.ping(timeout=5) + return await self.bootstrap_config.application.broker.ping(timeout=5) @dataclasses.dataclass(kw_only=True, frozen=True) diff --git a/tests/test_faststream_bootstrap.py b/tests/test_faststream_bootstrap.py index ffef06e..3f999e8 100644 --- a/tests/test_faststream_bootstrap.py +++ b/tests/test_faststream_bootstrap.py @@ -24,7 +24,6 @@ def broker() -> RedisBroker: def build_faststream_config( broker: BrokerUsecase[typing.Any, typing.Any] | None = None, - health_checks_additional_checker: typing.Callable[[], typing.Coroutine[bool, typing.Any, typing.Any]] | None = None, ) -> FastStreamConfig: return FastStreamConfig( service_name="microservice", @@ -40,7 +39,6 @@ def build_faststream_config( sentry_dsn="https://testdsn@localhost/1", health_checks_path="/custom-health/", logging_buffer_capacity=0, - health_checks_additional_checker=health_checks_additional_checker, application=faststream.asgi.AsgiFastStream( broker, asyncapi_path=faststream.asgi.AsyncAPIRoute("/docs/"), @@ -86,20 +84,6 @@ async def test_faststream_bootstrap_health_check_wo_broker() -> None: assert response.text == "Service is unhealthy" -async def test_faststream_bootstrap_additional_health_checker(broker: RedisBroker) -> None: - async def custom_checker() -> bool: - return False - - bootstrap_config = build_faststream_config(broker=broker, health_checks_additional_checker=custom_checker) - bootstrapper = FastStreamBootstrapper(bootstrap_config=bootstrap_config) - application = bootstrapper.bootstrap() - test_client = TestClient(app=application) - - response = test_client.get(bootstrap_config.health_checks_path) - assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR - assert response.text == "Service is unhealthy" - - def test_faststream_bootstrapper_not_ready() -> None: with emulate_package_missing("faststream"), pytest.raises(RuntimeError, match="faststream is not installed"): FastStreamBootstrapper(bootstrap_config=FastStreamConfig(application=faststream.asgi.AsgiFastStream()))