Skip to content

Commit 44de3d4

Browse files
refactor(helm)!: Remove all host-path volume mounts. (y-scope#2023)
Co-authored-by: hoophalab <200652805+hoophalab@users.noreply.github.com>
1 parent 7fd21c9 commit 44de3d4

File tree

80 files changed

+185
-993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+185
-993
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/api-server/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ thiserror = "2.0.18"
3636
tokio = { version = "1.49.0", features = ["full"] }
3737
tower-http = { version = "0.6.8", features = ["cors"] }
3838
tracing = "0.1.44"
39-
tracing-appender = "0.2.4"
40-
tracing-subscriber = { version = "0.3.22", features = ["json", "env-filter", "fmt", "std"] }
4139
utoipa = { version = "5.4.0", features = ["axum_extras"] }
4240
utoipa-axum = "0.2.0"

components/api-server/src/bin/api_server.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
use anyhow::Context;
22
use clap::Parser;
33
use clp_rust_utils::{clp_config::package, serde::yaml};
4-
use tracing_appender::{
5-
non_blocking::WorkerGuard,
6-
rolling::{RollingFileAppender, Rotation},
7-
};
8-
use tracing_subscriber::{self, fmt::writer::MakeWriterExt};
94

105
#[derive(Parser)]
116
#[command(version, about = "API Server for CLP.")]
@@ -40,29 +35,6 @@ fn read_config_and_credentials(
4035
Ok((config, credentials))
4136
}
4237

43-
fn set_up_logging() -> anyhow::Result<WorkerGuard> {
44-
let logs_directory =
45-
std::env::var("CLP_LOGS_DIR").context("Expect `CLP_LOGS_DIR` environment variable.")?;
46-
let logs_directory = std::path::Path::new(logs_directory.as_str());
47-
let file_appender =
48-
RollingFileAppender::new(Rotation::HOURLY, logs_directory, "api_server.log");
49-
let (non_blocking_writer, guard) = tracing_appender::non_blocking(file_appender);
50-
tracing_subscriber::fmt()
51-
.event_format(
52-
tracing_subscriber::fmt::format()
53-
.with_level(true)
54-
.with_target(false)
55-
.with_file(true)
56-
.with_line_number(true)
57-
.json(),
58-
)
59-
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
60-
.with_ansi(false)
61-
.with_writer(std::io::stdout.and(non_blocking_writer))
62-
.init();
63-
Ok(guard)
64-
}
65-
6638
async fn shutdown_signal() {
6739
let mut sigterm = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
6840
.expect("failed to listen for SIGTERM");
@@ -79,7 +51,7 @@ async fn main() -> anyhow::Result<()> {
7951
let args = Args::parse();
8052

8153
let (config, credentials) = read_config_and_credentials(&args)?;
82-
let _guard = set_up_logging()?;
54+
let _guard = clp_rust_utils::logging::set_up_logging("api_server.log");
8355

8456
let api_server_config = config
8557
.api_server

components/clp-mcp-server/clp_mcp_server/clp_mcp_server.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""CLP MCP Server entry point."""
22

33
import ipaddress
4-
import logging
5-
import os
64
import socket
75
import sys
86
from pathlib import Path
97

108
import click
119
from clp_py_utils.clp_config import ClpConfig, MCP_SERVER_COMPONENT_NAME
12-
from clp_py_utils.clp_logging import get_logger, get_logging_formatter, set_logging_level
10+
from clp_py_utils.clp_logging import configure_logging, get_logger
1311
from clp_py_utils.core import read_yaml_config_file
1412
from pydantic import ValidationError
1513

@@ -38,12 +36,8 @@ def main(host: str, port: int, config_path: Path) -> int:
3836
:param config_path: The path to server's configuration file.
3937
:return: Exit code (0 for success, non-zero for failure).
4038
"""
41-
# Setup logging to file
42-
log_file_path = Path(os.getenv("CLP_LOGS_DIR")) / "mcp_server.log"
43-
logging_file_handler = logging.FileHandler(filename=log_file_path, encoding="utf-8")
44-
logging_file_handler.setFormatter(get_logging_formatter())
45-
logger.addHandler(logging_file_handler)
46-
set_logging_level(logger, os.getenv("CLP_LOGGING_LEVEL"))
39+
# Setup optional file logging and logging level.
40+
configure_logging(logger, "mcp_server")
4741

4842
exit_code = 0
4943

components/clp-py-utils/clp_py_utils/clp_logging.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import logging
2+
import os
3+
import pathlib
24
from typing import get_args, Literal
35

46
LoggingLevel = Literal[
@@ -26,10 +28,36 @@ def get_logger(name: str):
2628
return logger
2729

2830

29-
def set_logging_level(logger: logging.Logger, level: str):
31+
def set_logging_level(logger: logging.Logger, level: str | None):
32+
if level is None:
33+
logger.setLevel(logging.INFO)
34+
return
3035
if level not in get_args(LoggingLevel):
3136
logger.warning(f"Invalid logging level: {level}, using INFO as default")
3237
logger.setLevel(logging.INFO)
3338
return
3439

3540
logger.setLevel(level)
41+
42+
43+
def configure_logging(
44+
logger: logging.Logger,
45+
component_name: str,
46+
):
47+
"""
48+
Configures file logging and the logging level for a logger using environment variables.
49+
50+
If ``CLP_LOGS_DIR`` is set, a :class:`logging.FileHandler` writing to
51+
``<CLP_LOGS_DIR>/<component_name>.log`` is added to the logger.
52+
``CLP_LOGGING_LEVEL`` is used to set the logging level (defaults to INFO if unset/invalid).
53+
54+
:param logger: The logger to configure.
55+
:param component_name: Used as the log filename stem and in log messages.
56+
"""
57+
logs_dir = os.getenv("CLP_LOGS_DIR")
58+
if logs_dir:
59+
log_file = pathlib.Path(logs_dir) / f"{component_name}.log"
60+
logging_file_handler = logging.FileHandler(filename=log_file, encoding="utf-8")
61+
logging_file_handler.setFormatter(get_logging_formatter())
62+
logger.addHandler(logging_file_handler)
63+
set_logging_level(logger, os.getenv("CLP_LOGGING_LEVEL"))

components/clp-rust-utils/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ serde_yaml = "0.9.34"
1717
sqlx = { version = "0.8.6", features = ["runtime-tokio", "mysql"] }
1818
strum = "0.28.0"
1919
thiserror = "2.0.18"
20+
tracing-appender = "0.2.4"
21+
tracing-subscriber = { version = "0.3.22", features = ["json", "env-filter", "fmt", "std"] }
2022
utoipa = { version = "5.4.0" }
2123

2224
[dev-dependencies]

components/clp-rust-utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod clp_config;
33
pub mod database;
44
mod error;
55
pub mod job_config;
6+
pub mod logging;
67
pub mod s3;
78
pub mod serde;
89
pub mod sqs;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use tracing_appender::{
2+
non_blocking::WorkerGuard,
3+
rolling::{RollingFileAppender, Rotation},
4+
};
5+
use tracing_subscriber::{self, fmt::writer::MakeWriterExt};
6+
7+
/// Initializes the global tracing subscriber with JSON-formatted output to stdout.
8+
///
9+
/// If the `CLP_LOGS_DIR` environment variable is set, logs are also written to a
10+
/// rolling file (`{log_filename}`) in that directory. The returned [`WorkerGuard`]
11+
/// must be held for the lifetime of the program to ensure file logs are flushed.
12+
pub fn set_up_logging(log_filename: &str) -> Option<WorkerGuard> {
13+
let subscriber = tracing_subscriber::fmt()
14+
.event_format(
15+
tracing_subscriber::fmt::format()
16+
.with_level(true)
17+
.with_target(false)
18+
.with_file(true)
19+
.with_line_number(true)
20+
.json(),
21+
)
22+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
23+
.with_ansi(false);
24+
25+
if let Ok(logs_directory) = std::env::var("CLP_LOGS_DIR") {
26+
let logs_directory = std::path::Path::new(logs_directory.as_str());
27+
let file_appender =
28+
RollingFileAppender::new(Rotation::HOURLY, logs_directory, log_filename);
29+
let (non_blocking_writer, guard) = tracing_appender::non_blocking(file_appender);
30+
31+
subscriber
32+
.with_writer(std::io::stdout.and(non_blocking_writer))
33+
.init();
34+
Some(guard)
35+
} else {
36+
subscriber.with_writer(std::io::stdout).init();
37+
None
38+
}
39+
}

components/job-orchestration/job_orchestration/garbage_collector/archive_garbage_collector.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
QUERY_JOBS_TABLE_NAME,
1111
StorageEngine,
1212
)
13-
from clp_py_utils.clp_logging import get_logger
13+
from clp_py_utils.clp_logging import configure_logging, get_logger
1414
from clp_py_utils.clp_metadata_db_utils import (
1515
delete_archives_from_metadata_db,
1616
fetch_existing_datasets,
@@ -24,7 +24,6 @@
2424
SECOND_TO_MILLISECOND,
2525
)
2626
from job_orchestration.garbage_collector.utils import (
27-
configure_logger,
2827
DeletionCandidatesBuffer,
2928
execute_deletion,
3029
validate_storage_type,
@@ -192,10 +191,8 @@ def _collect_and_sweep_expired_archives(
192191
raise ValueError(f"Unsupported Storage engine: {storage_engine}.")
193192

194193

195-
async def archive_garbage_collector(
196-
clp_config: ClpConfig, log_directory: pathlib.Path, logging_level: str
197-
) -> None:
198-
configure_logger(logger, logging_level, log_directory, ARCHIVE_GARBAGE_COLLECTOR_NAME)
194+
async def archive_garbage_collector(clp_config: ClpConfig) -> None:
195+
configure_logging(logger, ARCHIVE_GARBAGE_COLLECTOR_NAME)
199196

200197
archive_output_config = clp_config.archive_output
201198
storage_engine = clp_config.package.storage_engine

components/job-orchestration/job_orchestration/garbage_collector/garbage_collector.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import argparse
44
import asyncio
5-
import os
65
import sys
76
from collections.abc import Callable
87
from pathlib import Path
@@ -11,7 +10,7 @@
1110
ClpConfig,
1211
GARBAGE_COLLECTOR_COMPONENT_NAME,
1312
)
14-
from clp_py_utils.clp_logging import get_logger
13+
from clp_py_utils.clp_logging import configure_logging, get_logger
1514
from clp_py_utils.core import read_yaml_config_file
1615
from pydantic import ValidationError
1716

@@ -23,7 +22,6 @@
2322
from job_orchestration.garbage_collector.search_result_garbage_collector import (
2423
search_result_garbage_collector,
2524
)
26-
from job_orchestration.garbage_collector.utils import configure_logger
2725

2826
logger = get_logger(GARBAGE_COLLECTOR_COMPONENT_NAME)
2927

@@ -35,10 +33,8 @@ async def main(argv: list[str]) -> int:
3533
args_parser.add_argument("--config", "-c", required=True, help="CLP configuration file.")
3634
parsed_args = args_parser.parse_args(argv[1:])
3735

38-
# Setup logging to file
39-
logs_directory = Path(os.getenv("CLP_LOGS_DIR"))
40-
logging_level = os.getenv("CLP_LOGGING_LEVEL")
41-
configure_logger(logger, logging_level, logs_directory, GARBAGE_COLLECTOR_COMPONENT_NAME)
36+
# Setup optional file logging and logging level.
37+
configure_logging(logger, GARBAGE_COLLECTOR_COMPONENT_NAME)
4238

4339
# Load configuration
4440
config_path = Path(parsed_args.config)
@@ -52,7 +48,7 @@ async def main(argv: list[str]) -> int:
5248
logger.exception("Failed to parse CLP configuration file.")
5349
return 1
5450

55-
gc_task_configs: dict[str, tuple[int | None, Callable]] = {
51+
gc_task_configs: dict[str, tuple[int | None, Callable[[ClpConfig], None]]] = {
5652
ARCHIVE_GARBAGE_COLLECTOR_NAME: (
5753
clp_config.archive_output.retention_period,
5854
archive_garbage_collector,
@@ -70,11 +66,7 @@ async def main(argv: list[str]) -> int:
7066
logger.info(f"Retention period is not configured, skip creating {gc_name}.")
7167
continue
7268
logger.info(f"Creating {gc_name} with retention period = {retention_period} minutes")
73-
gc_tasks.append(
74-
asyncio.create_task(
75-
task_method(clp_config, logs_directory, logging_level), name=gc_name
76-
)
77-
)
69+
gc_tasks.append(asyncio.create_task(task_method(clp_config), name=gc_name))
7870

7971
# Poll and report any task that finished unexpectedly
8072
while len(gc_tasks) != 0:

0 commit comments

Comments
 (0)