Skip to content

feat: factory settings#925

Open
chaen wants to merge 1 commit into
DIRACGrid:mainfrom
chaen:feat_factory_settings
Open

feat: factory settings#925
chaen wants to merge 1 commit into
DIRACGrid:mainfrom
chaen:feat_factory_settings

Conversation

@chaen

@chaen chaen commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Closes #894

Introduce FactorySettings to centralize shared global configuration that does not belong to a single service settings class.

Changes:

  • add FactorySettings
  • update consumers across routers, tasks, and DB helpers
  • extend settings docs generation to include FactorySettings

In principle, that change should be transparent

@read-the-docs-community

read-the-docs-community Bot commented Jun 1, 2026

Copy link
Copy Markdown

@aldbr aldbr linked an issue Jun 1, 2026 that may be closed by this pull request
@chaen chaen force-pushed the feat_factory_settings branch from aedbf8a to 18d7e66 Compare June 3, 2026 09:59
@chaen chaen force-pushed the feat_factory_settings branch from d7b1d17 to 29c5f90 Compare June 10, 2026 12:52
@chaen chaen changed the title Feat factory settings feat: factory settings Jun 10, 2026
@chaen chaen force-pushed the feat_factory_settings branch 5 times, most recently from d9f369d to 427a9ef Compare June 30, 2026 13:04
@chaen chaen marked this pull request as ready for review June 30, 2026 13:19
Comment thread diracx-db/src/diracx/db/os/utils.py Outdated
Comment thread diracx-db/src/diracx/db/os/utils.py Outdated
Comment thread diracx-db/src/diracx/db/os/utils.py Outdated
in FactorySettings, which reads from environment variables
prefixed with ``DIRACX_DB_URL_{DB_NAME}``.
"""
from diracx.core.settings import FactorySettings

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be protected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not, I'll try

Comment thread diracx-db/src/diracx/db/sql/utils/base.py Outdated
Comment thread diracx-db/src/diracx/db/sql/utils/base.py Outdated

DEFAULT_REDIS_URL = "redis://localhost"
REDIS_URL_ENV_VAR = "DIRACX_TASKS_REDIS_URL"
_factory_settings = FactorySettings()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one global but the other use cases aren't. We should decide one or the other.

I wonder if a global instance in settings.py makes more sense...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we tried hard to avoid global variable. I did not want to introduce any.
This one here is a bit special in the sense that this file is pretty much a script so I felt like it was okay.

type=str,
default=None,
help=f"Redis URL (default: ${REDIS_URL_ENV_VAR} or {DEFAULT_REDIS_URL})",
help=f"Redis URL (default: ${{REDIS_URL_ENV_VAR}} or {DEFAULT_REDIS_URL})",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the double braces?

type=str,
default=None,
help=f"Redis URL (default: ${REDIS_URL_ENV_VAR} or {DEFAULT_REDIS_URL})",
help=f"Redis URL (default: ${{REDIS_URL_ENV_VAR}} or {DEFAULT_REDIS_URL})",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto = "abc"; print(f"a literal for the environment variable ${{toto}} while here I want the value of a python variable {toto=}" )
a literal for the environment variable ${toto} while here I want the value of a python variable toto='abc'

@pytest.fixture(scope="session")
def test_factory_settings() -> Generator[FactorySettings, None, None]:

from diracx.core.settings import FactorySettings

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be protected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here I just blindly reapplied the same pattern as the other fixtures.

settings = AuthSettings()
db_url = os.environ["DIRACX_DB_URL_AUTHDB"]
factory_settings = FactorySettings()
db_url = factory_settings.sql_dbs.AuthDB

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
db_url = factory_settings.sql_dbs.AuthDB
db_url = factory_settings.sql_dbs["AuthDB"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I wonder why this one was not spotted by the static analyzer 🤔

# Try to connect to Redis for lock acquisition
redis: LockCoordinator | None = None
redis_url = os.environ.get(REDIS_URL_ENV_VAR)
redis_url = _factory_settings.tasks_redis_url

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be optional now if redis_url: is always true.

I haven't checked in detail to figure out what the correct behavoir is

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was always needed

use_attribute_docstrings=True, validate_by_alias=True, validate_by_name=True
)

config_backend_url: ConfigSourceUrl | None = Field(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be mandatory, maybe it still should be?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i made it non mandatory because of things like the OpenSearch init jobs that do not need that

@chaen chaen force-pushed the feat_factory_settings branch from 427a9ef to 16c70c9 Compare June 30, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Introduce FactorySettings

2 participants