Better error reporting when DB_URL env variables are missing
- Dominant language
- Python
- Stars
- 19
- Forks
- 45
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 12
Description
### Current behavior
Database connection URLs are read from environment variables (DIRACX_DB_URL_ for SQL databases, DIRACX_OS_DB_ for OpenSearch ones). When one of them is not set, the database is silently dropped during discovery, and the errors that
eventually surface never mention the environment variable the operator needs to set:
1. build_sql_dbs / build_opensearch_dbs (diracx-core/src/diracx/core/settings.py) assign an empty URL to every DB entry point whose env variable is unset, and BaseSQLDB.available_urls() (diracx-db/src/diracx/db/sql/utils/base.py) /
BaseOSDB.available_urls() (diracx-db/src/diracx/db/os/utils.py) skip empty entries without logging anything.
2. If an enabled service depends on the missing DB, startup fails in create_app_inner (diracx-routers/src/diracx/routers/factory.py) with:
`NotImplementedError: Cannot enable system_name='jobs' as it requires missing_sql_dbs={}`
2. This names the Python class, not the fix. The operator has to know the `JobDB → DIRACX_DB_URL_JOBDB` convention to act on it.
3. If no SQL DB URL is set at all, startup fails with Exception("No SQL database could be initialized, aborting"), again without mentioning environment variables.
Malformed URLs are already handled reasonably (Error loading URL for is logged before the validation error is re-raised); this issue is only about missing variables.
Deployments using the helm chart generate these variables automatically, so this mostly affects people running services directly (development setups, debugging, bare installs) — which is exactly the audience that has to interpret these errors.
### Proposed changes
- In BaseSQLDB.available_urls() and BaseOSDB.available_urls(), log a warning for each DB entry point that was discovered but has no URL configured, naming the exact environment variable, e.g. JobDB was found but has no connection URL: set
DIRACX_DB_URL_JOBDB to enable it.
- In create_app_inner, extend the two startup errors ("Cannot enable system…" and "No SQL database could be initialized") with the same hint, listing the expected variable name(s) for the missing DB(s).
### Definition of Done
- [ ] Starting a service whose DB env variable is unset produces an error message that contains the literal environment variable name to set (e.g. DIRACX_DB_URL_JOBDB).
- [ ] Starting with no DB URLs configured at all produces an error explaining that connection URLs are provided via DIRACX_DB_URL_ / DIRACX_OS_DB_ variables.
- [ ] DBs that are discovered but unconfigured are logged (warning level) at startup instead of being silently skipped, for both SQL and OpenSearch databases.
- [ ] Behavior is covered by tests (missing single DB, no DBs at all, OpenSearch variant) if possible.
- [ ] Malformed-URL error handling is unchanged.
Contributor guide
Assessment
This issue has not been assessed yet.