From 73541f852ff7c225e44e979cd394ef5be2de1bf8 Mon Sep 17 00:00:00 2001 From: Christopher Usher Date: Tue, 20 Aug 2019 16:28:40 -0700 Subject: [PATCH] logging and monitoring for thrimshim --- thrimshim/thrimshim/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/thrimshim/thrimshim/main.py b/thrimshim/thrimshim/main.py index c0a1e21..2d89380 100644 --- a/thrimshim/thrimshim/main.py +++ b/thrimshim/thrimshim/main.py @@ -12,11 +12,11 @@ import prometheus_client import psycopg2 from psycopg2 import sql -import common -from common import database +from common import database, PromLogCountsHandler, install_stacksampler, request_stats, after_request psycopg2.extras.register_uuid() app = flask.Flask('thrimshim') +app.after_request(after_request) def cors(app): """WSGI middleware that sets CORS headers""" @@ -36,11 +36,13 @@ def cors(app): @app.route('/metrics') +@request_stats def metrics(): """Expose Prometheus metrics.""" return prometheus_client.generate_latest() @app.route('/thrimshim') +@request_stats def get_all_rows(): """Gets all rows from the events table from the database""" conn = app.db_manager.get_conn() @@ -58,9 +60,11 @@ def get_all_rows(): ) for key, value in row.items() } rows.append(row) + logging.info('All rows fetched') return json.dumps(rows) @app.route('/thrimshim/', methods=['GET', 'POST']) +@request_stats def thrimshim(ident): """Comunicate between Thrimbletrimmer and the Wubloader database.""" if flask.request.method == 'POST': @@ -166,6 +170,7 @@ def update_row(ident, new_row): return '' @app.route('/thrimshim/manual-link/', methods=['POST']) +@request_stats def manual_link(ident): """Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the upload_location is 'manual'.""" @@ -191,6 +196,7 @@ def manual_link(ident): @app.route('/thrimshim/reset/', methods=['POST']) +@request_stats def reset_row(ident): """Clear state and video_link columns and reset state to 'UNEDITED'.""" conn = app.db_manager.get_conn() @@ -219,8 +225,8 @@ def main(connection_string, host='0.0.0.0', port=8004, backdoor_port=0): server.stop() gevent.signal(signal.SIGTERM, stop) - common.PromLogCountsHandler.install() - common.install_stacksampler() + PromLogCountsHandler.install() + install_stacksampler() if backdoor_port: gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()