From 1aef09c5ed3653e0938ca092c6498a4b3b61d730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 19 Oct 2020 22:29:20 +0200 Subject: [PATCH 1/4] add sentry tracing --- storage_service/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage_service/app.py b/storage_service/app.py index 7773eea..3725402 100644 --- a/storage_service/app.py +++ b/storage_service/app.py @@ -17,9 +17,11 @@ if SENTRY_DSN: sentry_sdk.init( dsn=SENTRY_DSN, integrations=[FlaskIntegration()], + traces_sample_rate=1.0, send_default_pii=True, release=os.environ.get('RELEASE_ID', 'test'), - environment=os.environ.get('RELEASEMODE', 'dev') + environment=os.environ.get('RELEASEMODE', 'dev'), + _experiments={"auto_enabling_integrations": True} ) # create flask app From ddee056c25670b3f95a724a065d8bd4a5a71328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 19 Nov 2020 01:49:40 +0100 Subject: [PATCH 2/4] add health endpoint --- requirements.txt | 3 ++- storage_service/app.py | 8 +++++++- storage_service/utils/__init__.py | 1 + storage_service/utils/healthchecks.py | 23 +++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 storage_service/utils/healthchecks.py diff --git a/requirements.txt b/requirements.txt index 21fa9bc..62de5db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ marshmallow Flask-Classful gunicorn sentry_sdk -flask_minio \ No newline at end of file +flask_minio +py-healthcheck \ No newline at end of file diff --git a/storage_service/app.py b/storage_service/app.py index 3725402..5dd2eb4 100644 --- a/storage_service/app.py +++ b/storage_service/app.py @@ -4,9 +4,10 @@ import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from flask import Flask from werkzeug.middleware.proxy_fix import ProxyFix +from healthcheck import HealthCheck # import stuff -from utils import register_all_error_handlers, storage +from utils import register_all_error_handlers, storage, health_database_status # import views from views import ObjectView @@ -41,6 +42,9 @@ app.config['MINIO_BUCKET_NAME'] = os.environ['MINIO_BUCKET_NAME'] app.config['MINIO_SECURE'] = os.environ.get('MINIO_SECURE', False) app.config['MINIO_REGION'] = os.environ.get('MINIO_REGION', None) +health = HealthCheck(app, "/healthz") + + # register error handlers register_all_error_handlers(app) @@ -48,6 +52,8 @@ register_all_error_handlers(app) for view in [ObjectView]: view.register(app, trailing_slash=False) +health.add_check(health_database_status) + # start debugging if needed if __name__ == "__main__": app.run(debug=True) diff --git a/storage_service/utils/__init__.py b/storage_service/utils/__init__.py index cd90b13..6c02400 100644 --- a/storage_service/utils/__init__.py +++ b/storage_service/utils/__init__.py @@ -2,3 +2,4 @@ from .require_decorators import json_required from .error_handlers import register_all_error_handlers from .storage import storage +from .healthchecks import health_database_status \ No newline at end of file diff --git a/storage_service/utils/healthchecks.py b/storage_service/utils/healthchecks.py new file mode 100644 index 0000000..45cda3b --- /dev/null +++ b/storage_service/utils/healthchecks.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from utils import storage + +""" +Healthchek functions +""" + +__author__ = "@tormakris" +__copyright__ = "Copyright 2020, Birbnetes Team" +__module_name__ = "healthchecks" +__version__text__ = "1" + + +def health_database_status(): + is_database_working = True + output = 'storage is ok' + try: + storage.connection.list_buckets() + except Exception as e: + output = str(e) + is_database_working = False + return is_database_working, output From 475e0e724207be353ef9be0fc910ba5d89f85f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 6 Dec 2020 11:14:40 +0100 Subject: [PATCH 3/4] update helathcheck --- storage_service/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage_service/app.py b/storage_service/app.py index 5dd2eb4..ccb9af1 100644 --- a/storage_service/app.py +++ b/storage_service/app.py @@ -42,7 +42,7 @@ app.config['MINIO_BUCKET_NAME'] = os.environ['MINIO_BUCKET_NAME'] app.config['MINIO_SECURE'] = os.environ.get('MINIO_SECURE', False) app.config['MINIO_REGION'] = os.environ.get('MINIO_REGION', None) -health = HealthCheck(app, "/healthz") +health = HealthCheck() # register error handlers @@ -53,6 +53,7 @@ for view in [ObjectView]: view.register(app, trailing_slash=False) health.add_check(health_database_status) +app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run()) # start debugging if needed if __name__ == "__main__": From 991bf21b3ae41e98c2248117c3270d2c14978d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 6 Dec 2020 11:26:12 +0100 Subject: [PATCH 4/4] update python --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 86e59b4..fe55131 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8-slim +FROM python:3.9-slim ADD storage_service requirements.txt /storage_service/ WORKDIR /storage_service/