Changeset View
Changeset View
Standalone View
Standalone View
swh/counters/api/server.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import os | import os | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.api import RPCServerApp | from swh.core.api import RPCServerApp | ||||
from swh.counters import get_counters | from swh.counters import get_counters, get_history | ||||
from swh.counters.interface import CountersInterface | from swh.counters.interface import CountersInterface, HistoryInterface | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
app = None | app = None | ||||
def make_app(config: Dict[str, Any]) -> RPCServerApp: | def make_app(config: Dict[str, Any]) -> RPCServerApp: | ||||
"""Initialize the remote api application. | """Initialize the remote api application. | ||||
""" | """ | ||||
app = RPCServerApp( | app = RPCServerApp( | ||||
__name__, | __name__, | ||||
backend_class=CountersInterface, | backend_class=CountersInterface, | ||||
backend_factory=lambda: get_counters(**config["counters"]), | backend_factory=lambda: get_counters(**config["counters"]), | ||||
) | ) | ||||
app.add_backend_class( | |||||
backend_class=HistoryInterface, | |||||
backend_factory=lambda: get_history(**config["history"]), | |||||
) | |||||
handler = logging.StreamHandler() | handler = logging.StreamHandler() | ||||
app.logger.addHandler(handler) | app.logger.addHandler(handler) | ||||
app.config["counters"] = get_counters(**config["counters"]) | app.config["counters"] = get_counters(**config["counters"]) | ||||
app.add_url_rule("/", "index", index) | app.add_url_rule("/", "index", index) | ||||
app.add_url_rule("/metrics", "metrics", get_metrics) | app.add_url_rule("/metrics", "metrics", get_metrics) | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |