Skip to content

Commit

Permalink
helper(scalingo-logs): print last requests from user
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-gueguen committed Mar 25, 2024
1 parent f97c351 commit 30b1166
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions app/helpers/scalingo_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 30b1166

Please sign in to comment.