-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging improvements #63
Changes from all commits
d882ac8
789c877
1b10465
b69b1ad
376cef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import json | ||
from datetime import datetime | ||
from pathlib import Path | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, BackgroundTasks, Form | ||
from fastapi import APIRouter, BackgroundTasks, Form, HTTPException | ||
from fastapi.responses import StreamingResponse | ||
|
||
from ..local_paths import Paths | ||
from ..query.base import Query | ||
|
@@ -87,6 +90,38 @@ def get_ipa_helper_status( | |
return {"status": query.status.name} | ||
|
||
|
||
@router.get("/{query_id}/log-file") | ||
def get_ipa_helper_log_file( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend to guarantee ordering on the server side. JS operates in my browser and it is busy with other things, so we should delegate hard work to server side. Besides that, it also makes API consistent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw can you point me to the file where traces are written out of order? I'd like to take a look and see if we may have an issue on the MPC side There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I don't think they should ever be out of order on the server side. they are only out of order when merging the 4 files together. for example a log from Helper 1 might arrive after a log from Helper 2, but have an earlier timestamp. this is particularly true when we're refreshing later and just consuming the file in it's entirety. let me point you to where the ordering happens. It should be pretty efficient. |
||
query_id: str, | ||
): | ||
query = Query.get_from_query_id(query_id) | ||
if query is None: | ||
return HTTPException(status_code=404, detail="Query not found") | ||
|
||
def iterfile(): | ||
with open(query.log_file_path, "rb") as f: | ||
for line in f: | ||
try: | ||
data = json.loads(line) | ||
d = datetime.fromtimestamp( | ||
float(data["record"]["time"]["timestamp"]) | ||
) | ||
message = data["record"]["message"] | ||
yield f"{d.isoformat()} - {message}\n" | ||
except (json.JSONDecodeError, KeyError): | ||
yield line | ||
|
||
return StreamingResponse( | ||
iterfile(), | ||
headers={ | ||
"Content-Disposition": ( | ||
f'attachment; filename="{query_id}-{settings.role.name.title()}.log"' | ||
) | ||
}, | ||
media_type="text/plain", | ||
) | ||
|
||
|
||
@router.post("/ipa-query/{query_id}") | ||
def start_ipa_test_query( | ||
query_id: str, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akoshelev this is where the ordering happens. if the new log is already the last, it is just appended. if not, it uses
lastIndexOf
to find the right spot. this should be O(n) and I would imagine starts from the end of the list, where it will most likely find the right position.the other performance knob here is the max lines kept. I upped it to 10k, but we could lower that now that the download option is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it server side or client side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client side. client connects directly via websocket to logs from every helper.
I don't think it would be possible to do server side while they query is running, because a stale log from one helper could always arrive after other logs have reached the client.