From 9ee4a80f997b65d7ecda918e30fde5759d9b8f17 Mon Sep 17 00:00:00 2001 From: Oleksandr Bozbei Date: Fri, 15 Dec 2023 15:44:07 +0200 Subject: [PATCH 1/4] feat: Add additional logs on list requests. --- py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py | 1 + py_ocpi/modules/cdrs/v_2_2_1/api/cpo.py | 1 + py_ocpi/modules/locations/v_2_1_1/api/cpo.py | 1 + py_ocpi/modules/locations/v_2_2_1/api/cpo.py | 1 + py_ocpi/modules/sessions/v_2_1_1/api/cpo.py | 1 + py_ocpi/modules/sessions/v_2_2_1/api/cpo.py | 1 + py_ocpi/modules/tariffs/v_2_1_1/api/cpo.py | 1 + py_ocpi/modules/tariffs/v_2_2_1/api/cpo.py | 1 + py_ocpi/modules/tokens/v_2_1_1/api/emsp.py | 2 +- py_ocpi/modules/tokens/v_2_2_1/api/emsp.py | 2 +- 10 files changed, 10 insertions(+), 2 deletions(-) diff --git a/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py b/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py index d6285ae..e2eb691 100644 --- a/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py +++ b/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py @@ -58,6 +58,7 @@ async def get_cdrs( cdrs = [] for data in data_list: cdrs.append(adapter.cdr_adapter(data, VersionNumber.v_2_1_1).dict()) + logger.debug(f"Amount of cdrs in response: {len(cdrs)}") return OCPIResponse( data=cdrs, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/cdrs/v_2_2_1/api/cpo.py b/py_ocpi/modules/cdrs/v_2_2_1/api/cpo.py index 2721d03..c6c4b74 100644 --- a/py_ocpi/modules/cdrs/v_2_2_1/api/cpo.py +++ b/py_ocpi/modules/cdrs/v_2_2_1/api/cpo.py @@ -58,6 +58,7 @@ async def get_cdrs( cdrs = [] for data in data_list: cdrs.append(adapter.cdr_adapter(data).dict()) + logger.debug(f"Amount of cdrs in response: {len(cdrs)}") return OCPIResponse( data=cdrs, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/locations/v_2_1_1/api/cpo.py b/py_ocpi/modules/locations/v_2_1_1/api/cpo.py index ece8dd4..3d2c42c 100644 --- a/py_ocpi/modules/locations/v_2_1_1/api/cpo.py +++ b/py_ocpi/modules/locations/v_2_1_1/api/cpo.py @@ -61,6 +61,7 @@ async def get_locations( locations.append( adapter.location_adapter(data, VersionNumber.v_2_1_1).dict() ) + logger.debug(f"Amount of locations in response: {len(locations)}") return OCPIResponse( data=locations, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/locations/v_2_2_1/api/cpo.py b/py_ocpi/modules/locations/v_2_2_1/api/cpo.py index b590f4f..45f3e88 100644 --- a/py_ocpi/modules/locations/v_2_2_1/api/cpo.py +++ b/py_ocpi/modules/locations/v_2_2_1/api/cpo.py @@ -59,6 +59,7 @@ async def get_locations( locations = [] for data in data_list: locations.append(adapter.location_adapter(data).dict()) + logger.debug(f"Amount of locations in response: {len(locations)}") return OCPIResponse( data=locations, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/sessions/v_2_1_1/api/cpo.py b/py_ocpi/modules/sessions/v_2_1_1/api/cpo.py index c839c9c..bc8ee88 100644 --- a/py_ocpi/modules/sessions/v_2_1_1/api/cpo.py +++ b/py_ocpi/modules/sessions/v_2_1_1/api/cpo.py @@ -59,6 +59,7 @@ async def get_sessions( sessions.append( adapter.session_adapter(data, VersionNumber.v_2_1_1).dict() ) + logger.debug(f"Amount of sessions in response: {len(sessions)}") return OCPIResponse( data=sessions, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/sessions/v_2_2_1/api/cpo.py b/py_ocpi/modules/sessions/v_2_2_1/api/cpo.py index 0b8f4db..42a452b 100644 --- a/py_ocpi/modules/sessions/v_2_2_1/api/cpo.py +++ b/py_ocpi/modules/sessions/v_2_2_1/api/cpo.py @@ -59,6 +59,7 @@ async def get_sessions( sessions = [] for data in data_list: sessions.append(adapter.session_adapter(data).dict()) + logger.debug(f"Amount of sessions in response: {len(sessions)}") return OCPIResponse( data=sessions, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/tariffs/v_2_1_1/api/cpo.py b/py_ocpi/modules/tariffs/v_2_1_1/api/cpo.py index d54f557..fefbbac 100644 --- a/py_ocpi/modules/tariffs/v_2_1_1/api/cpo.py +++ b/py_ocpi/modules/tariffs/v_2_1_1/api/cpo.py @@ -59,6 +59,7 @@ async def get_tariffs( tariffs.append( adapter.tariff_adapter(data, VersionNumber.v_2_1_1).dict() ) + logger.debug(f"Amount of tariffs in response: {len(tariffs)}") return OCPIResponse( data=tariffs, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/tariffs/v_2_2_1/api/cpo.py b/py_ocpi/modules/tariffs/v_2_2_1/api/cpo.py index 3caa154..23dc6be 100644 --- a/py_ocpi/modules/tariffs/v_2_2_1/api/cpo.py +++ b/py_ocpi/modules/tariffs/v_2_2_1/api/cpo.py @@ -57,6 +57,7 @@ async def get_tariffs( tariffs = [] for data in data_list: tariffs.append(adapter.tariff_adapter(data).dict()) + logger.debug(f"Amount of tariffs in response: {len(tariffs)}") return OCPIResponse( data=tariffs, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/tokens/v_2_1_1/api/emsp.py b/py_ocpi/modules/tokens/v_2_1_1/api/emsp.py index b9b625c..a5c85a2 100644 --- a/py_ocpi/modules/tokens/v_2_1_1/api/emsp.py +++ b/py_ocpi/modules/tokens/v_2_1_1/api/emsp.py @@ -61,7 +61,7 @@ async def get_tokens( tokens = [] for data in data_list: tokens.append(adapter.token_adapter(data, VersionNumber.v_2_1_1).dict()) - + logger.debug(f"Amount of tokens in response: {len(tokens)}") return OCPIResponse( data=tokens, **status.OCPI_1000_GENERIC_SUCESS_CODE, diff --git a/py_ocpi/modules/tokens/v_2_2_1/api/emsp.py b/py_ocpi/modules/tokens/v_2_2_1/api/emsp.py index 9e47158..161b68b 100644 --- a/py_ocpi/modules/tokens/v_2_2_1/api/emsp.py +++ b/py_ocpi/modules/tokens/v_2_2_1/api/emsp.py @@ -61,7 +61,7 @@ async def get_tokens( tokens = [] for data in data_list: tokens.append(adapter.token_adapter(data).dict()) - + logger.debug(f"Amount of tokens in response: {len(tokens)}") return OCPIResponse( data=tokens, **status.OCPI_1000_GENERIC_SUCESS_CODE, From 680326368d145877ab8a5ad8ff22f56a45ebe69d Mon Sep 17 00:00:00 2001 From: Oleksandr Bozbei Date: Fri, 15 Dec 2023 15:44:43 +0200 Subject: [PATCH 2/4] feat: Add logs for get_list function result. --- py_ocpi/core/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/py_ocpi/core/utils.py b/py_ocpi/core/utils.py index 4c7bba5..d06e464 100644 --- a/py_ocpi/core/utils.py +++ b/py_ocpi/core/utils.py @@ -6,6 +6,7 @@ from fastapi import Response, Request from pydantic import BaseModel +from py_ocpi.core.config import logger from py_ocpi.core.enums import ModuleID, RoleEnum from py_ocpi.core.config import settings from py_ocpi.modules.versions.enums import VersionNumber @@ -59,7 +60,10 @@ async def get_list( ) set_pagination_headers(response, link, total, filters["limit"]) - + logger.debug( + f"List / total / is_last_page -> " + f"{len(data_list)} / {total} / {is_last_page}." + ) return data_list From d572b8b953c3bd1b0fd5ab7c973714cb340fa15a Mon Sep 17 00:00:00 2001 From: Oleksandr Bozbei Date: Fri, 15 Dec 2023 15:45:33 +0200 Subject: [PATCH 3/4] feat: Add general exception catcher + log resulting status code. --- py_ocpi/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/py_ocpi/main.py b/py_ocpi/main.py index 47ce540..c19a4a0 100644 --- a/py_ocpi/main.py +++ b/py_ocpi/main.py @@ -64,6 +64,16 @@ async def dispatch( **status.OCPI_3000_GENERIC_SERVER_ERROR, ).dict() ) + except Exception as e: + logger.warning(f"Unknown exception: {str(e)}.") + response = JSONResponse( + OCPIResponse( + data=[], + **status.OCPI_3000_GENERIC_SERVER_ERROR, + ).dict() + ) + + logger.debug(f"Response status_code -> {response.status_code}.") return response From 560638c4f752de2ac66843cfeff0b6c505d29ed3 Mon Sep 17 00:00:00 2001 From: Oleksandr Bozbei Date: Fri, 15 Dec 2023 15:45:58 +0200 Subject: [PATCH 4/4] docs: Change release version. --- py_ocpi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py_ocpi/__init__.py b/py_ocpi/__init__.py index 2653523..d041942 100644 --- a/py_ocpi/__init__.py +++ b/py_ocpi/__init__.py @@ -1,6 +1,6 @@ """Python Implementation of OCPI""" -__version__ = "2023.12.4" +__version__ = "2023.12.15" from .core import enums, data_types from .main import get_application