Skip to content

Commit

Permalink
Add response time in logs (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaysoni committed Jul 7, 2020
1 parent 68d604d commit ff7e355
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rest_api/controller/search.py
@@ -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

0 comments on commit ff7e355

Please sign in to comment.