mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
refactor: 抽离 AI pipeline 与调度共享能力逻辑
This commit is contained in:
@@ -289,6 +289,8 @@ pub fn build_admin_monitoring_trace_request_candidate_payload(
|
||||
"provider_id": candidate.provider_id,
|
||||
"provider_name": item.provider_name,
|
||||
"provider_website": item.provider_website,
|
||||
"provider_priority": item.provider_priority,
|
||||
"provider_keep_priority_on_conversion": item.provider_keep_priority_on_conversion,
|
||||
"endpoint_id": candidate.endpoint_id,
|
||||
"endpoint_name": item.endpoint_api_format,
|
||||
"key_id": candidate.key_id,
|
||||
@@ -296,6 +298,8 @@ pub fn build_admin_monitoring_trace_request_candidate_payload(
|
||||
"key_account_label": serde_json::Value::Null,
|
||||
"key_preview": serde_json::Value::Null,
|
||||
"key_auth_type": item.provider_key_auth_type,
|
||||
"key_internal_priority": item.provider_key_internal_priority,
|
||||
"key_global_priority_by_format": item.provider_key_global_priority_by_format,
|
||||
"key_oauth_plan_type": serde_json::Value::Null,
|
||||
"key_capabilities": item.provider_key_capabilities,
|
||||
"required_capabilities": candidate.required_capabilities,
|
||||
@@ -308,9 +312,9 @@ pub fn build_admin_monitoring_trace_request_candidate_payload(
|
||||
"latency_ms": candidate.latency_ms,
|
||||
"concurrent_requests": candidate.concurrent_requests,
|
||||
"extra_data": candidate.extra_data,
|
||||
"created_at": unix_secs_to_rfc3339(candidate.created_at_unix_secs),
|
||||
"started_at": candidate.started_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
"finished_at": candidate.finished_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
"created_at": unix_ms_to_rfc3339(candidate.created_at_unix_ms),
|
||||
"started_at": candidate.started_at_unix_ms.and_then(unix_ms_to_rfc3339),
|
||||
"finished_at": candidate.finished_at_unix_ms.and_then(unix_ms_to_rfc3339),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -745,9 +749,11 @@ fn path_identifier_from_path(request_path: &str, prefix: &str) -> Option<String>
|
||||
}
|
||||
}
|
||||
|
||||
fn unix_secs_to_rfc3339(unix_secs: u64) -> Option<String> {
|
||||
chrono::DateTime::<chrono::Utc>::from_timestamp(unix_secs as i64, 0)
|
||||
.map(|value| value.to_rfc3339_opts(chrono::SecondsFormat::Secs, true))
|
||||
fn unix_ms_to_rfc3339(unix_ms: u64) -> Option<String> {
|
||||
let secs = (unix_ms / 1000) as i64;
|
||||
let nanos = ((unix_ms % 1000) * 1_000_000) as u32;
|
||||
chrono::DateTime::<chrono::Utc>::from_timestamp(secs, nanos)
|
||||
.map(|value| value.to_rfc3339_opts(chrono::SecondsFormat::Millis, true))
|
||||
}
|
||||
|
||||
fn query_param_value(query: Option<&str>, key: &str) -> Option<String> {
|
||||
|
||||
@@ -862,7 +862,7 @@ pub fn build_admin_stats_error_distribution_response(
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let Some(local_day) = time_range.local_date_string_for_unix_secs(item.created_at_unix_secs)
|
||||
let Some(local_day) = time_range.local_date_string_for_unix_secs(item.created_at_unix_ms)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
@@ -927,7 +927,7 @@ pub fn build_admin_stats_performance_percentiles_response(
|
||||
if item.status != "completed" {
|
||||
continue;
|
||||
}
|
||||
let Some(local_day) = time_range.local_date_string_for_unix_secs(item.created_at_unix_secs)
|
||||
let Some(local_day) = time_range.local_date_string_for_unix_secs(item.created_at_unix_ms)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
@@ -1078,7 +1078,7 @@ pub fn build_daily_time_series_buckets(
|
||||
.collect();
|
||||
|
||||
for item in items {
|
||||
let Some(local_day) = time_range.local_date_for_unix_secs(item.created_at_unix_secs) else {
|
||||
let Some(local_day) = time_range.local_date_for_unix_secs(item.created_at_unix_ms) else {
|
||||
continue;
|
||||
};
|
||||
let Some(bucket) = buckets.get_mut(&local_day) else {
|
||||
@@ -1173,7 +1173,7 @@ fn build_hourly_time_series_payload(
|
||||
}
|
||||
|
||||
for item in items {
|
||||
let Some(unix_secs) = i64::try_from(item.created_at_unix_secs).ok() else {
|
||||
let Some(unix_secs) = i64::try_from(item.created_at_unix_ms).ok() else {
|
||||
continue;
|
||||
};
|
||||
let Some(timestamp) = chrono::DateTime::<Utc>::from_timestamp(unix_secs, 0) else {
|
||||
|
||||
@@ -266,7 +266,7 @@ pub fn admin_usage_record_json(
|
||||
"rate_multiplier": Value::Null,
|
||||
"response_time_ms": item.response_time_ms,
|
||||
"first_byte_time_ms": item.first_byte_time_ms,
|
||||
"created_at": unix_secs_to_rfc3339(item.created_at_unix_secs),
|
||||
"created_at": unix_secs_to_rfc3339(item.created_at_unix_ms),
|
||||
"is_stream": item.is_stream,
|
||||
"input_price_per_1m": Value::Null,
|
||||
"output_price_per_1m": item.output_price_per_1m,
|
||||
@@ -537,11 +537,11 @@ pub fn admin_usage_heatmap_json(usage: &[StoredRequestUsageAudit]) -> Value {
|
||||
.unwrap_or(today);
|
||||
let mut grouped: BTreeMap<chrono::NaiveDate, (u64, u64, f64, f64)> = BTreeMap::new();
|
||||
for item in usage {
|
||||
let Ok(created_at_unix_secs) = i64::try_from(item.created_at_unix_secs) else {
|
||||
let Ok(created_at_unix_ms) = i64::try_from(item.created_at_unix_ms) else {
|
||||
continue;
|
||||
};
|
||||
let Some(created_at) =
|
||||
chrono::DateTime::<chrono::Utc>::from_timestamp(created_at_unix_secs, 0)
|
||||
chrono::DateTime::<chrono::Utc>::from_timestamp(created_at_unix_ms, 0)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
@@ -631,13 +631,13 @@ pub fn admin_usage_group_completed_by_api_key(
|
||||
pub fn admin_usage_collect_request_intervals_minutes(
|
||||
items: &[StoredRequestUsageAudit],
|
||||
) -> Vec<f64> {
|
||||
let mut previous_created_at_unix_secs = None;
|
||||
let mut previous_created_at_unix_ms = None;
|
||||
let mut intervals = Vec::new();
|
||||
for item in items {
|
||||
if let Some(previous) = previous_created_at_unix_secs {
|
||||
intervals.push(item.created_at_unix_secs.saturating_sub(previous) as f64 / 60.0);
|
||||
if let Some(previous) = previous_created_at_unix_ms {
|
||||
intervals.push(item.created_at_unix_ms.saturating_sub(previous) as f64 / 60.0);
|
||||
}
|
||||
previous_created_at_unix_secs = Some(item.created_at_unix_secs);
|
||||
previous_created_at_unix_ms = Some(item.created_at_unix_ms);
|
||||
}
|
||||
intervals
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ pub fn build_admin_provider_endpoint_response(
|
||||
"format_acceptance_config": endpoint.format_acceptance_config,
|
||||
"total_keys": total_keys,
|
||||
"active_keys": active_keys,
|
||||
"created_at": endpoint_timestamp_or_now(endpoint.created_at_unix_secs, now_unix_secs),
|
||||
"created_at": endpoint_timestamp_or_now(endpoint.created_at_unix_ms, now_unix_secs),
|
||||
"updated_at": endpoint_timestamp_or_now(endpoint.updated_at_unix_secs, now_unix_secs),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ pub fn build_admin_provider_model_response(
|
||||
"effective_config": effective_config,
|
||||
"global_model_name": model.global_model_name.clone(),
|
||||
"global_model_display_name": model.global_model_display_name.clone(),
|
||||
"created_at": timestamp_or_now(model.created_at_unix_secs, now_unix_secs),
|
||||
"created_at": timestamp_or_now(model.created_at_unix_ms, now_unix_secs),
|
||||
"updated_at": timestamp_or_now(model.updated_at_unix_secs, now_unix_secs),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ pub fn build_admin_pool_key_payload(
|
||||
"total_cost_usd": "0.00000000",
|
||||
"sticky_sessions": context.sticky_sessions,
|
||||
"lru_score": context.lru_score,
|
||||
"created_at": key.created_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
"created_at": key.created_at_unix_ms.and_then(unix_secs_to_rfc3339),
|
||||
"last_used_at": key.last_used_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
"scheduling_status": scheduling_status,
|
||||
"scheduling_reason": scheduling_reason,
|
||||
@@ -817,7 +817,7 @@ pub fn build_admin_pool_batch_import_key_record(
|
||||
record.total_response_time_ms = Some(0);
|
||||
record.health_by_format = Some(json!({}));
|
||||
record.circuit_breaker_by_format = Some(json!({}));
|
||||
record.created_at_unix_secs = Some(now_unix_secs);
|
||||
record.created_at_unix_ms = Some(now_unix_secs);
|
||||
record.updated_at_unix_secs = Some(now_unix_secs);
|
||||
Ok(record)
|
||||
}
|
||||
|
||||
@@ -1198,7 +1198,7 @@ pub fn build_admin_proxy_node_payload(node: &StoredProxyNode) -> serde_json::Val
|
||||
("config_version".to_string(), json!(node.config_version)),
|
||||
(
|
||||
"created_at".to_string(),
|
||||
json!(node.created_at_unix_secs.and_then(unix_secs_to_rfc3339)),
|
||||
json!(node.created_at_unix_ms.and_then(unix_secs_to_rfc3339)),
|
||||
),
|
||||
(
|
||||
"updated_at".to_string(),
|
||||
@@ -1225,7 +1225,7 @@ pub fn build_admin_proxy_node_event_payload(event: &StoredProxyNodeEvent) -> ser
|
||||
"id": event.id,
|
||||
"event_type": event.event_type,
|
||||
"detail": event.detail,
|
||||
"created_at": event.created_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
"created_at": event.created_at_unix_ms.and_then(unix_secs_to_rfc3339),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user