diff --git a/backend/Pipfile b/backend/Pipfile
index 4d06a94..1f9a632 100644
--- a/backend/Pipfile
+++ b/backend/Pipfile
@@ -25,3 +25,4 @@ pymemcache = "*"
fastapi-cli = "*"
scikit-learn = "*"
pyqt6 = "*"
+loki-logger-handler = "*"
diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock
index 880b9a6..b13bd13 100644
--- a/backend/Pipfile.lock
+++ b/backend/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "bb22b4e28c7aa199c94b688ad93d3ab0ccf1089a172131f4aec03b78e7bd7f1c"
+ "sha256": "6edd6644586e8814a0b4526adb3352dfc17828ca129de7a68c1d5929efe94daa"
},
"pipfile-spec": 6,
"requires": {},
@@ -507,6 +507,15 @@
"markers": "python_version >= '3.8'",
"version": "==1.4.7"
},
+ "loki-logger-handler": {
+ "hashes": [
+ "sha256:aa1a9c933282c134a1e4271aba3cbaa2a3660eab6ea415bad7a072444ab98aa8",
+ "sha256:f6114727a9e5e6f3f2058b9b5324d1cab6d1a04e802079f7b57a8aeb7bd0a112"
+ ],
+ "index": "pypi",
+ "markers": "python_version >= '2.7'",
+ "version": "==1.0.2"
+ },
"lxml": {
"hashes": [
"sha256:01220dca0d066d1349bd6a1726856a78f7929f3878f7e2ee83c296c69495309e",
diff --git a/backend/deployment b/backend/deployment
index 718df09..4f0a028 160000
--- a/backend/deployment
+++ b/backend/deployment
@@ -1 +1 @@
-Subproject commit 718df09e88b63c9524c882ccbb8247ca1448d3ff
+Subproject commit 4f0a0289fcf8a7755d7dc1a76b443fe1233685ae
diff --git a/backend/report.html b/backend/report.html
deleted file mode 100644
index d46b72d..0000000
--- a/backend/report.html
+++ /dev/null
@@ -1,1094 +0,0 @@
-
-
-
-
- Backend Testing Report
-
-
-
-
- Backend Testing Report
- Report generated on 13-Dec-2024 at 08:58:37 by pytest-html
- v4.1.1
-
-
-
-
-
- |
- |
-
-
-
-
-
- No results found. Check the filters.
- |
-
-
-
-
-
-
-
-
-
-
-
-
Summary
-
-
-
12 tests took 865 ms.
-
(Un)check the boxes to filter the results.
-
-
-
-
-
-
-
-
-
-
-
-
- Result |
- Test |
- Detailed trip |
- Trip Duration |
- Target Duration |
- Execution time |
- Links |
-
-
-
-
-
-
\ No newline at end of file
diff --git a/backend/src/persistence.py b/backend/src/cache.py
similarity index 100%
rename from backend/src/persistence.py
rename to backend/src/cache.py
diff --git a/backend/src/constants.py b/backend/src/constants.py
index 21ed016..303e7ed 100644
--- a/backend/src/constants.py
+++ b/backend/src/constants.py
@@ -1,4 +1,4 @@
-"""Module allowing to access the parameters of route generation"""
+"""Module setting global parameters for the application, such as logging, cache, route generation, etc."""
import logging
import os
@@ -16,19 +16,33 @@ cache_dir_string = os.getenv('OSM_CACHE_DIR', './cache')
OSM_CACHE_DIR = Path(cache_dir_string)
-# if we are in a debug session, set verbose and rich logging
-if os.getenv('DEBUG', "false") == "true":
+# if we are in a debug (local) session, set verbose and rich logging
+debug = os.getenv('DEBUG', "false") == "true"
+if os.getenv('KUBERNETES_SERVICE_HOST', None) is not None:
+ # in that case we want to log to stdout and also to loki
+ from loki_logger_handler.loki_logger_handler import LokiLoggerHandler
+ loki_handler = LokiLoggerHandler(
+ url=os.getenv('LOKI_URL', 'http://loki:3100'),
+ labels={'app': 'anyway', 'env': 'production' if debug else 'staging'}
+ )
+ if debug:
+ logging.basicConfig(
+ level=logging.DEBUG,
+ handlers=[loki_handler, logging.StreamHandler()]
+ )
+ else:
+ logging.basicConfig(
+ level=logging.INFO,
+ handlers=[loki_handler, logging.StreamHandler()]
+ )
+else:
+ # in that case we are local and we want to log to stdout only, but make it pretty
from rich.logging import RichHandler
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[RichHandler()]
)
-else:
- logging.basicConfig(
- level=logging.INFO,
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
- )
MEMCACHED_HOST_PATH = os.getenv('MEMCACHED_HOST_PATH', None)
diff --git a/backend/src/main.py b/backend/src/main.py
index a2efbf1..eea3bad 100644
--- a/backend/src/main.py
+++ b/backend/src/main.py
@@ -11,7 +11,7 @@ from .utils.landmarks_manager import LandmarkManager
from .utils.toilets_manager import ToiletsManager
from .utils.optimizer import Optimizer
from .utils.refiner import Refiner
-from .persistence import client as cache_client
+from .cache import client as cache_client
logger = logging.getLogger(__name__)
diff --git a/backend/src/tests/test_utils.py b/backend/src/tests/test_utils.py
index d5b69ad..73f4ec7 100644
--- a/backend/src/tests/test_utils.py
+++ b/backend/src/tests/test_utils.py
@@ -4,7 +4,7 @@ from fastapi import HTTPException
from pydantic import ValidationError
from ..structs.landmark import Landmark
-from ..persistence import client as cache_client
+from ..cache import client as cache_client
def landmarks_to_osmid(landmarks: list[Landmark]) -> list[int] :