Add artifact.data_logger/src/artifact_data_logger/cli.py
This commit is contained in:
parent
ac5ede1aef
commit
63979723fe
1 changed files with 60 additions and 0 deletions
60
artifact.data_logger/src/artifact_data_logger/cli.py
Normal file
60
artifact.data_logger/src/artifact_data_logger/cli.py
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
|
# Lokaler Import des Moduls, das log_metrics enthält
|
||||||
|
from artifact_data_logger.core import log_metrics
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI-Interface zum Protokollieren von Mix-Freeze-Metriken.
|
||||||
|
|
||||||
|
Liest Argumente --run-id und --metrics-file, validiert Eingaben,
|
||||||
|
lädt JSON-Inhalt und ruft log_metrics(run_id, metrics) auf.
|
||||||
|
"""
|
||||||
|
parser = argparse.ArgumentParser(description="Mix Freeze Metric Logger CLI")
|
||||||
|
parser.add_argument("--run-id", required=True, help="Kennung des Runs (z. B. '40')")
|
||||||
|
parser.add_argument(
|
||||||
|
"--metrics-file", required=True, help="Pfad zur JSON-Datei mit Preflight-Metriken."
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
run_id: str = args.run_id.strip()
|
||||||
|
metrics_path = Path(args.metrics_file)
|
||||||
|
|
||||||
|
# Validation: Existenz und Struktur prüfen
|
||||||
|
if not metrics_path.exists():
|
||||||
|
console.print(f"[red]Fehler:[/red] Metrics-Datei '{metrics_path}' nicht gefunden.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with metrics_path.open("r", encoding="utf-8") as f:
|
||||||
|
metrics = json.load(f)
|
||||||
|
except json.JSONDecodeError as err:
|
||||||
|
console.print(f"[red]Fehler beim Einlesen von JSON:[/red] {err}")
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
# Simple structure validation (input_validation_required)
|
||||||
|
required_keys = {"setup_fingerprint", "policy_hash", "epoch_ms", "near_expiry_unpinned"}
|
||||||
|
missing = required_keys - metrics.keys()
|
||||||
|
if missing:
|
||||||
|
console.print(f"[red]Fehlende Schlüssel im Metrics-JSON:[/red] {', '.join(missing)}")
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
|
# Lauf-Startzeit für Nachvollziehbarkeit
|
||||||
|
console.print(f"[green]Starte Logging für Run {run_id} um {datetime.utcnow().isoformat()}Z[/green]")
|
||||||
|
|
||||||
|
try:
|
||||||
|
log_metrics(run_id, metrics)
|
||||||
|
except Exception as exc:
|
||||||
|
console.print(f"[red]Fehler beim Loggen der Metriken:[/red] {exc}")
|
||||||
|
sys.exit(4)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue