diff --git a/swh/storage/api/server.py b/swh/storage/api/server.py --- a/swh/storage/api/server.py +++ b/swh/storage/api/server.py @@ -13,11 +13,26 @@ from swh.core.api import (SWHServerAPIApp, decode_request, error_handler, encode_data_server as encode_data) +from swh.core.statsd import statsd + app = SWHServerAPIApp(__name__) storage = None +def timed(f): + """Time that function! + + """ + def time_and_count_function(*a, **kw): + statsd.increment('swh_storage_request_count', + tags={'endpoint': f.__name__}) + with statsd.timed('swh_storage_request_duration_seconds', + tags={'endpoint': f.__name__}): + return f(*a, **kw) + return time_and_count_function + + @app.errorhandler(Exception) def my_error_handler(exception): return error_handler(exception, encode_data) @@ -67,6 +82,7 @@ return encode_data(get_storage().content_find(**decode_request(request))) +@timed @app.route('/content/add', methods=['POST']) def content_add(): return encode_data(get_storage().content_add(**decode_request(request))) diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -25,6 +25,7 @@ from swh.objstorage import get_objstorage from swh.objstorage.exc import ObjNotFoundError + # Max block size of contents to return BULK_BLOCK_CONTENT_LEN_MAX = 10000