Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/api/server.py
Show All 11 Lines | |||||
from swh.core import config | from swh.core import config | ||||
from swh.storage import get_storage as get_swhstorage | from swh.storage import get_storage as get_swhstorage | ||||
from swh.core.api import (RPCServerApp, decode_request, | from swh.core.api import (RPCServerApp, decode_request, | ||||
error_handler, | error_handler, | ||||
encode_data_server as encode_data) | encode_data_server as encode_data) | ||||
from swh.core.statsd import statsd | from swh.core.statsd import statsd | ||||
def get_storage(): | |||||
global storage | |||||
if not storage: | |||||
storage = get_swhstorage(**app.config['storage']) | |||||
return storage | |||||
app = RPCServerApp(__name__) | app = RPCServerApp(__name__) | ||||
storage = None | storage = None | ||||
OPERATIONS_METRIC = 'swh_storage_operations_total' | OPERATIONS_METRIC = 'swh_storage_operations_total' | ||||
OPERATIONS_UNIT_METRIC = "swh_storage_operations_{unit}_total" | OPERATIONS_UNIT_METRIC = "swh_storage_operations_{unit}_total" | ||||
DURATION_METRIC = "swh_storage_request_duration_seconds" | DURATION_METRIC = "swh_storage_request_duration_seconds" | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | def process_metrics(f): | ||||
return d | return d | ||||
@app.errorhandler(Exception) | @app.errorhandler(Exception) | ||||
def my_error_handler(exception): | def my_error_handler(exception): | ||||
return error_handler(exception, encode_data) | return error_handler(exception, encode_data) | ||||
def get_storage(): | |||||
global storage | |||||
if not storage: | |||||
storage = get_swhstorage(**app.config['storage']) | |||||
return storage | |||||
@app.route('/') | @app.route('/') | ||||
@timed | @timed | ||||
def index(): | def index(): | ||||
return '''<html> | return '''<html> | ||||
<head><title>Software Heritage storage server</title></head> | <head><title>Software Heritage storage server</title></head> | ||||
<body> | <body> | ||||
<p>You have reached the | <p>You have reached the | ||||
<a href="https://www.softwareheritage.org/">Software Heritage</a> | <a href="https://www.softwareheritage.org/">Software Heritage</a> | ||||
▲ Show 20 Lines • Show All 475 Lines • Show Last 20 Lines |