feat: JSON-Logging mit Correlation-ID, Anfrage-Log und Audit (M2.4)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -16,7 +16,7 @@ use serde::Deserialize;
|
||||
use tokio::process::{Child, Command};
|
||||
|
||||
use crate::engine::Engine;
|
||||
use crate::process::{PortPool, http_status, log_tail, sigterm};
|
||||
use crate::process::{PortPool, http_status, log_tail, rotate_log, sigterm};
|
||||
use crate::types::{
|
||||
AdapterError, Capabilities, DiscoveredArtifact, Endpoint, EngineInfo, Health, InstanceHandle,
|
||||
Mode, ProfileSpec, Protocol, Result, Usage,
|
||||
@ -39,6 +39,8 @@ pub struct LlamaCppConfig {
|
||||
pub log_dir: PathBuf,
|
||||
/// Anzahl der Schichten auf der GPU (`-ngl`).
|
||||
pub gpu_layers: i32,
|
||||
/// Wie viele aufgehobene Logs älterer Läufe erhalten bleiben.
|
||||
pub log_keep: usize,
|
||||
/// Zusätzliche Argumente für jeden Start.
|
||||
pub extra_args: Vec<String>,
|
||||
/// Zusätzliche Umgebungsvariablen (keine Geheimnisse).
|
||||
@ -57,6 +59,7 @@ impl Default for LlamaCppConfig {
|
||||
ready_timeout_secs: 120,
|
||||
log_dir: PathBuf::from("data/logs"),
|
||||
gpu_layers: 99,
|
||||
log_keep: 10,
|
||||
extra_args: Vec::new(),
|
||||
env: BTreeMap::new(),
|
||||
nvidia_smi: PathBuf::from("nvidia-smi"),
|
||||
@ -162,6 +165,9 @@ impl LlamaCppEngine {
|
||||
path: log_path.clone(),
|
||||
source,
|
||||
};
|
||||
// Ein Neustart überschreibt keine alten Logs: Sie werden aufgehoben,
|
||||
// die ältesten über `log_keep` hinaus gelöscht.
|
||||
rotate_log(&log_path, self.config.log_keep).map_err(io_err)?;
|
||||
let log = std::fs::File::create(&log_path).map_err(io_err)?;
|
||||
let log_err = log.try_clone().map_err(io_err)?;
|
||||
|
||||
@ -180,6 +186,11 @@ impl LlamaCppEngine {
|
||||
let started = Instant::now();
|
||||
loop {
|
||||
if let Ok(Some(status)) = child.try_wait() {
|
||||
tracing::warn!(
|
||||
instance_id = id,
|
||||
exit_code = status.code(),
|
||||
"llama-server endete beim Start"
|
||||
);
|
||||
return Err(AdapterError::ExitedEarly {
|
||||
code: status.code(),
|
||||
log_tail: log_tail(&log_path, 20),
|
||||
@ -189,6 +200,11 @@ impl LlamaCppEngine {
|
||||
break;
|
||||
}
|
||||
if started.elapsed() >= timeout {
|
||||
tracing::warn!(
|
||||
instance_id = id,
|
||||
seconds = self.config.ready_timeout_secs,
|
||||
"llama-server wurde nicht rechtzeitig bereit"
|
||||
);
|
||||
let _ = child.start_kill();
|
||||
let _ = child.wait().await;
|
||||
return Err(AdapterError::NotReady {
|
||||
@ -277,6 +293,10 @@ impl Engine for LlamaCppEngine {
|
||||
}
|
||||
let exited = tokio::time::timeout(grace, managed.child.wait()).await;
|
||||
if exited.is_err() {
|
||||
tracing::warn!(
|
||||
instance_id = instance.id,
|
||||
"llama-server reagierte nicht auf SIGTERM, wird beendet"
|
||||
);
|
||||
managed
|
||||
.child
|
||||
.kill()
|
||||
@ -294,7 +314,12 @@ impl Engine for LlamaCppEngine {
|
||||
return Health::Gone;
|
||||
};
|
||||
match managed.child.try_wait() {
|
||||
Ok(Some(_)) => {
|
||||
Ok(Some(status)) => {
|
||||
tracing::warn!(
|
||||
instance_id = instance.id,
|
||||
exit_code = status.code(),
|
||||
"llama-server ist von selbst beendet"
|
||||
);
|
||||
let port = managed.port;
|
||||
children.remove(&instance.id);
|
||||
self.ports.release(port);
|
||||
|
||||
Reference in New Issue
Block a user