Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OLS-1308: environment variable with config file on one place #219

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 ols/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,7 @@ class GenericLLMParameters:

# Default configuration file name
DEFAULT_CONFIGURATION_FILE = "rcsconfig.yaml"

# Environment variable containing configuration file name to override default
# configuration file
CONFIGURATION_FILE_NAME_ENV_VARIABLE = "RCS_CONFIG_FILE"
9 changes: 7 additions & 2 deletions ols/user_data_collection/data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@

# initialize config
from ols import config # pylint: disable=C0413
from ols.constants import DEFAULT_CONFIGURATION_FILE # pylint: disable=C0413
from ols.constants import ( # pylint: disable=C0413
CONFIGURATION_FILE_NAME_ENV_VARIABLE,
DEFAULT_CONFIGURATION_FILE,
)

cfg_file = os.environ.get("RCS_CONFIG_FILE", DEFAULT_CONFIGURATION_FILE)
cfg_file = os.environ.get(
CONFIGURATION_FILE_NAME_ENV_VARIABLE, DEFAULT_CONFIGURATION_FILE
)
config.reload_from_yaml_file(
cfg_file, ignore_llm_secrets=True, ignore_missing_certs=True
)
Expand Down
9 changes: 7 additions & 2 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import threading
from pathlib import Path

from ols.constants import DEFAULT_CONFIGURATION_FILE
from ols.constants import (
CONFIGURATION_FILE_NAME_ENV_VARIABLE,
DEFAULT_CONFIGURATION_FILE,
)
from ols.runners.uvicorn import start_uvicorn
from ols.src.auth.auth import use_k8s_auth
from ols.utils.certificates import generate_certificates_file
Expand Down Expand Up @@ -35,7 +38,9 @@ def load_index():
# else via our code before other envs are set (mainly the gradio).
from ols import config

cfg_file = os.environ.get("RCS_CONFIG_FILE", DEFAULT_CONFIGURATION_FILE)
cfg_file = os.environ.get(
CONFIGURATION_FILE_NAME_ENV_VARIABLE, DEFAULT_CONFIGURATION_FILE
)
config.reload_from_yaml_file(cfg_file)

configure_logging(config.ols_config.logging_config)
Expand Down
9 changes: 7 additions & 2 deletions scripts/generate_openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
)

from ols import config # pylint: disable=C0413
from ols.constants import DEFAULT_CONFIGURATION_FILE
from ols.constants import (
CONFIGURATION_FILE_NAME_ENV_VARIABLE,
DEFAULT_CONFIGURATION_FILE,
)

# it is needed to read proper configuration in order to start the app to generate schema
cfg_file = os.environ.get("RCS_CONFIG_FILE", "scripts/" + DEFAULT_CONFIGURATION_FILE)
cfg_file = os.environ.get(
CONFIGURATION_FILE_NAME_ENV_VARIABLE, "scripts/" + DEFAULT_CONFIGURATION_FILE
)
config.reload_from_yaml_file(cfg_file)

from ols.app.main import app # noqa: E402 pylint: disable=C0413
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_liveness_readiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from fastapi.testclient import TestClient

from ols import config
from ols.constants import CONFIGURATION_FILE_NAME_ENV_VARIABLE

client: TestClient

Expand All @@ -16,7 +17,10 @@
# config file before we import anything from main.py
@pytest.fixture(scope="function", autouse=True)
@patch.dict(
os.environ, {"RCS_CONFIG_FILE": "tests/config/config_for_integration_tests.yaml"}
os.environ,
{
CONFIGURATION_FILE_NAME_ENV_VARIABLE: "tests/config/config_for_integration_tests.yaml"
},
)
def _setup():
"""Setups the test client."""
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from ols import config
from ols.app.models.config import LoggingConfig
from ols.constants import CONFIGURATION_FILE_NAME_ENV_VARIABLE
from ols.utils.logging_configurator import configure_logging

client: TestClient
Expand All @@ -31,7 +32,10 @@
# config file before we import anything from main.py
@pytest.fixture(scope="function", autouse=True)
@patch.dict(
os.environ, {"RCS_CONFIG_FILE": "tests/config/config_for_integration_tests.yaml"}
os.environ,
{
CONFIGURATION_FILE_NAME_ENV_VARIABLE: "tests/config/config_for_integration_tests.yaml"
},
)
def _setup():
"""Setups the test client."""
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from fastapi.testclient import TestClient

from ols import config
from ols.constants import CONFIGURATION_FILE_NAME_ENV_VARIABLE

client: TestClient

Expand All @@ -17,7 +18,10 @@
# config file before we import anything from main.py
@pytest.fixture(scope="function", autouse=True)
@patch.dict(
os.environ, {"RCS_CONFIG_FILE": "tests/config/config_for_integration_tests.yaml"}
os.environ,
{
CONFIGURATION_FILE_NAME_ENV_VARIABLE: "tests/config/config_for_integration_tests.yaml"
},
)
def _setup():
"""Setups the test client."""
Expand Down
Loading