diff --git a/app/commands.py b/app/commands.py index 9b7e6afa..b516848f 100644 --- a/app/commands.py +++ b/app/commands.py @@ -15,7 +15,7 @@ from app.domain.regulations import compute_regulation_for_user from app.domain.vehicle import find_vehicle from app.helpers.oauth.models import ThirdPartyApiKey -from app.helpers.scalingo_logs import get_long_requests +from app.helpers.scalingo_logs import get_long_requests, get_user_requests from app.helpers.xml.greco import temp_write_greco_xml from app.models.controller_control import ControllerControl from app.models.user import User @@ -309,3 +309,9 @@ def temp_command_generate_xm_control(id): @app.cli.command("log_long_requests", with_appcontext=False) def log_long_requests(): get_long_requests(nb_results=20, nb_lines=100000) + + +@app.cli.command("log_user_requests", with_appcontext=False) +@click.argument("user_id", required=True) +def log_user_requests(user_id): + get_user_requests(user_id=user_id, nb_results=20, nb_lines=1000000) diff --git a/app/helpers/scalingo_logs.py b/app/helpers/scalingo_logs.py index b7c5bfef..ac0bb447 100644 --- a/app/helpers/scalingo_logs.py +++ b/app/helpers/scalingo_logs.py @@ -56,3 +56,15 @@ def get_long_requests(nb_results=20, nb_lines=10000): [f"{ms} ms", ts, endpoint, f"id={userid}", f"name={username}"] ) ) + + +def get_user_requests(user_id, nb_results=20, nb_lines=10000): + cmd = f"scalingo --region osc-fr1 --app mobilic-api logs --lines {nb_lines} | grep 'user_id={user_id}'" + + lines = [ + l.decode("utf-8") + for l in subprocess.check_output(cmd, shell=True).splitlines() + ] + + for l in lines[:nb_results]: + print(l)