logging and monitoring for thrimshim

pull/68/head
Christopher Usher 5 years ago
parent 6c633df3ee
commit 73541f852f

@ -12,11 +12,11 @@ import prometheus_client
import psycopg2 import psycopg2
from psycopg2 import sql from psycopg2 import sql
import common from common import database, PromLogCountsHandler, install_stacksampler, request_stats, after_request
from common import database
psycopg2.extras.register_uuid() psycopg2.extras.register_uuid()
app = flask.Flask('thrimshim') app = flask.Flask('thrimshim')
app.after_request(after_request)
def cors(app): def cors(app):
"""WSGI middleware that sets CORS headers""" """WSGI middleware that sets CORS headers"""
@ -36,11 +36,13 @@ def cors(app):
@app.route('/metrics') @app.route('/metrics')
@request_stats
def metrics(): def metrics():
"""Expose Prometheus metrics.""" """Expose Prometheus metrics."""
return prometheus_client.generate_latest() return prometheus_client.generate_latest()
@app.route('/thrimshim') @app.route('/thrimshim')
@request_stats
def get_all_rows(): def get_all_rows():
"""Gets all rows from the events table from the database""" """Gets all rows from the events table from the database"""
conn = app.db_manager.get_conn() conn = app.db_manager.get_conn()
@ -58,9 +60,11 @@ def get_all_rows():
) for key, value in row.items() ) for key, value in row.items()
} }
rows.append(row) rows.append(row)
logging.info('All rows fetched')
return json.dumps(rows) return json.dumps(rows)
@app.route('/thrimshim/<uuid:ident>', methods=['GET', 'POST']) @app.route('/thrimshim/<uuid:ident>', methods=['GET', 'POST'])
@request_stats
def thrimshim(ident): def thrimshim(ident):
"""Comunicate between Thrimbletrimmer and the Wubloader database.""" """Comunicate between Thrimbletrimmer and the Wubloader database."""
if flask.request.method == 'POST': if flask.request.method == 'POST':
@ -166,6 +170,7 @@ def update_row(ident, new_row):
return '' return ''
@app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST']) @app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST'])
@request_stats
def manual_link(ident): def manual_link(ident):
"""Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the """Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the
upload_location is 'manual'.""" upload_location is 'manual'."""
@ -191,6 +196,7 @@ def manual_link(ident):
@app.route('/thrimshim/reset/<uuid:ident>', methods=['POST']) @app.route('/thrimshim/reset/<uuid:ident>', methods=['POST'])
@request_stats
def reset_row(ident): def reset_row(ident):
"""Clear state and video_link columns and reset state to 'UNEDITED'.""" """Clear state and video_link columns and reset state to 'UNEDITED'."""
conn = app.db_manager.get_conn() 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() server.stop()
gevent.signal(signal.SIGTERM, stop) gevent.signal(signal.SIGTERM, stop)
common.PromLogCountsHandler.install() PromLogCountsHandler.install()
common.install_stacksampler() install_stacksampler()
if backdoor_port: if backdoor_port:
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start() gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()

Loading…
Cancel
Save