🚧 WIP
This commit is contained in:
@@ -103,11 +103,22 @@ class EventLogConfig:
|
||||
min_severity: str = "WARN" # INFO / WARN / CRITICAL
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class HttpConfig:
|
||||
"""Optional webhook reporter (spec §9): one JSON event per POST."""
|
||||
|
||||
url: str
|
||||
bearer_token: str | None = None
|
||||
timeout_s: float = 5.0
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ReportConfig:
|
||||
heartbeat_s: float = 300.0 # D15
|
||||
jsonl: JsonlConfig = field(default_factory=JsonlConfig)
|
||||
textlog: JsonlConfig = field(default_factory=JsonlConfig) # same knobs: dir/max_mb/backups
|
||||
eventlog: EventLogConfig = field(default_factory=EventLogConfig)
|
||||
http: HttpConfig | None = None # omitted = webhook off
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -183,9 +194,14 @@ def _build_section(cls: type[Any], data: Any, where: str) -> Any:
|
||||
def _build_report(data: Any) -> ReportConfig:
|
||||
data = {} if data is None else dict(data)
|
||||
jsonl = _build_section(JsonlConfig, data.pop("jsonl", None), "report.jsonl")
|
||||
textlog = _build_section(JsonlConfig, data.pop("textlog", None), "report.textlog")
|
||||
eventlog = _build_section(EventLogConfig, data.pop("eventlog", None), "report.eventlog")
|
||||
http_raw = data.pop("http", None)
|
||||
http = None
|
||||
if http_raw is not None:
|
||||
http = _build_section(HttpConfig, http_raw, "report.http")
|
||||
rest = _build_section(ReportConfig, data, "report")
|
||||
return replace(rest, jsonl=jsonl, eventlog=eventlog)
|
||||
return replace(rest, jsonl=jsonl, textlog=textlog, eventlog=eventlog, http=http)
|
||||
|
||||
|
||||
def _build_tags(data: Any) -> tuple[TagEntry, ...]:
|
||||
@@ -328,6 +344,20 @@ def _validate(config: Config) -> None:
|
||||
raise ConfigError(f"report.jsonl.max_mb: must be >= 1, got {config.report.jsonl.max_mb}")
|
||||
if config.report.jsonl.backups < 0:
|
||||
raise ConfigError(f"report.jsonl.backups: must be >= 0, got {config.report.jsonl.backups}")
|
||||
if config.report.textlog.max_mb < 1:
|
||||
raise ConfigError(f"report.textlog.max_mb: must be >= 1, got {config.report.textlog.max_mb}")
|
||||
if config.report.textlog.backups < 0:
|
||||
raise ConfigError(f"report.textlog.backups: must be >= 0, got {config.report.textlog.backups}")
|
||||
if config.report.http is not None:
|
||||
if not config.report.http.url.startswith(("http://", "https://")):
|
||||
raise ConfigError(
|
||||
"report.http.url: must start with http:// or https://, got "
|
||||
f"{config.report.http.url!r}"
|
||||
)
|
||||
if config.report.http.timeout_s <= 0:
|
||||
raise ConfigError(
|
||||
f"report.http.timeout_s: must be > 0, got {config.report.http.timeout_s}"
|
||||
)
|
||||
|
||||
|
||||
def load_config(path: str | Path) -> Config:
|
||||
|
||||
Reference in New Issue
Block a user