crate-operator
crate-operator copied to clipboard
Replace sql-exporter with Kopf timer
At this point, we're deploying a sql-exporter sidecar container to the crate container. The sql-exporter provides a way to monitor the cluster availability. In the future, it might be a good idea to replace the sidecar container with a Kopf timer. Something along these lines:
@kopf.timer(API_GROUP, "v1", RESOURCE_CRATEDB, interval=15.0)
async def cluster_health(namespace: str, name: str, logger: logging.Logger, **kwargs):
core = CoreV1Api()
host = await get_host(core, namespace, name)
password = await get_system_user_password(namespace, name, core)
try:
async with get_connection(host, password) as conn:
async with conn.cursor(timeout=0.5) as cursor:
await cursor.execute("SELECT count(state) FROM sys.shards")
await cursor.fetchone()
except Exception:
prometheus._clusters_status.set({"namespace": namespace, "name": name}, 0)
logger.error("Cluster is not responsive")
else:
prometheus._clusters_status.set({"namespace": namespace, "name": name}, 1)
Depends on #45