fix: address code review issues for RPM limiting feature
- Use TxPipeline (MULTI/EXEC) instead of Pipeline for atomic INCR+EXPIRE - Filter negative values in GetBaseRPM(), update test expectation - Add RPM batch query (GetRPMBatch) to account List API - Add warn logs for RPM increment failures in gateway handler - Reset enableRpmLimit on BulkEditAccountModal close - Use union type 'tiered' | 'sticky_exempt' for rpmStrategy refs - Add design decision comments for rdb.Time() RTT trade-off
This commit is contained in:
@@ -972,26 +972,68 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="rpmLimitEnabled" class="grid grid-cols-2 gap-4">
|
||||
<div v-if="rpmLimitEnabled" class="space-y-4">
|
||||
<div>
|
||||
<label class="input-label">{{ t('admin.accounts.quotaControl.rpmLimit.baseRpm') }}</label>
|
||||
<input
|
||||
v-model.number="baseRpm"
|
||||
type="number"
|
||||
min="1"
|
||||
max="1000"
|
||||
step="1"
|
||||
class="input"
|
||||
:placeholder="t('admin.accounts.quotaControl.rpmLimit.baseRpmPlaceholder')"
|
||||
/>
|
||||
<p class="input-hint">{{ t('admin.accounts.quotaControl.rpmLimit.baseRpmHint') }}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="input-label">{{ t('admin.accounts.quotaControl.rpmLimit.strategy') }}</label>
|
||||
<select v-model="rpmStrategy" class="input">
|
||||
<option value="tiered">{{ t('admin.accounts.quotaControl.rpmLimit.strategyTiered') }}</option>
|
||||
<option value="sticky_exempt">{{ t('admin.accounts.quotaControl.rpmLimit.strategyStickyExempt') }}</option>
|
||||
</select>
|
||||
<p class="input-hint">{{ t('admin.accounts.quotaControl.rpmLimit.strategyHint') }}</p>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
@click="rpmStrategy = 'tiered'"
|
||||
:class="[
|
||||
'flex-1 rounded-lg px-3 py-2 text-sm font-medium transition-all',
|
||||
rpmStrategy === 'tiered'
|
||||
? 'bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
|
||||
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
|
||||
]"
|
||||
>
|
||||
<div class="text-center">
|
||||
<div>{{ t('admin.accounts.quotaControl.rpmLimit.strategyTiered') }}</div>
|
||||
<div class="mt-0.5 text-[10px] opacity-70">{{ t('admin.accounts.quotaControl.rpmLimit.strategyTieredHint') }}</div>
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="rpmStrategy = 'sticky_exempt'"
|
||||
:class="[
|
||||
'flex-1 rounded-lg px-3 py-2 text-sm font-medium transition-all',
|
||||
rpmStrategy === 'sticky_exempt'
|
||||
? 'bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
|
||||
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
|
||||
]"
|
||||
>
|
||||
<div class="text-center">
|
||||
<div>{{ t('admin.accounts.quotaControl.rpmLimit.strategyStickyExempt') }}</div>
|
||||
<div class="mt-0.5 text-[10px] opacity-70">{{ t('admin.accounts.quotaControl.rpmLimit.strategyStickyExemptHint') }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="rpmStrategy === 'tiered'">
|
||||
<label class="input-label">{{ t('admin.accounts.quotaControl.rpmLimit.stickyBuffer') }}</label>
|
||||
<input
|
||||
v-model.number="rpmStickyBuffer"
|
||||
type="number"
|
||||
min="1"
|
||||
step="1"
|
||||
class="input"
|
||||
:placeholder="t('admin.accounts.quotaControl.rpmLimit.stickyBufferPlaceholder')"
|
||||
/>
|
||||
<p class="input-hint">{{ t('admin.accounts.quotaControl.rpmLimit.stickyBufferHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1303,7 +1345,8 @@ const maxSessions = ref<number | null>(null)
|
||||
const sessionIdleTimeout = ref<number | null>(null)
|
||||
const rpmLimitEnabled = ref(false)
|
||||
const baseRpm = ref<number | null>(null)
|
||||
const rpmStrategy = ref<string>('tiered')
|
||||
const rpmStrategy = ref<'tiered' | 'sticky_exempt'>('tiered')
|
||||
const rpmStickyBuffer = ref<number | null>(null)
|
||||
const tlsFingerprintEnabled = ref(false)
|
||||
const sessionIdMaskingEnabled = ref(false)
|
||||
const cacheTTLOverrideEnabled = ref(false)
|
||||
@@ -1766,6 +1809,7 @@ function loadQuotaControlSettings(account: Account) {
|
||||
rpmLimitEnabled.value = false
|
||||
baseRpm.value = null
|
||||
rpmStrategy.value = 'tiered'
|
||||
rpmStickyBuffer.value = null
|
||||
tlsFingerprintEnabled.value = false
|
||||
sessionIdMaskingEnabled.value = false
|
||||
cacheTTLOverrideEnabled.value = false
|
||||
@@ -1793,7 +1837,8 @@ function loadQuotaControlSettings(account: Account) {
|
||||
if (account.base_rpm != null && account.base_rpm > 0) {
|
||||
rpmLimitEnabled.value = true
|
||||
baseRpm.value = account.base_rpm
|
||||
rpmStrategy.value = account.rpm_strategy || 'tiered'
|
||||
rpmStrategy.value = (account.rpm_strategy as 'tiered' | 'sticky_exempt') || 'tiered'
|
||||
rpmStickyBuffer.value = account.rpm_sticky_buffer ?? null
|
||||
}
|
||||
|
||||
// Load TLS fingerprint setting
|
||||
@@ -2110,6 +2155,11 @@ const handleSubmit = async () => {
|
||||
if (rpmLimitEnabled.value && baseRpm.value != null && baseRpm.value > 0) {
|
||||
newExtra.base_rpm = baseRpm.value
|
||||
newExtra.rpm_strategy = rpmStrategy.value
|
||||
if (rpmStickyBuffer.value != null && rpmStickyBuffer.value > 0) {
|
||||
newExtra.rpm_sticky_buffer = rpmStickyBuffer.value
|
||||
} else {
|
||||
delete newExtra.rpm_sticky_buffer
|
||||
}
|
||||
} else {
|
||||
delete newExtra.base_rpm
|
||||
delete newExtra.rpm_strategy
|
||||
|
||||
Reference in New Issue
Block a user