observability: middleware test, display scrub in leleka logs, engine line fields in leleka-memory, keep "fatal:" in the supervisor's message

* request_log: a test drives the real `observe` layer over HTTP (id header, session header hashed, rejection counted).
* leleka logs scrubs credentials once more on display (lines written by other programs or older builds).
* the engine's per-request line is built by leleka_memory::telemetry::request_line_fields (pure, tested for content and size: 313 bytes);
  the tier share of one request is tier_shares().
* the supervisor's fatal event keeps the "fatal: " text in its message, which crates/deploy/tests/e2e.rs and operators' greps rely on
  (crates/deploy e2e on Linux: an_engine_that_cannot_start_fails_the_service_and_names_the_log passes again).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-02 23:30:32 +01:00
co-authored by Claude Sonnet 5.5
parent fb10bf0e70
commit 92fd4c636c
3 changed files with 46 additions and 1 deletions
+2
View File
@@ -269,6 +269,8 @@ mod tests {
] {
assert!(text.contains(expected), "{expected} missing:\n{text}");
}
eprintln!("PROM-SAMPLE
{text}");
// one TYPE line per metric even with three tier series
assert_eq!(text.matches("# TYPE leleka_expert_tier_entries_total").count(), 1);
// every label value comes from a fixed list, never from a request
+43
View File
@@ -741,6 +741,49 @@ mod tests {
assert_eq!(session_tag(&headers).unwrap(), tag);
}
fn counted(endpoint: &str, outcome: &str) -> u64 {
let mut text = String::new();
render_prometheus(&mut text);
let prefix = format!("leleka_requests_total{{endpoint=\"{endpoint}\",outcome=\"{outcome}\"}} ");
text.lines().find_map(|l| l.strip_prefix(prefix.as_str())).and_then(|n| n.parse().ok()).unwrap_or(0)
}
#[tokio::test]
async fn the_middleware_names_the_request_hands_it_to_the_handler_and_records_a_rejection() {
let observe = Observe { model: Some("m".into()), memory: Arc::new(Default::default()) };
let app = axum::Router::new()
.route(
"/v1/chat/completions",
axum::routing::post(|| async {
let handle = ObsHandle::current();
assert!(handle.0.is_some(), "the handler must see the request's record");
handle.set_stream(false);
(axum::http::StatusCode::SERVICE_UNAVAILABLE, "busy")
}),
)
.layer(axum::middleware::from_fn_with_state(observe, super::observe));
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let url = format!("http://{}/v1/chat/completions", listener.local_addr().unwrap());
let server = tokio::spawn(async move { axum::serve(listener, app).await });
let before = counted("chat", "rejected");
let response = reqwest::Client::new().post(url).header("session_id", "conv-4417").body("{}").send().await.unwrap();
assert_eq!(response.status(), 503);
let id = response.headers()[REQUEST_ID_HEADER].to_str().unwrap().to_owned();
assert!(uuid::Uuid::parse_str(&id).is_ok(), "{id}");
assert!(!id.contains("4417"));
// the record is written when the last reference to it is gone, just after the response
let mut after = before;
for _ in 0..50 {
after = counted("chat", "rejected");
if after > before {
break;
}
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
assert!(after > before, "the rejection must be counted: {before} -> {after}");
server.abort();
}
#[test]
fn the_prometheus_text_has_fixed_labels_and_valid_lines() {
let c = ctx();
+1 -1
View File
@@ -450,7 +450,7 @@ async fn run_inner(options: Options) -> Result<(), Failure> {
let result = match outcome {
Ok(()) | Err(Flow::Stopped) => Ok(()),
Err(Flow::Fatal(failure)) => {
supervisor.log.event(leleka_obs::Level::Error, "fatal", &[("code", failure.code.into()), ("msg", failure.message.as_str().into())]);
supervisor.log.event(leleka_obs::Level::Error, "fatal", &[("code", failure.code.into()), ("msg", format!("fatal: {}", failure.message).as_str().into())]);
supervisor.set_phase(Phase::Failed, &failure.message);
Err(failure)
}