Clarify API key concurrency skip reasons

This commit is contained in:
fawney19
2026-05-27 17:00:09 +08:00
parent d77a572dc7
commit 42e723ff7c
9 changed files with 96 additions and 53 deletions
@@ -32,7 +32,9 @@ use sha2::{Digest, Sha256};
use std::collections::BTreeMap;
pub(crate) use self::selection::{
SchedulerSkippedCandidate, API_KEY_CONCURRENCY_LIMIT_SKIP_REASON,
is_auth_api_key_concurrency_limit_skip_reason, SchedulerSkippedCandidate,
API_KEY_CONCURRENCY_LIMIT_SKIP_REASON, AUTH_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON,
LEGACY_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON,
};
use crate::data::auth::GatewayAuthApiKeySnapshot;
@@ -20,7 +20,19 @@ pub(crate) struct SchedulerSkippedCandidate {
pub(crate) skip_reason: &'static str,
}
pub(crate) const API_KEY_CONCURRENCY_LIMIT_SKIP_REASON: &str = "api_key_concurrency_limit_reached";
pub(crate) const AUTH_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON: &str =
"auth_api_key_concurrency_limit_reached";
pub(crate) const LEGACY_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON: &str =
"api_key_concurrency_limit_reached";
pub(crate) const API_KEY_CONCURRENCY_LIMIT_SKIP_REASON: &str =
AUTH_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON;
pub(crate) fn is_auth_api_key_concurrency_limit_skip_reason(reason: &str) -> bool {
matches!(
reason.trim(),
AUTH_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON | LEGACY_API_KEY_CONCURRENCY_LIMIT_SKIP_REASON
)
}
pub(super) fn is_exact_all_skipped_by_auth_limit(
selected: &[SchedulerMinimalCandidateSelectionCandidate],
@@ -30,7 +42,7 @@ pub(super) fn is_exact_all_skipped_by_auth_limit(
&& !skipped.is_empty()
&& skipped
.iter()
.all(|candidate| candidate.skip_reason == API_KEY_CONCURRENCY_LIMIT_SKIP_REASON)
.all(|candidate| is_auth_api_key_concurrency_limit_skip_reason(candidate.skip_reason))
}
#[cfg_attr(not(test), allow(dead_code))]