mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30: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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user