Skip to content

Commit bc6e70b

Browse files
authored
[DOP-24616] Add healthcheck endpoint for consumer (#195)
* [DOP-24616] add healtcheck endpoint for consumer * [DOP-24616] add healtcheck endpoint for consumer * [DOP-24616] update lines in docs
1 parent d9cce6b commit bc6e70b

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

.env.docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
88
KAFKA_CFG_NODE_ID=0
99
KAFKA_CFG_PROCESS_ROLES=controller,broker
1010
KAFKA_CFG_LISTENERS=DOCKER://:9092,LOCALHOST://:9093,CONTROLLER://:9094,INTERBROKER://:9095
11-
KAFKA_CFG_ADVERTISED_LISTENERS=DOCKER://kafka:9092,LOCALHOST://localhost:9093,INTERBROKER://broker:9095
11+
KAFKA_CFG_ADVERTISED_LISTENERS=DOCKER://broker:9092,LOCALHOST://localhost:9093,INTERBROKER://broker:9095
1212
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,INTERBROKER:PLAINTEXT,DOCKER:SASL_PLAINTEXT,LOCALHOST:SASL_PLAINTEXT
1313
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@broker:9094
1414
KAFKA_CFG_INTER_BROKER_LISTENER_NAME=DOCKER

data_rentgen/consumer/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
import logging
55
from contextlib import asynccontextmanager
6+
from typing import Any
67

78
import anyio
89
from fast_depends import dependency_provider
910
from faststream import ContextRepo, FastStream
1011
from faststream._compat import ExceptionGroup
12+
from faststream.asgi import AsgiFastStream, AsgiResponse, get
1113
from faststream.kafka import KafkaBroker
1214
from sqlalchemy.ext.asyncio import AsyncSession
1315

@@ -20,6 +22,11 @@
2022
logger = logging.getLogger(__name__)
2123

2224

25+
@get # type: ignore[arg-type]
26+
async def liveness(scope: dict[str, Any]) -> AsgiResponse:
27+
return AsgiResponse(b"", status_code=204)
28+
29+
2330
def broker_factory(settings: ConsumerApplicationSettings) -> KafkaBroker:
2431
broker = KafkaBroker(
2532
bootstrap_servers=settings.kafka.bootstrap_servers,
@@ -43,7 +50,7 @@ def broker_factory(settings: ConsumerApplicationSettings) -> KafkaBroker:
4350
return broker
4451

4552

46-
def application_factory(settings: ConsumerApplicationSettings) -> FastStream:
53+
def application_factory(settings: ConsumerApplicationSettings) -> AsgiFastStream:
4754
@asynccontextmanager
4855
async def security_lifespan(context: ContextRepo):
4956
try:
@@ -66,7 +73,7 @@ async def security_lifespan(context: ContextRepo):
6673
description="Data.Rentgen is a nextgen DataLineage service",
6774
version=data_rentgen.__version__,
6875
logger=logger,
69-
)
76+
).as_asgi(asgi_routes=[("/internal/healthcheck/liveness", liveness)])
7077

7178

7279
def get_application():

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ services:
5959
command: python -m data_rentgen.consumer
6060
restart: unless-stopped
6161
env_file: .env.docker
62+
healthcheck:
63+
test: [CMD-SHELL, curl -f http://localhost:8000/internal/healthcheck/liveness]
64+
interval: 30s
65+
timeout: 5s
66+
retries: 3
67+
start_period: 5s
6268
depends_on:
6369
broker:
6470
condition: service_healthy

docs/reference/consumer/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ With docker
2727
.. dropdown:: ``docker-compose.yml``
2828

2929
.. literalinclude:: ../../../docker-compose.yml
30-
:emphasize-lines: 57-66
30+
:emphasize-lines: 57-72
3131

3232
.. dropdown:: ``.env.docker``
3333

docs/reference/database/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ With Docker
6464
.. dropdown:: ``docker-compose.yml``
6565

6666
.. literalinclude:: ../../../docker-compose.yml
67-
:emphasize-lines: 1-15,102-103
67+
:emphasize-lines: 1-15,108-110
6868

6969
.. dropdown:: ``.env.docker``
7070

docs/reference/frontend/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ With Docker
2828
.. dropdown:: ``docker-compose.yml``
2929

3030
.. literalinclude:: ../../../docker-compose.yml
31-
:emphasize-lines: 86-100
31+
:emphasize-lines: 92-106
3232

3333
.. dropdown:: ``.env.docker``
3434

0 commit comments

Comments
 (0)