Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions helm/diffcalc-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
env:
- name: mongo_url
value: {{ include "diffcalc-api.mongoUrl" . }}
- name: logging_level
value: {{ .Values.logging.level }}
- name: logging_format
value: {{ .Values.logging.format }}
ports:
- name: http
containerPort: 8000
Expand Down
4 changes: 4 additions & 0 deletions helm/diffcalc-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ mongodb:
cpu: 2
requests:
cpu: 1

logging:
level: "WARN"
format: "[%(asctime)s] %(levelname)s:%(message)s"
43 changes: 29 additions & 14 deletions src/diffcalc_API/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
import logging

from pydantic import BaseSettings

from ._version_git import __version__

release = __version__

# The short X.Y version.
if "+" in release:
# Not on a tag
version = "master"
else:
version = release


class Settings(BaseSettings):
mongo_url: str = "localhost:27017"
api_version = version
logging_level: str = "WARN"
logging_format: str = "[%(asctime)s] %(levelname)s:%(message)s"


settings = Settings()
try:
logging.basicConfig(level=settings.logging_level, format=settings.logging_format)
except ValueError:
logging.basicConfig(level="WARN")
logging.warn(
f"{settings.logging_level} is not a valid logging level "
+ "(See logging python library for details). Initializing basic logging."
)

SAVE_PICKLES_FOLDER = "/"
VECTOR_PROPERTIES = ["n_hkl", "n_phi", "surf_nhkl", "surf_nphi"]
CONSTRAINTS_WITH_NO_VALUE = {"a_eq_b", "bin_eq_bout", "mu_is_gam", "bisect"}
Expand All @@ -26,17 +55,3 @@
"bisect",
"omega",
}

release = __version__

# The short X.Y version.
if "+" in release:
# Not on a tag
version = "master"
else:
version = release


class Settings(BaseSettings):
mongo_url: str = "localhost:27017"
api_version = version
12 changes: 9 additions & 3 deletions src/diffcalc_API/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import traceback
from typing import Optional

Expand All @@ -12,8 +13,8 @@
from diffcalc_API.errors.ub import responses as ub_responses
from diffcalc_API.stores.protocol import get_store, setup_store

logger = logging.getLogger(__name__)
config = Settings()

setup_store("diffcalc_API.stores.mongo.MongoHklCalcStore")

app = FastAPI(
Expand All @@ -31,6 +32,9 @@

@app.exception_handler(DiffcalcException)
async def diffcalc_exception_handler(request: Request, exc: DiffcalcException):
tb = traceback.format_exc()
logger.warn(f"Diffcalc Exception caught by middleware: {tb}")

return responses.JSONResponse(
status_code=400,
content={"message": str(exc), "type": str(type(exc))},
Expand All @@ -39,6 +43,9 @@ async def diffcalc_exception_handler(request: Request, exc: DiffcalcException):

@app.exception_handler(DiffcalcAPIException)
async def http_exception_handler(request: Request, exc: DiffcalcAPIException):
tb = traceback.format_exc()
logger.error(f"Diffcalc API Exception caught by middleware: {tb}")

return responses.JSONResponse(
status_code=exc.status_code,
content={"message": exc.detail, "type": str(type(exc))},
Expand All @@ -50,9 +57,8 @@ async def server_exceptions_middleware(request: Request, call_next):
try:
return await call_next(request)
except Exception as e:
# TODO: implement proper logging
tb = traceback.format_exc()
print(tb)
logger.error(f"General Exception caught by middleware: {tb}")

return responses.JSONResponse(
status_code=500,
Expand Down