fix: restore provider key circuit breaker backoff

This commit is contained in:
fawney19
2026-05-19 13:57:36 +08:00
parent 6a1da6a5ff
commit 7e9ca88e00
14 changed files with 525 additions and 42 deletions

View File

@@ -2,7 +2,7 @@ use crate::handlers::admin::provider::shared::payloads::AdminProviderKeyCreateRe
use crate::handlers::admin::provider::write::normalize::{
normalize_allow_auth_channel_mismatch_formats, normalize_api_format_json_object_keys,
normalize_api_format_list, normalize_auth_type, normalize_auth_type_by_format,
validate_vertex_api_formats,
normalize_max_probe_interval_minutes, validate_vertex_api_formats,
};
use crate::handlers::admin::request::AdminAppState;
use crate::handlers::admin::shared::{
@@ -181,7 +181,8 @@ pub(crate) async fn build_admin_create_provider_key_record(
key.rpm_limit = payload.rpm_limit;
key.concurrent_limit = normalize_optional_api_key_concurrent_limit(payload.concurrent_limit)?;
key.cache_ttl_minutes = payload.cache_ttl_minutes.unwrap_or(5);
key.max_probe_interval_minutes = payload.max_probe_interval_minutes.unwrap_or(32);
key.max_probe_interval_minutes =
normalize_max_probe_interval_minutes(payload.max_probe_interval_minutes.unwrap_or(32))?;
key.request_count = Some(0);
key.success_count = Some(0);
key.error_count = Some(0);

View File

@@ -41,8 +41,9 @@ async fn build_admin_provider_key_items_payload(
.ok()
.map(|duration| duration.as_secs())
.unwrap_or(0);
let items = key_page
.items
let keys = key_page.items;
let items = keys
.into_iter()
.map(|key| {
let api_formats =

View File

@@ -2,7 +2,7 @@ use crate::handlers::admin::provider::shared::payloads::AdminProviderKeyUpdatePa
use crate::handlers::admin::provider::write::normalize::{
normalize_allow_auth_channel_mismatch_formats, normalize_api_format_json_object_keys,
normalize_api_format_list, normalize_auth_type, normalize_auth_type_by_format,
validate_vertex_api_formats,
normalize_max_probe_interval_minutes, validate_vertex_api_formats,
};
use crate::handlers::admin::request::AdminAppState;
use crate::handlers::admin::shared::{
@@ -293,7 +293,8 @@ pub(crate) async fn build_admin_update_provider_key_record(
updated.cache_ttl_minutes = cache_ttl_minutes;
}
if let Some(max_probe_interval_minutes) = payload.max_probe_interval_minutes {
updated.max_probe_interval_minutes = max_probe_interval_minutes;
updated.max_probe_interval_minutes =
normalize_max_probe_interval_minutes(max_probe_interval_minutes)?;
}
if let Some(is_active) = payload.is_active {
updated.is_active = is_active;

View File

@@ -115,6 +115,14 @@ pub(crate) fn normalize_auth_type(value: Option<&str>) -> Result<String, String>
}
}
pub(crate) fn normalize_max_probe_interval_minutes(value: i32) -> Result<i32, String> {
if (0..=32).contains(&value) {
Ok(value)
} else {
Err("max_probe_interval_minutes 必须在 0 到 32 之间".to_string())
}
}
pub(crate) fn normalize_pool_advanced_config(
value: Option<serde_json::Value>,
) -> Result<Option<serde_json::Value>, String> {