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, Optional | from typing import Any, Dict, Optional | ||||
from flask import abort | from flask import abort, jsonify | ||||
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, get_history | from swh.counters import get_counters, get_history | ||||
from swh.counters.interface import CountersInterface, HistoryInterface | from swh.counters.interface import CountersInterface, HistoryInterface | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | def get_metrics(): | ||||
response.append("") | response.append("") | ||||
return "\n".join(response) | return "\n".join(response) | ||||
def get_history_file_content(filename: str): | def get_history_file_content(filename: str): | ||||
assert app is not None | assert app is not None | ||||
try: | try: | ||||
return app.config["history"].get_history(filename) | content = app.config["history"].get_history(filename) | ||||
except FileNotFoundError: | except FileNotFoundError: | ||||
abort(404) | abort(404) | ||||
return jsonify(content) |