Revert "Added before/after request handlers that add the execution time"

This reverts commit 424784ee45.
This commit is contained in:
Shay Nehmad 2020-02-12 16:05:30 +02:00
parent 424784ee45
commit 51099504e3
1 changed files with 1 additions and 26 deletions

View File

@ -1,11 +1,8 @@
import json
import logging
import os import os
import time
import uuid import uuid
import flask_restful import flask_restful
from flask import Flask, send_from_directory, Response, g from flask import Flask, send_from_directory, Response
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound
from monkey_island.cc.auth import init_jwt from monkey_island.cc.auth import init_jwt
@ -44,8 +41,6 @@ __author__ = 'Barak'
HOME_FILE = 'index.html' HOME_FILE = 'index.html'
logger = logging.getLogger(__name__)
def serve_static_file(static_path): def serve_static_file(static_path):
if static_path.startswith('api/'): if static_path.startswith('api/'):
@ -124,25 +119,6 @@ def init_api_resources(api):
api.add_resource(LogTest, '/api/test/log') api.add_resource(LogTest, '/api/test/log')
def init_app_execution_time_calc(app):
@app.before_request
def before_request():
g.start = time.time()
logger.debug("inb4 next request?")
@app.after_request
def after_request(response):
diff_in_ms = int((time.time() - g.start)*1000)
logger.debug(f"After request")
if response.response:
if response.content_type == "application/json":
response_data = json.loads(response.get_data())
if isinstance(response_data, dict):
response_data["execution_time_ms"] = diff_in_ms
response.set_data(json.dumps(response_data))
return response
def init_app(mongo_url): def init_app(mongo_url):
app = Flask(__name__) app = Flask(__name__)
@ -152,7 +128,6 @@ def init_app(mongo_url):
init_app_config(app, mongo_url) init_app_config(app, mongo_url)
init_app_services(app) init_app_services(app)
init_app_url_rules(app) init_app_url_rules(app)
init_app_execution_time_calc(app)
init_api_resources(api) init_api_resources(api)
return app return app