fix: Aufrufe der Oberfläche nicht als API-Anfragen zählen, Diagnose-Ordner zufällig und exklusiv anlegen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -134,7 +134,10 @@ pub async fn observe(
|
|||||||
"Anfrage beantwortet"
|
"Anfrage beantwortet"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if !info.deferred {
|
// Die Oberfläche lädt sich alle paar Sekunden selbst neu; ihre Aufrufe
|
||||||
|
// gehören nicht in die Zählung der API-Anfragen.
|
||||||
|
let counted = !path.starts_with("/ui");
|
||||||
|
if !info.deferred && counted {
|
||||||
state.runtime.metrics.record_request(
|
state.runtime.metrics.record_request(
|
||||||
info.metric_model.as_deref().unwrap_or("-"),
|
info.metric_model.as_deref().unwrap_or("-"),
|
||||||
status,
|
status,
|
||||||
|
|||||||
@ -1164,3 +1164,16 @@ async fn status_endpunkt_fuer_ui_und_metrik_keys() {
|
|||||||
assert!(v["totals"]["requests"].is_u64());
|
assert!(v["totals"]["requests"].is_u64());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn aufrufe_der_oberflaeche_zaehlen_nicht_als_api_anfragen() {
|
||||||
|
let gw = gateway(0, false).await;
|
||||||
|
let cookie = ui_cookie(&gw).await;
|
||||||
|
for _ in 0..5 {
|
||||||
|
ui_get(&gw, "/ui/teil/uebersicht", Some(&cookie)).await;
|
||||||
|
}
|
||||||
|
ui_get(&gw, "/ui", Some(&cookie)).await;
|
||||||
|
assert_eq!(gw.state.runtime.metrics.totals().requests, 0);
|
||||||
|
gw.get("/v1/models", Some(&gw.key)).await;
|
||||||
|
assert_eq!(gw.state.runtime.metrics.totals().requests, 1);
|
||||||
|
}
|
||||||
|
|||||||
@ -55,8 +55,16 @@ fn run(args: &[String]) -> Result<String, String> {
|
|||||||
!flags.has("ohne-engine-logs"),
|
!flags.has("ohne-engine-logs"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let staging = std::env::temp_dir().join(format!("nexus-diag-{}", std::process::id()));
|
// Zufälliger Name und exklusives Anlegen: Ein vorher angelegter Ordner oder
|
||||||
let _ = std::fs::remove_dir_all(&staging);
|
// Verweis eines anderen Benutzers in /tmp wird nicht benutzt.
|
||||||
|
let suffix = nexus_core::random_hex(8).map_err(|e| e.to_string())?;
|
||||||
|
let staging = std::env::temp_dir().join(format!("nexus-diag-{suffix}"));
|
||||||
|
std::fs::create_dir(&staging).map_err(|e| format!("{}: {e}", staging.display()))?;
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
let _ = std::fs::set_permissions(&staging, std::fs::Permissions::from_mode(0o700));
|
||||||
|
}
|
||||||
for (name, content) in &files {
|
for (name, content) in &files {
|
||||||
let path = staging.join(name);
|
let path = staging.join(name);
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
|
|||||||
Reference in New Issue
Block a user