mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
Expose ranking metadata in request trace
This commit is contained in:
@@ -358,6 +358,66 @@ async fn admin_monitoring_trace_request_enriches_proxy_timing_from_usage_audit()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn admin_monitoring_trace_request_exposes_structured_ranking_metadata() {
|
||||
let mut candidate = sample_candidate(
|
||||
"cand-used",
|
||||
"request-1",
|
||||
0,
|
||||
RequestCandidateStatus::Success,
|
||||
Some(101),
|
||||
Some(33),
|
||||
Some(200),
|
||||
);
|
||||
candidate.extra_data = Some(json!({
|
||||
"ranking_mode": "CacheAffinity",
|
||||
"priority_mode": "Provider",
|
||||
"ranking_index": 0,
|
||||
"priority_slot": 7,
|
||||
"promoted_by": "cached_affinity",
|
||||
"demoted_by": "cross_format",
|
||||
"client_api_format": "openai:responses"
|
||||
}));
|
||||
|
||||
let request_candidates = Arc::new(InMemoryRequestCandidateRepository::seed(vec![candidate]));
|
||||
let provider_catalog = Arc::new(InMemoryProviderCatalogReadRepository::seed(
|
||||
vec![sample_provider()],
|
||||
vec![sample_endpoint()],
|
||||
vec![sample_key()],
|
||||
));
|
||||
let state = AppState::new()
|
||||
.expect("state should build")
|
||||
.with_decision_trace_data_readers_for_tests(request_candidates, provider_catalog);
|
||||
let context = request_context(http::Method::GET, "/api/admin/monitoring/trace/request-1");
|
||||
|
||||
let response = local_monitoring_response(&state, &context)
|
||||
.await
|
||||
.expect("handler should not error")
|
||||
.expect("route should be handled locally");
|
||||
|
||||
assert_eq!(response.status(), http::StatusCode::OK);
|
||||
let body = to_bytes(response.into_body(), usize::MAX)
|
||||
.await
|
||||
.expect("body should read");
|
||||
let payload: serde_json::Value = serde_json::from_slice(&body).expect("json body should parse");
|
||||
|
||||
assert_eq!(
|
||||
payload["candidates"][0]["ranking"],
|
||||
json!({
|
||||
"mode": "CacheAffinity",
|
||||
"priority_mode": "Provider",
|
||||
"index": 0,
|
||||
"priority_slot": 7,
|
||||
"promoted_by": "cached_affinity",
|
||||
"demoted_by": "cross_format"
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
payload["candidates"][0]["extra_data"]["ranking_mode"],
|
||||
json!("CacheAffinity")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn admin_monitoring_trace_provider_stats_returns_local_payload() {
|
||||
let request_candidates = Arc::new(InMemoryRequestCandidateRepository::seed(vec![
|
||||
|
||||
Reference in New Issue
Block a user