mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 02:17:46 +08:00
fix(observability): preserve admin upstream error diagnostics
This commit is contained in:
@@ -473,6 +473,23 @@ async fn gateway_handles_admin_monitoring_trace_request_locally_with_trusted_adm
|
||||
}),
|
||||
);
|
||||
|
||||
let mut failed_candidate = sample_candidate(
|
||||
"cand-used",
|
||||
"request-1",
|
||||
1,
|
||||
RequestCandidateStatus::Failed,
|
||||
Some(101),
|
||||
Some(33),
|
||||
Some(502),
|
||||
);
|
||||
failed_candidate.error_message = Some("private upstream diagnostic".to_string());
|
||||
failed_candidate.extra_data = Some(json!({
|
||||
"upstream_response": {
|
||||
"status_code": 502,
|
||||
"headers": {"x-request-id": "upstream-diagnostic-id"},
|
||||
"body": {"error": {"message": "private upstream diagnostic"}}
|
||||
}
|
||||
}));
|
||||
let request_candidates = Arc::new(InMemoryRequestCandidateRepository::seed(vec![
|
||||
sample_candidate(
|
||||
"cand-unused",
|
||||
@@ -483,15 +500,7 @@ async fn gateway_handles_admin_monitoring_trace_request_locally_with_trusted_adm
|
||||
None,
|
||||
None,
|
||||
),
|
||||
sample_candidate(
|
||||
"cand-used",
|
||||
"request-1",
|
||||
1,
|
||||
RequestCandidateStatus::Failed,
|
||||
Some(101),
|
||||
Some(33),
|
||||
Some(502),
|
||||
),
|
||||
failed_candidate,
|
||||
]));
|
||||
let provider_catalog = Arc::new(InMemoryProviderCatalogReadRepository::seed(
|
||||
vec![sample_provider()],
|
||||
@@ -538,6 +547,37 @@ async fn gateway_handles_admin_monitoring_trace_request_locally_with_trusted_adm
|
||||
assert_eq!(payload["candidates"][0]["key_auth_type"], json!("api_key"));
|
||||
assert_eq!(payload["candidates"][0]["latency_ms"], json!(33));
|
||||
assert_eq!(payload["candidates"][0]["status_code"], json!(502));
|
||||
assert_eq!(
|
||||
payload["candidates"][0]["error_message"],
|
||||
"private upstream diagnostic"
|
||||
);
|
||||
assert_eq!(
|
||||
payload["candidates"][0]["extra_data"]["upstream_response"]["body"]["error"]["message"],
|
||||
"private upstream diagnostic"
|
||||
);
|
||||
for role in [None, Some("user")] {
|
||||
let mut request = reqwest::Client::new().get(format!(
|
||||
"{gateway_url}/api/admin/monitoring/trace/request-1"
|
||||
));
|
||||
if let Some(role) = role {
|
||||
request = request
|
||||
.header(crate::constants::GATEWAY_HEADER, "rust-phase3b")
|
||||
.header(TRUSTED_ADMIN_USER_ID_HEADER, "regular-user")
|
||||
.header(TRUSTED_ADMIN_USER_ROLE_HEADER, role)
|
||||
.header(TRUSTED_ADMIN_SESSION_ID_HEADER, "regular-session");
|
||||
}
|
||||
let response = request
|
||||
.send()
|
||||
.await
|
||||
.expect("unauthorized probe should complete");
|
||||
assert!(matches!(
|
||||
response.status(),
|
||||
StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN
|
||||
));
|
||||
let body = response.text().await.expect("denial body should read");
|
||||
assert!(!body.contains("private upstream diagnostic"));
|
||||
assert!(!body.contains("upstream-diagnostic-id"));
|
||||
}
|
||||
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
||||
|
||||
gateway_handle.abort();
|
||||
|
||||
@@ -85,10 +85,7 @@ async fn admin_provider_summary_health_preserves_redacted_key_summaries() {
|
||||
.into_iter()
|
||||
.map(|(key_id, auth_type, auth_config, score)| {
|
||||
let mut key = sample_key(key_id, "provider-openai", "openai:chat", "test")
|
||||
.with_health_fields(
|
||||
Some(json!({"openai:chat": {"health_score": score}})),
|
||||
None,
|
||||
);
|
||||
.with_health_fields(Some(json!({"openai:chat": {"health_score": score}})), None);
|
||||
key.auth_type = auth_type.to_string();
|
||||
key.encrypted_api_key = Some("summary".to_string());
|
||||
key.encrypted_auth_config = auth_config.map(ToOwned::to_owned);
|
||||
@@ -115,7 +112,8 @@ async fn admin_provider_summary_health_preserves_redacted_key_summaries() {
|
||||
let body = axum::body::to_bytes(response.into_body(), 1024 * 1024)
|
||||
.await
|
||||
.expect("summary body should read");
|
||||
let payload: serde_json::Value = serde_json::from_slice(&body).expect("summary should parse");
|
||||
let payload: serde_json::Value =
|
||||
serde_json::from_slice(&body).expect("summary should parse");
|
||||
let summary = if uri == "/api/admin/providers/summary" {
|
||||
&payload["items"][0]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user