- Require Python 3.15 in project metadata, runtime pin, and Docker stages. - Use lazy imports for database backends and type-only dependencies. - Defer benchmark dependencies until their code paths are used. - Rely on deferred annotations and use Path.info for file discovery. - Accept BattlesnakeArena alongside BattlesnakeEngine on game endpoints. - Advance quart_common for Python 3.15 and multi-agent validation. - Add pytest development dependencies and refresh the uv lockfile. - Test lazy backend loading, import order, and fresh file discovery. - Document the runtime requirements and locked uv workflow. BREAKING CHANGE: Python 3.15 or newer is required; earlier runtimes cannot parse the lazy import syntax.
24 lines
702 B
Python
24 lines
702 B
Python
from quart import Blueprint, jsonify, request
|
|
|
|
lazy from server.Server import Server
|
|
|
|
def create_metrics_blueprint(server:'Server') -> Blueprint:
|
|
blueprint = Blueprint('metrics', __name__)
|
|
|
|
@blueprint.get('/metrics')
|
|
async def metrics():
|
|
snapshot = await server.metrics_collector.build_snapshot(
|
|
server.game_runtime.game_last_seen_unix,
|
|
server.game_runtime.game_move_counts,
|
|
)
|
|
|
|
if 'prometheus' in (request.headers.get('User-Agent') or '').lower():
|
|
return (
|
|
server.metrics_collector.build_prometheus_metrics(snapshot),
|
|
200,
|
|
{'Content-Type': 'text/plain; version=0.0.4; charset=utf-8'},
|
|
)
|
|
|
|
return jsonify(snapshot)
|
|
return blueprint
|