-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealthcheck.py
More file actions
30 lines (24 loc) · 999 Bytes
/
Copy pathhealthcheck.py
File metadata and controls
30 lines (24 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Container HEALTHCHECK: probe the Flight server with a trivial query."""
from __future__ import annotations
import os
import sys
import pyarrow.flight as flight
def main() -> int:
host = os.environ.get("FLIGHT_HOST", "127.0.0.1")
if host == "0.0.0.0":
host = "127.0.0.1"
port = os.environ.get("FLIGHT_PORT", "50051")
try:
client = flight.FlightClient(f"grpc://{host}:{port}")
descriptor = flight.FlightDescriptor.for_command(b"RETURN 1 AS ok")
info = client.get_flight_info(descriptor, options=flight.FlightCallOptions(timeout=4))
reader = client.do_get(
info.endpoints[0].ticket, options=flight.FlightCallOptions(timeout=4)
)
table = reader.read_all()
return 0 if table.num_rows >= 1 else 1
except Exception as e: # noqa: BLE001 -- healthcheck must not crash, just fail
print(f"unhealthy: {e}", file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())