Skip to content

Commit 68c504a

Browse files
committed
tests: Allow enabling CMG logging
Introduce the '--enable-cmg-logging' option, to allow setting the logging level for the Gatewat and Scheduler to INFO (default is WARNING). Signed-off-by: Phoevos Kalemkeris <[email protected]>
1 parent 00e4ef7 commit 68c504a

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

tests/conftest.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ def pytest_addoption(parser: pytest.Parser) -> None:
1111
help="Skip cleanup for the CMS resources after completing the tests.",
1212
)
1313

14+
parser.addoption(
15+
"--enable-cmg-logging",
16+
action="store_true",
17+
default=False,
18+
help="Enable logging for the CogStack Model Gateway resources (i.e. Gateway, Scheduler).",
19+
)
20+
1421

1522
@pytest.fixture(scope="module")
1623
def cleanup_cms(request: pytest.FixtureRequest) -> bool:
@@ -24,14 +31,13 @@ def setup_logging() -> None:
2431
if logger_name.startswith("testcontainers"):
2532
logging.getLogger(logger_name).setLevel(logging.WARNING)
2633

27-
parent_logger = logging.getLogger("cmg.tests")
34+
parent_logger = logging.getLogger("cmg")
2835
parent_logger.setLevel(logging.DEBUG)
2936

30-
handler = logging.StreamHandler()
31-
handler.setLevel(logging.DEBUG)
32-
handler.setFormatter(logging.Formatter("%(levelname)s:%(message)s"))
33-
parent_logger.addHandler(handler)
37+
if not any(isinstance(handler, logging.StreamHandler) for handler in parent_logger.handlers):
38+
handler = logging.StreamHandler()
39+
handler.setLevel(logging.DEBUG)
40+
handler.setFormatter(logging.Formatter("%(levelname)s:%(name)s:%(message)s"))
41+
parent_logger.addHandler(handler)
3442

35-
# Configure child loggers
36-
logging.getLogger("cmg.tests.integration").setLevel(logging.INFO)
37-
logging.getLogger("cmg.tests.unit").setLevel(logging.INFO)
43+
logging.getLogger("cmg.tests").setLevel(logging.INFO)

tests/integration/test_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def setup(request: pytest.FixtureRequest, cleanup_cms: bool):
4848
env = {
4949
"MLFLOW_TRACKING_URI": f"http://{mlflow_addr}:{mlflow_port}",
5050
}
51-
configure_environment(postgres, rabbitmq, minio, extras=env)
51+
52+
enable_cmg_logging = request.config.getoption("--enable-cmg-logging")
53+
configure_environment(postgres, rabbitmq, minio, enable_logs=enable_cmg_logging, extras=env)
5254

5355
setup_scheduler(request)
5456

tests/integration/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ def configure_environment(
121121
postgres: PostgresContainer,
122122
rabbitmq: RabbitMqContainer,
123123
minio: MinioContainer,
124+
enable_logs: bool = False,
124125
extras: dict = None,
125126
):
126127
log.info("Setting environment variables...")
128+
cmg_log_level = logging.INFO if enable_logs else logging.WARNING
127129
queue_connection_params = rabbitmq.get_connection_params()
128130
minio_host, minio_port = minio.get_config()["endpoint"].split(":")
129131
env = {
132+
"CMG_COMMON_LOG_LEVEL": logging.getLevelName(logging.WARNING),
133+
"CMG_GATEWAY_LOG_LEVEL": logging.getLevelName(cmg_log_level),
134+
"CMG_SCHEDULER_LOG_LEVEL": logging.getLevelName(cmg_log_level),
130135
"CMG_DB_USER": postgres.username,
131136
"CMG_DB_PASSWORD": postgres.password,
132137
"CMG_DB_HOST": postgres.get_container_host_ip(),
@@ -157,8 +162,6 @@ def start_scheduler():
157162
["poetry", "run", "python3", SCHEDULER_SCRIPT_PATH],
158163
start_new_session=True,
159164
env=dict(os.environ),
160-
stderr=subprocess.DEVNULL,
161-
stdout=subprocess.DEVNULL,
162165
)
163166

164167

0 commit comments

Comments
 (0)