mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 09:57:47 +08:00
fix(gateway): add provider key concurrency and cache affinity modes
This commit is contained in:
@@ -35,6 +35,18 @@ describe('pool key batch settings', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('serializes a positive concurrency limit as a number', () => {
|
||||
const selection = createPoolKeyBatchSettingSelection()
|
||||
const draft = createPoolKeyBatchSettingsDraft()
|
||||
selection.concurrent_limit = true
|
||||
draft.concurrent_limit = 6
|
||||
|
||||
expect(validatePoolKeyBatchSettings(selection, draft)).toEqual([])
|
||||
expect(buildPoolKeySettingsPatch(selection, draft)).toEqual({
|
||||
concurrent_limit: 6,
|
||||
})
|
||||
})
|
||||
|
||||
it('requires a selected field and a proxy node for set mode', () => {
|
||||
const selection = createPoolKeyBatchSettingSelection()
|
||||
const draft = createPoolKeyBatchSettingsDraft()
|
||||
|
||||
@@ -5,24 +5,34 @@ export function mergePoolKeyQuotaSnapshots(
|
||||
keys: PoolKeyDetail[],
|
||||
results: RefreshQuotaResult['results'],
|
||||
): PoolKeyDetail[] {
|
||||
const quotaByKeyId = new Map<string, NonNullable<RefreshQuotaResult['results'][number]['quota_snapshot']>>()
|
||||
const resultByKeyId = new Map<string, RefreshQuotaResult['results'][number]>()
|
||||
for (const result of results) {
|
||||
if (result.quota_snapshot) {
|
||||
quotaByKeyId.set(result.key_id, result.quota_snapshot)
|
||||
if (result.quota_snapshot || result.metadata) {
|
||||
resultByKeyId.set(result.key_id, result)
|
||||
}
|
||||
}
|
||||
if (quotaByKeyId.size === 0) return keys
|
||||
if (resultByKeyId.size === 0) return keys
|
||||
|
||||
return keys.map((key) => {
|
||||
const quotaSnapshot = quotaByKeyId.get(key.key_id)
|
||||
if (!quotaSnapshot) return key
|
||||
const result = resultByKeyId.get(key.key_id)
|
||||
if (!result) return key
|
||||
const quotaSnapshot = result.quota_snapshot
|
||||
const providerType = String(quotaSnapshot?.provider_type || key.provider_type || '').trim().toLowerCase()
|
||||
return {
|
||||
...key,
|
||||
quota_updated_at: quotaSnapshot.updated_at ?? quotaSnapshot.observed_at ?? key.quota_updated_at ?? null,
|
||||
status_snapshot: {
|
||||
...(key.status_snapshot ?? {}),
|
||||
quota: quotaSnapshot,
|
||||
},
|
||||
...(quotaSnapshot ? {
|
||||
quota_updated_at: quotaSnapshot.updated_at ?? quotaSnapshot.observed_at ?? key.quota_updated_at ?? null,
|
||||
status_snapshot: {
|
||||
...(key.status_snapshot ?? {}),
|
||||
quota: quotaSnapshot,
|
||||
},
|
||||
} : {}),
|
||||
...(result.metadata && providerType ? {
|
||||
upstream_metadata: {
|
||||
...(key.upstream_metadata ?? {}),
|
||||
[providerType]: result.metadata,
|
||||
},
|
||||
} : {}),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user