diff --git a/csm/core/agent/api.py b/csm/core/agent/api.py index bf47c3c00..1bd1424d9 100644 --- a/csm/core/agent/api.py +++ b/csm/core/agent/api.py @@ -313,7 +313,7 @@ async def throttler_middleware(request, handler): if CsmRestApi.__nreq >= CsmRestApi.__request_quota: # This block get executed when number of request reaches the request quota CsmRestApi.__nblocked += 1 - msg = (f"The request is blocked because the number of requests reached threshold\n" + msg = (f"[{request.request_id}] The request is blocked because the number of requests reached threshold\n" f"Number of requests blocked since the start is {CsmRestApi.__nblocked}") Log.warn(msg) return web.Response(status=429, text="Too many requests") @@ -343,13 +343,13 @@ async def session_middleware(request, handler): conf_key = CsmRestApi._retrieve_config(request) if conf_key.lower() == const.ENABLE: is_public = False - Log.debug(f'{"Public" if is_public else "Non-public"}: {request}') + Log.debug(f'[{request.request_id}]{"Public" if is_public else "Non-public"}: {request}') try: if not is_public: session_id = CsmRestApi._extract_bearer(request.headers) session = await CsmRestApi._validate_bearer( request.app.login_service, session_id) - Log.info("Session token validated. User:"\ + Log.info(f"[{request.request_id}]Session token validated. User:"\ f" {session.credentials.user_id}") except CsmNotFoundError as e: CsmRestApi._unauthorised(e.error()) @@ -363,15 +363,15 @@ async def permission_middleware(cls, request, handler): # Check user permissions required = await cls._get_permissions(request) verdict = (request.session.permissions & required) == required - Log.debug(f'Required permissions: {required}') - Log.debug(f'User permissions: {request.session.permissions}') - Log.debug(f'Allow access: {verdict}') + Log.debug(f'[{request.request_id}] Required permissions: {required}') + Log.debug(f'[{request.request_id}] User permissions: {request.session.permissions}') + Log.debug(f'[{request.request_id}] Allow access: {verdict}') if not verdict: - Log.info(f"Authorization failed. User:"\ + Log.info(f"[{request.request_id}] Authorization failed. User:"\ f" {request.session.credentials.user_id}") raise CsmPermissionDenied("Access to the requested resource"\ " is forbidden") - Log.info(f"Authorization successful. User:"\ + Log.info(f"[{request.request_id}]Authorization successful. User:"\ f" {request.session.credentials.user_id}") return await handler(request) @@ -420,7 +420,7 @@ async def rest_middleware(request, handler): resp_obj = {'message': resp.output()} status = resp.rc() if not 200 <= status <= 299: - Log.error(f"Error: ({status}):{resp_obj['message']}") + Log.error(f"[{request.request_id}] : Error: ({status}):{resp_obj['message']}") else: resp_obj = resp return CsmRestApi.json_response(resp_obj, status) @@ -429,7 +429,7 @@ async def rest_middleware(request, handler): # These exceptions are thrown by aiohttp when request is cancelled # by client to complete task which are await use atomic except (ConcurrentCancelledError, AsyncioCancelledError): - Log.warn(f"Client cancelled call for {request.method} {request.path}") + Log.warn(f"[{request.request_id}] : Client cancelled call for {request.method} {request.path}") resp = CsmRestApi.error_response( CsmRequestCancelled(desc="Call cancelled by client"), request=request, request_id=request.request_id) @@ -437,70 +437,80 @@ async def rest_middleware(request, handler): except CsmHttpException as e: raise e except web.HTTPException as e: - Log.error(f'HTTP Exception {e.status}: {e.reason}') + Log.error(f'[{request.request_id}] : HTTP Exception {e.status}: {e.reason}') resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=e.status) except DataAccessError as e: - Log.error(f"Failed to access the database: {e}") + Log.error(f"[{request.request_id}] : Failed to access the database: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=503) except InvalidRequest as e: - Log.debug(f"Invalid Request: {e} \n {traceback.format_exc()}") + Log.debug(f"[{request.request_id}] Invalid Request: {e} \n {traceback.format_exc()}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=400) except CsmNotFoundError as e: + Log.error(f"[{request.request_id}] : CSM not found: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=404) except CsmPermissionDenied as e: + Log.debug(f"[{request.request_id}] : CSM permission denied: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=403) except ResourceExist as e: + Log.debug(f"[{request.request_id}] : Resource Exists : {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=const.STATUS_CONFLICT) except CsmInternalError as e: + Log.error(f"[{request.request_id}] : CSM Internal error: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=500) except CsmNotImplemented as e: + Log.debug(f"[{request.request_id}] : CSM Not Implemented : {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=501) except CsmGatewayTimeout as e: + Log.debug(f"[{request.request_id}] : CSM Gateway Timeout : {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=504) except CsmServiceConflict as e: + Log.error(f"[{request.request_id}] : CSM Service conflict: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=409) except CsmUnauthorizedError as e: + Log.error(f"[{request.request_id}] : CSM Unauthorized Error: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=401) except CsmError as e: + Log.error(f"[{request.request_id}] : CSM Error : {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=400) except KeyError as e: - Log.debug(f"Key Error: {e} \n {traceback.format_exc()}") + Log.error(f"[{request.request_id}] : Key Error: {e}") + message = f"Missing Key for {e}" resp = CsmRestApi.error_response(KeyError(message), request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=422) except (ServerDisconnectedError, ClientConnectorError, ClientOSError, ConcurrentTimeoutError) as e: + Log.error(f"[{request.request_id}] : Error : {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=503) except Exception as e: - Log.critical(f"Unhandled Exception Caught: {e} \n" - f"{traceback.format_exc()}") + Log.critical(f"[{request.request_id}] : Unhandled Exception Caught: {e}") resp = CsmRestApi.error_response(e, request=request, request_id=request.request_id) return CsmRestApi.json_response(resp, status=500) @@ -650,7 +660,8 @@ async def _websock_broadcast(msg): for ws in clients: json_msg = CsmRestApi.json_serializer(msg) await ws.send_str(json_msg) - except Exception: + except Exception : + # Log.debug('REST API websock broadcast error') Log.debug('REST API websock broadcast error') @classmethod @@ -683,3 +694,4 @@ def push(alert): coro = CsmRestApi._async_push(alert) asyncio.run_coroutine_threadsafe(coro, CsmRestApi._app.loop) return True + diff --git a/csm/core/controllers/login.py b/csm/core/controllers/login.py index 50f5b6b04..155643dd6 100644 --- a/csm/core/controllers/login.py +++ b/csm/core/controllers/login.py @@ -38,7 +38,7 @@ async def post(self): username = request_body.get(const.UNAME) password = request_body.get(const.PASS) Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" user: {username}") except json.decoder.JSONDecodeError: raise InvalidRequest(const.JSON_ERROR) @@ -48,7 +48,7 @@ async def post(self): username, password) if not session_id: raise CsmUnauthorizedError("Invalid credentials for user") - Log.info(f"Login successful. User: {username}") + Log.info(f"[{self.request.request_id}] Login successful. User: {username}") headers = {CsmAuth.HDR: f'{CsmAuth.TYPE} {session_id}'} return CsmResponse(body, headers=headers) @@ -60,10 +60,11 @@ class LogoutView(CsmView): async def post(self): username = self.request.session.credentials.user_id Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {username}") session_id = self.request.session.session_id await self.request.app.login_service.logout(session_id) # TODO: Stop any websocket connection corresponding to this session - Log.info(f"Logout successful. User: {username}") + Log.info(f"[{self.request.request_id}] Logout successful. User: {username}") return CsmResponse() + \ No newline at end of file diff --git a/csm/core/controllers/rgw/s3/users.py b/csm/core/controllers/rgw/s3/users.py index 0729e2034..ef5c05f7c 100644 --- a/csm/core/controllers/rgw/s3/users.py +++ b/csm/core/controllers/rgw/s3/users.py @@ -124,12 +124,12 @@ def __init__(self, request): async def post(self): """POST REST implementation for creating a new s3 iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") try: schema = UserCreateSchema() user_body = schema.load(await self.request.json()) - Log.debug(f"Handling create s3 iam user PUT request" + Log.debug(f"[{self.request.request_id}] Handling create s3 iam user PUT request" f" request body: {user_body}") except json.decoder.JSONDecodeError: raise InvalidRequest("Could not parse request body, invalid JSON received.") @@ -138,7 +138,7 @@ async def post(self): with ServiceError.guard_service(): response = await self._service.create_user(**user_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response, const.STATUS_CREATED) @@ -149,12 +149,12 @@ async def get(self): GET REST implementation for list IAM users. """ Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") try: schema = ListAllUsersSchema() request_parameters = schema.load(self.request.rel_url.query) - Log.debug(f"Handling listing of all IAM users request" + Log.debug(f"[{self.request.request_id}] Handling listing of all IAM users request" f" request body: {request_parameters}") except json.decoder.JSONDecodeError: raise InvalidRequest("Could not parse request body, invalid JSON received.") @@ -163,7 +163,7 @@ async def get(self): with ServiceError.guard_service(): response = await self._service.get_all_users(**request_parameters) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -186,16 +186,16 @@ def __init__(self, request): async def get(self): """GET REST implementation for fetching an existing s3 iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") uid = self.request.match_info[const.UID] path_params_dict = {const.UID: uid} - Log.debug(f"Handling s3 iam user GET request" + Log.debug(f"[{self.request.request_id}] Handling s3 iam user GET request" f" with path param: {uid}") with ServiceError.guard_service(): response = await self._service.get_user(**path_params_dict) Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -204,18 +204,18 @@ async def get(self): async def delete(self): """DELETE REST implementation for deleting an existing s3 iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") uid = self.request.match_info[const.UID] if self._is_iam_privileged_user(uid): raise CsmPermissionDenied() path_params = {const.UID: uid} - Log.debug(f"Handling s3 iam user DELETE request" + Log.debug(f"[{self.request.request_id}] Handling s3 iam user DELETE request" f" path params/request body: {path_params}") with ServiceError.guard_service(): response = await self._service.delete_user(**path_params) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -224,7 +224,7 @@ async def delete(self): async def patch(self): """PATCH REST implementation for modifying an existing s3 iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") uid = self.request.match_info[const.UID] path_params_dict = {const.UID: uid} @@ -241,12 +241,12 @@ async def patch(self): except ValidationError as val_err: raise InvalidRequest(f"{ValidationErrorFormatter.format(val_err)}") request_body = {**path_params_dict, **request_body_params_dict} - Log.debug(f"Handling s3 iam user Modify request" + Log.debug(f"[{self.request.request_id}] Handling s3 iam user Modify request" f" path params/request body: {request_body}") with ServiceError.guard_service(): response = await self._service.modify_user(**request_body) Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -269,14 +269,14 @@ def __init__(self, request): async def put(self): """PUT REST implementation to create/add access key for iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") try: schema = CreateKeySchema() create_key_body = schema.load(await self.request.json()) if self._is_iam_privileged_user(create_key_body.get(const.UID)): raise CsmPermissionDenied() - Log.debug(f"Handling Add access key PUT request" + Log.debug(f"[{self.request.request_id}] Handling Add access key PUT request" f" request body: {create_key_body}") except json.decoder.JSONDecodeError: raise InvalidRequest("Could not parse request body, invalid JSON received.") @@ -285,7 +285,7 @@ async def put(self): with ServiceError.guard_service(): response = await self._service.create_key(**create_key_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -294,14 +294,14 @@ async def put(self): async def delete(self): """DELETE REST implementation to remove access key of user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") try: schema = RemoveKeySchema() remove_key_body = schema.load(await self.request.json()) if self._is_iam_privileged_user(remove_key_body.get(const.UID)): raise CsmPermissionDenied() - Log.debug(f"Handling Remove access key DELETE request" + Log.debug(f"[{self.request.request_id}] Handling Remove access key DELETE request" f" request body: {remove_key_body}") except json.decoder.JSONDecodeError: raise InvalidRequest("Could not parse request body, invalid JSON received.") @@ -310,7 +310,7 @@ async def delete(self): with ServiceError.guard_service(): response = await self._service.remove_key(**remove_key_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -341,7 +341,7 @@ async def create_caps_request_body(self): raise InvalidRequest(f"{ValidationErrorFormatter.format(val_err)}") path_params_dict = {const.UID: uid} request_body = {**path_params_dict, **user_caps_body} - Log.debug(f"Handling user caps request" + Log.debug(f"[{self.request.request_id}] Handling user caps request" f" request body: {request_body}") return request_body @@ -350,14 +350,14 @@ async def create_caps_request_body(self): async def put(self): """PUT REST implementation to add user caps for iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") request_body = await self.create_caps_request_body() with ServiceError.guard_service(): response = await self._service.add_user_caps(**request_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -366,13 +366,13 @@ async def put(self): async def delete(self): """DELETE REST implementation to remove user caps for iam user.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") request_body = await self.create_caps_request_body() with ServiceError.guard_service(): response = await self._service.remove_user_caps(**request_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -395,7 +395,7 @@ def __init__(self, request): async def get(self): """GET REST implementation for fetching user level quota by uid.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") uid = self.request.match_info[const.UID] path_params_dict = {const.UID: uid} @@ -404,7 +404,7 @@ async def get(self): with ServiceError.guard_service(): response = await self._service.get_user_quota(**path_params_dict) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -413,7 +413,7 @@ async def get(self): async def put(self): """PUT REST implementation for setting user level quota by uid.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") uid = self.request.match_info[const.UID] try: @@ -430,11 +430,12 @@ async def put(self): raise InvalidRequest(f"{ValidationErrorFormatter.format(val_err)}") path_params_dict = {const.UID: uid} request_body = {**path_params_dict, **request_body_params_dict} - Log.debug(f"Handling iam user quota PUT request" + Log.debug(f"[{self.request.request_id}] Handling iam user quota PUT request" f" path params/request body: {request_body}") with ServiceError.guard_service(): response = await self._service.set_user_quota(**request_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) + \ No newline at end of file diff --git a/csm/core/controllers/storage_capacity.py b/csm/core/controllers/storage_capacity.py index e191019a4..3df74ecac 100644 --- a/csm/core/controllers/storage_capacity.py +++ b/csm/core/controllers/storage_capacity.py @@ -70,14 +70,18 @@ def __init__(self, request): @CsmAuth.permissions({Resource.CAPACITY: {Action.LIST}}) @Log.trace_method(Log.DEBUG) async def get(self): - Log.info("Handling GET implementation for getting cluster staus data") - + Log.info( + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ + f" User: {self.request.session.credentials.user_id}") resp = await self._service.get_cluster_data() if isinstance(resp, CapacityError): raise CsmHttpException(resp.http_status, CAPACITY_SERVICE_ERROR, resp.message_id, resp.message) + Log.info( + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ + f" User: {self.request.session.credentials.user_id}") return resp @@ -92,6 +96,9 @@ def __init__(self, request): @CsmAuth.permissions({Resource.CAPACITY: {Action.LIST}}) @Log.trace_method(Log.DEBUG) async def get(self): + Log.info( + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ + f" User: {self.request.session.credentials.user_id}") path_param = self.request.match_info[const.CAPACITY_RESOURCE] Log.info(f"Handling GET implementation for getting cluster status data" f" with path param: {path_param}") @@ -101,6 +108,9 @@ async def get(self): CAPACITY_SERVICE_ERROR, resp.message_id, resp.message) + Log.info( + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ + f" User: {self.request.session.credentials.user_id}") return resp @CsmView._app_routes.view("/api/v2/capacity/s3/{resource}/{id}") @@ -117,10 +127,11 @@ def __init__(self, request): @CsmAuth.permissions({Resource.CAPACITY: {Action.LIST}}) @Log.trace_method(Log.DEBUG) async def get(self): + Log.info( + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ + f" User: {self.request.session.credentials.user_id}") resource = self.request.match_info[const.ARG_RESOURCE] resource_id = self.request.match_info[const.ID] - Log.info(f"Handling GET s3 capacity request" - f"resource={resource} and id ={resource_id}") try: schema = S3CapacitySchema() schema.load({const.ARG_RESOURCE:resource}) @@ -128,6 +139,9 @@ async def get(self): raise InvalidRequest(f"{ValidationErrorFormatter.format(val_err)}") with ServiceError.guard_service(): response = await self._service.get_usage(resource, resource_id) + Log.info( + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ + f" User: {self.request.session.credentials.user_id}") return CsmResponse(response) @@ -136,7 +150,6 @@ class S3CapacityTenantView(CsmView): """ GET REST API view implementation for getting capacity usage for specific user """ - def __init__(self, request): """Get user level capacity usage Init.""" super().__init__(request) @@ -149,7 +162,7 @@ async def get(self): resource_id = self.request.match_info[const.ID] tenant = self.request.match_info[const.TENANT] resource_id = tenant+'$'+resource_id - Log.info(f"Handling GET s3 capacity request" + Log.info(f"[{self.request.request_id}] Handling GET s3 capacity request" f"resource={resource} and id ={resource_id}") try: schema = S3CapacitySchema() diff --git a/csm/core/controllers/users.py b/csm/core/controllers/users.py index 7bad1cf9f..33a3fa93d 100644 --- a/csm/core/controllers/users.py +++ b/csm/core/controllers/users.py @@ -93,7 +93,7 @@ def __init__(self, request): async def get(self): """GET REST implementation for fetching csm users.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") csm_schema = CsmGetUsersSchema() try: @@ -102,7 +102,7 @@ async def get(self): raise InvalidRequest(str(val_err)) users = await self._service.get_user_list(**request_data) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return {'users': users} @@ -111,7 +111,7 @@ async def post(self): """POST REST implementation for creating a csm user.""" creator = self.request.session.credentials.user_id if self.request.session else None Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {creator}") try: schema = CsmUserCreateSchema() @@ -131,7 +131,7 @@ async def post(self): user_body['creator_id'] = creator response = await self._service.create_user(**user_body) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {creator}") return CsmResponse(response, const.STATUS_CREATED) @@ -148,12 +148,12 @@ def __init__(self, request): async def get(self): """GET REST implementation for csm account get request.""" Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") user_id = self.request.match_info["user_id"] resp = await self._service.get_user(user_id) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {self.request.session.credentials.user_id}") return resp @@ -162,7 +162,7 @@ async def delete(self): """DELETE REST implementation for csm account delete request.""" loggedin_user_id = self.request.session.credentials.user_id Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {loggedin_user_id}") user_id = self.request.match_info["user_id"] resp = await self._service.delete_user(user_id, loggedin_user_id) @@ -171,7 +171,7 @@ async def delete(self): # admin cannot be deleted await self.request.app.login_service.delete_all_sessions_for_user(user_id) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {loggedin_user_id}") return resp @@ -180,7 +180,7 @@ async def patch(self): """PATCH implementation for creating a csm user.""" loggedin_user_id = self.request.session.credentials.user_id Log.info( - f"Processing request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processing request: {self.request.method} {self.request.path}"\ f" User: {loggedin_user_id}") user_id = self.request.match_info["user_id"] @@ -196,6 +196,7 @@ async def patch(self): resp = await self._service.update_user( user_id, user_body, loggedin_user_id) Log.info( - f"Processed request: {self.request.method} {self.request.path}"\ + f"[{self.request.request_id}] Processed request: {self.request.method} {self.request.path}"\ f" User: {loggedin_user_id}") return resp + \ No newline at end of file diff --git a/csm/core/services/sessions.py b/csm/core/services/sessions.py index 87621fcdc..df03f7d1d 100644 --- a/csm/core/services/sessions.py +++ b/csm/core/services/sessions.py @@ -433,3 +433,4 @@ async def _is_valid_session_exists(self, user_id: str) -> None: # return valid session return each_session return None + \ No newline at end of file diff --git a/csm/core/services/storage_capacity.py b/csm/core/services/storage_capacity.py index 80f06dc95..68efd36e9 100644 --- a/csm/core/services/storage_capacity.py +++ b/csm/core/services/storage_capacity.py @@ -125,8 +125,8 @@ async def get_cluster_data(self, data_filter=None): Log.info(f"Fetching cluster status retry counter: {retry}") response = await self.request(session, method, url, expected_success_code) break - except ClientConnectorError: - Log.error(f"Failed to get cluster status in attempt ({retry})") + except ClientConnectorError as error: + Log.error(f"Failed to get cluster status in attempt ({retry}):{error}") if retry == MAX_RETRY_COUNT-1: self._create_error(503, "Unable to connect to the service") return self.capacity_error @@ -180,9 +180,12 @@ async def get_usage(self, resource, resource_id): async def _get_user_usage(self, **request_body): plugin_response = await self._s3_iam_plugin.execute(const.GET_USER_CAPACITY_OPERATION, **request_body) if isinstance(plugin_response, RgwError): + Log.error(f"S3ServiceError: {plugin_response.error_code.name}:"\ + f" {plugin_response.error_message}") ServiceError.create(plugin_response) users_dict = plugin_response["capacity"]["s3"]["users"] users_list = [] users_list.append(users_dict.copy()) plugin_response["capacity"]["s3"]["users"] = users_list return plugin_response +