From: subhash kumar singh Date: Fri, 11 Oct 2024 12:39:50 +0000 (+0000) Subject: Add middleware to log the request time X-Git-Tag: 3.0.0~63 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=df24c7a1b266c2a3de4fa9b051b8469c85bf1027;p=aiml-fw%2Fawmf%2Ftm.git Add middleware to log the request time Added middleware to log the request time. Change-Id: I556b79332bcbad276b786162502751e68b4b624d Signed-off-by: subhash kumar singh --- diff --git a/.github/workflows/gerrit-verify.yaml b/.github/workflows/gerrit-verify.yaml index 2dc5c84..006eacc 100644 --- a/.github/workflows/gerrit-verify.yaml +++ b/.github/workflows/gerrit-verify.yaml @@ -81,7 +81,7 @@ jobs: GERRIT_PROJECT: ${{ inputs.GERRIT_PROJECT }} GERRIT_REFSPEC: ${{ inputs.GERRIT_REFSPEC }} TOX_ENVS: '["code"]' - PYTHON_VERSION: '3.8' + PYTHON_VERSION: '3.10' vote: if: ${{ always() }} diff --git a/middleware/__init__.py b/middleware/__init__.py new file mode 100644 index 0000000..677395c --- /dev/null +++ b/middleware/__init__.py @@ -0,0 +1,17 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== \ No newline at end of file diff --git a/middleware/loggingMiddleware.py b/middleware/loggingMiddleware.py new file mode 100644 index 0000000..177348a --- /dev/null +++ b/middleware/loggingMiddleware.py @@ -0,0 +1,35 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== +import time +from werkzeug.wrappers import Request, Response + +class LoggingMiddleware: + def __init__(self, app): + self.app = app + + def __call__(self, environ, start_response): + request = Request(environ) + + request_start_time = time.time() + response = self.app(environ, start_response) + request_end_time = time.time() + request_time_taken = request_end_time - request_start_time + + print(f"=(TM)=> Request: {request.method} {request.url} - Time Taken: {request_time_taken:.4f} seconds") + return response + diff --git a/trainingmgr/trainingmgr_main.py b/trainingmgr/trainingmgr_main.py index 3a213c6..413de0b 100644 --- a/trainingmgr/trainingmgr_main.py +++ b/trainingmgr/trainingmgr_main.py @@ -56,6 +56,9 @@ from trainingmgr.db.common_db_fun import get_data_extraction_in_progress_trainin get_feature_groups_db, get_feature_group_by_name_db, delete_feature_group_by_name, delete_trainingjob_version, change_field_value_by_version APP = Flask(__name__) + +from middleware.loggingMiddleware import LoggingMiddleware +APP.wsgi_app = LoggingMiddleware(APP.wsgi_app) TRAININGMGR_CONFIG_OBJ = None PS_DB_OBJ = None LOGGER = None