From 68cfa1b3494fd11759ac05ddae3d6fa389a41901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 19 Oct 2020 22:30:34 +0200 Subject: [PATCH 1/3] add sentry tracing --- model_service/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model_service/app.py b/model_service/app.py index 5960ae3..b584d8c 100644 --- a/model_service/app.py +++ b/model_service/app.py @@ -19,6 +19,8 @@ if SENTRY_DSN: sentry_sdk.init( dsn=SENTRY_DSN, integrations=[FlaskIntegration()], + _experiments={"auto_enabling_integrations": True}, + traces_sample_rate=1.0, send_default_pii=True, release=os.environ.get('RELEASE_ID', 'test'), environment=os.environ.get('RELEASEMODE', 'dev') From c67bcc8db1d3a1581d100f8b1efba6aeeac9edfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 19 Nov 2020 01:28:21 +0100 Subject: [PATCH 2/3] add healthchecks --- model_service/app.py | 6 +++++- model_service/utils/__init__.py | 3 ++- model_service/utils/healthckecks.py | 23 +++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 model_service/utils/healthckecks.py diff --git a/model_service/app.py b/model_service/app.py index b584d8c..56c26e8 100644 --- a/model_service/app.py +++ b/model_service/app.py @@ -4,11 +4,12 @@ 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 model import db -from utils import register_all_error_handlers, storage +from utils import register_all_error_handlers, storage, health_database_status # import views from views import SVMView, CNNView, RootView @@ -47,6 +48,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # initialize stuff db.init_app(app) storage.init_app(app) +health = HealthCheck(app, "/healthz") @app.before_first_request @@ -61,6 +63,8 @@ register_all_error_handlers(app) for view in [SVMView, CNNView, RootView]: view.register(app, trailing_slash=False, route_prefix='/model') +health.add_check(health_database_status) + # start debuggig if needed if __name__ == "__main__": app.run(debug=True) diff --git a/model_service/utils/__init__.py b/model_service/utils/__init__.py index fe6829d..413c43a 100644 --- a/model_service/utils/__init__.py +++ b/model_service/utils/__init__.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 from .require_decorators import json_required, multipart_required from .error_handlers import register_all_error_handlers -from .storage import storage, ensure_buckets \ No newline at end of file +from .storage import storage, ensure_buckets +from .healthckecks import health_database_status \ No newline at end of file diff --git a/model_service/utils/healthckecks.py b/model_service/utils/healthckecks.py new file mode 100644 index 0000000..63a835f --- /dev/null +++ b/model_service/utils/healthckecks.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from model import db + +""" +Healthchek functions +""" + +__author__ = "@tormakris" +__copyright__ = "Copyright 2020, Birbnetes Team" +__module_name__ = "healthchecks" +__version__text__ = "1" + + +def health_database_status(): + is_database_working = True + output = 'database is ok' + try: + db.session.execute('SELECT 1') + except Exception as e: + output = str(e) + is_database_working = False + return is_database_working, output \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8c101e0..198015e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ marshmallow-enum psycopg2-binary flask_minio sentry-sdk +py-healthcheck cython From a7994d704d905431a7e2aa62d7a1a7e105e01585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 6 Dec 2020 11:15:11 +0100 Subject: [PATCH 3/3] update helathcheck --- model_service/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model_service/app.py b/model_service/app.py index 56c26e8..65a2f07 100644 --- a/model_service/app.py +++ b/model_service/app.py @@ -48,7 +48,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # initialize stuff db.init_app(app) storage.init_app(app) -health = HealthCheck(app, "/healthz") +health = HealthCheck() @app.before_first_request @@ -64,6 +64,7 @@ for view in [SVMView, CNNView, RootView]: view.register(app, trailing_slash=False, route_prefix='/model') health.add_check(health_database_status) +app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run()) # start debuggig if needed if __name__ == "__main__":