From 6bdd9e0fbfa26896fae46f204d5d1cced154d0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Fri, 2 Dec 2022 23:03:58 +0200 Subject: [PATCH] Add some logging for healthchecks --- camdetect.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/camdetect.py b/camdetect.py index e7972d2..79abad5 100755 --- a/camdetect.py +++ b/camdetect.py @@ -500,25 +500,15 @@ async def stream_wrapper(request): @app.route("/readyz") async def ready_check(request): - if app.ctx.mask is None: - return response.text("Not enough frames", status=503) - return response.text("OK") - - -@app.route("/healthz") -async def health_check(request): - if app.ctx.mask is None: - return response.text("Not enough frames", status=503) - - # Check if Mongo is accessible + logger.info("Testing if Mongo is accessible") try: async for i in app.ctx.coll.find().limit(1): break except pymongo.errors.ServerSelectionTimeoutError: return response.text("MongoDB server selection timeout", status=503) - # Check if S3 is accessible session = aioboto3.Session() + logger.info("Testing if S3 is writable") async with session.resource("s3", aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, @@ -527,6 +517,16 @@ async def health_check(request): await bucket.upload_fileobj(io.BytesIO(b"test"), "test") return response.text("OK") + print("Checking if there are any frames received") + if app.ctx.mask is None: + return response.text("Not enough frames", status=503) + + +@app.route("/healthz") +async def health_check(request): + if app.ctx.mask is None: + return response.text("Not enough frames", status=503) + @app.route("/event") async def wrapper_stream_event(request):