Skip to content
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

Add response time in logs #201

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rest_api/controller/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from datetime import datetime
from typing import List, Dict, Optional

Expand Down Expand Up @@ -111,6 +112,7 @@ class Answers(BaseModel):
@router.post("/models/{model_id}/doc-qa", response_model=Answers, response_model_exclude_unset=True)
def doc_qa(model_id: int, request: Question):
with doc_qa_limiter.run():
start_time = time.time()
finder = FINDERS.get(model_id, None)
if not finder:
raise HTTPException(
Expand All @@ -135,7 +137,8 @@ def doc_qa(model_id: int, request: Question):
results.append(result)

elasticapm.set_custom_context({"results": results})
logger.info({"request": request.json(), "results": results})
end_time = time.time()
logger.info({"request": request.json(), "results": results, "time": f"{(end_time - start_time):.2f}"})

return {"results": results}

Expand Down