Health Checks¶
broker_health_check¶
broker_health_check(broker: HealthProvider | Any, config: HealthCheckConfig | None = None, management_client: Any = None) -> BrokerHealthResult
¶
Check broker health status (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker
|
HealthProvider | Any
|
A broker implementing :class: |
required |
config
|
HealthCheckConfig | None
|
Optional :class: |
None
|
management_client
|
Any
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
BrokerHealthResult
|
BrokerHealthResult with status HEALTHY (started, connected, not |
BrokerHealthResult
|
blocked, all consumers active), DEGRADED (started but connection |
BrokerHealthResult
|
blocked (L15), consumers missing, pool backlog high, or — with |
BrokerHealthResult
|
|
BrokerHealthResult
|
unhealthy), or UNHEALTHY (not started or not connected). |
Source code in src/rabbitkit/health.py
broker_liveness / broker_readiness¶
broker_liveness(broker: HealthProvider | Any, wedged_timeout: float = 60.0) -> bool
¶
Liveness probe — is the broker process alive and not hard-wedged?
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker
|
HealthProvider | Any
|
A broker implementing :class: |
required |
wedged_timeout
|
float
|
Seconds without a heartbeat before liveness fails. |
60.0
|
Liveness fails when:
- the broker is not started (
_started/startedFalse/absent), OR - an explicit
_wedgedflag is set toTrue(transports/brokers may set this on a hard fault), OR - a
last_heartbeatis present andnow - last_heartbeat > wedged_timeout(a heartbeat was recorded via :func:mark_heartbeatbut has gone stale, meaning the I/O loop is wedged).
A transient broker/transport disconnect is not a liveness failure: the
process is still running and can recover. Use :func:broker_readiness to
decide whether to route traffic.
When no last_heartbeat attribute exists, liveness falls back to the
_started / _wedged checks only (backwards compatible).
Source code in src/rabbitkit/health.py
broker_readiness(broker: HealthProvider | Any, config: HealthCheckConfig | None = None, management_client: Any = None) -> bool
¶
Readiness probe — is the broker ready to serve traffic right now?
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker
|
HealthProvider | Any
|
A broker implementing :class: |
required |
config
|
HealthCheckConfig | None
|
Optional :class: |
None
|
management_client
|
Any
|
Optional :class: |
None
|
Requires: health check not UNHEALTHY, transport connected, connection
not blocked by broker flow control (L15), and every registered route
has an active (live) consumer. Use this for load-balancer / ingress
gating; use :func:broker_liveness for restart decisions.
Source code in src/rabbitkit/health.py
broker_liveness_async(broker: HealthProvider | Any, wedged_timeout: float = 60.0) -> bool
async
¶
Async variant of :func:broker_liveness.
broker_readiness_async(broker: HealthProvider | Any, config: HealthCheckConfig | None = None, management_client: Any = None) -> bool
async
¶
Async variant of :func:broker_readiness.
Uses :func:broker_health_check_async (management_client.health_check_async())
rather than delegating to the sync broker_readiness — the sync
management check makes a blocking network call, which must not run on
the event loop.
Source code in src/rabbitkit/health.py
HealthStatus / BrokerHealthResult¶
HealthStatus
¶
BrokerHealthResult
dataclass
¶
Result of a broker health check.
Source code in src/rabbitkit/health.py
HealthProvider Protocol¶
HealthProvider
¶
Bases: Protocol
Broker health surface — typed alternative to private-attribute probing.
Brokers that expose these read-only properties satisfy the protocol and
:mod:rabbitkit.health will use them directly. Brokers that still use
private attributes (_started, _transport, ...) are supported via
the deprecation fallback in :func:rabbitkit.health._get.
Source code in src/rabbitkit/core/protocols.py
Attributes¶
started: bool
property
¶
Whether the broker has been started.
connected: bool
property
¶
Whether the underlying transport is connected.
consumer_count: int
property
¶
Number of routes with an active (live) consumer.
route_count: int
property
¶
Total number of registered routes.
worker_pool_pending: int
property
¶
Current worker-pool backlog (pending tasks).
last_heartbeat: float | None
property
¶
Last liveness heartbeat (monotonic seconds), or None.
HealthWatcher¶
Opt-in push-style health notifications with debounced transitions. On Kubernetes keep probes primary; this is for bare metal/VMs and direct pager/webhook wiring.
HealthWatcher
¶
Opt-in push-style health notifications (sync, daemon-thread poller).
Polls :func:broker_health_check every interval seconds and fires
on_change(old, new, result) when the status transitions -- but only
after debounce consecutive identical readings, so a single flapping
poll never pages anyone. Callback exceptions are logged, never raised,
and never stall the loop.
Positioning: for deployments that aren't (only) Kubernetes -- bare
metal, VMs, direct pager/webhook wiring. On k8s, keep
:func:broker_liveness/:func:broker_readiness probes as the primary
signal; this watcher complements, never replaces, them.
When collector is given (any MetricsCollector with set_gauge),
every poll also emits a rabbitkit_health_state gauge
(0 healthy / 1 degraded / 2 unhealthy), so Prometheus users get a state
series without writing a callback.
clock and sleeper are injectable for tests (no wall-clock sleeps in the test suite -- a hard-won deflaking lesson).
Source code in src/rabbitkit/health.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
Attributes¶
current_status: HealthStatus | None
property
¶
Last debounce-confirmed status (None until the first confirmation).
Methods:¶
start() -> None
¶
Start the daemon poller thread. Idempotent.
Source code in src/rabbitkit/health.py
stop(timeout: float = 5.0) -> None
¶
Stop the poller (bounded join). Idempotent.
Source code in src/rabbitkit/health.py
AsyncHealthWatcher
¶
Bases: HealthWatcher
Async variant of :class:HealthWatcher — an asyncio task instead of
a thread, and the management check (if any) awaited via
:func:broker_health_check_async so it never blocks the event loop.