2026-04-05 20:23:16 +08:00
|
|
|
pub(super) use aether_scheduler_core::{
|
|
|
|
|
build_scheduler_affinity_cache_key_for_api_key_id, candidate_affinity_hash, candidate_key,
|
2026-04-27 14:54:56 +08:00
|
|
|
matches_affinity_target, SchedulerAffinityTarget,
|
2026-04-05 20:23:16 +08:00
|
|
|
};
|
2026-04-04 01:40:24 +08:00
|
|
|
|
2026-04-05 20:23:16 +08:00
|
|
|
use crate::data::auth::GatewayAuthApiKeySnapshot;
|
2026-04-07 02:50:19 +08:00
|
|
|
use crate::scheduler::affinity::SCHEDULER_AFFINITY_TTL;
|
2026-04-04 01:40:24 +08:00
|
|
|
|
|
|
|
|
use super::{
|
2026-04-07 02:50:19 +08:00
|
|
|
SchedulerMinimalCandidateSelectionCandidate, SchedulerRuntimeState,
|
|
|
|
|
SCHEDULER_AFFINITY_MAX_ENTRIES,
|
2026-04-04 01:40:24 +08:00
|
|
|
};
|
2026-03-31 19:19:04 +08:00
|
|
|
|
|
|
|
|
pub(super) fn build_scheduler_affinity_cache_key(
|
2026-04-05 20:23:16 +08:00
|
|
|
auth_snapshot: Option<&GatewayAuthApiKeySnapshot>,
|
2026-03-31 19:19:04 +08:00
|
|
|
api_format: &str,
|
|
|
|
|
global_model_name: &str,
|
|
|
|
|
) -> Option<String> {
|
|
|
|
|
let api_key_id = auth_snapshot
|
|
|
|
|
.map(|snapshot| snapshot.api_key_id.trim())
|
|
|
|
|
.filter(|value| !value.is_empty())?;
|
2026-04-03 14:59:58 +08:00
|
|
|
build_scheduler_affinity_cache_key_for_api_key_id(api_key_id, api_format, global_model_name)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 19:19:04 +08:00
|
|
|
#[cfg_attr(not(test), allow(dead_code))]
|
|
|
|
|
pub(super) fn remember_scheduler_affinity(
|
|
|
|
|
affinity_cache_key: Option<&str>,
|
2026-04-05 20:23:16 +08:00
|
|
|
state: &(impl SchedulerRuntimeState + ?Sized),
|
2026-04-07 02:50:19 +08:00
|
|
|
candidate: &SchedulerMinimalCandidateSelectionCandidate,
|
2026-03-31 19:19:04 +08:00
|
|
|
) {
|
|
|
|
|
let Some(cache_key) = affinity_cache_key else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-05 20:23:16 +08:00
|
|
|
state.remember_scheduler_affinity_target(
|
|
|
|
|
cache_key,
|
2026-03-31 19:19:04 +08:00
|
|
|
SchedulerAffinityTarget {
|
|
|
|
|
provider_id: candidate.provider_id.clone(),
|
|
|
|
|
endpoint_id: candidate.endpoint_id.clone(),
|
|
|
|
|
key_id: candidate.key_id.clone(),
|
|
|
|
|
},
|
|
|
|
|
SCHEDULER_AFFINITY_TTL,
|
|
|
|
|
SCHEDULER_AFFINITY_MAX_ENTRIES,
|
|
|
|
|
);
|
|
|
|
|
}
|