Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 0 additions & 6 deletions docs/introduction/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 1 addition & 7 deletions lite_bootstrap/bootstrappers/faststream_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions tests/test_faststream_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/"),
Expand Down Expand Up @@ -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()))
Expand Down
Loading