fix(api): reduce probe cache key fragmentation
This commit is contained in:
parent
f4c5ed12f5
commit
9cdf55073b
2 changed files with 24 additions and 13 deletions
|
|
@ -193,30 +193,18 @@ func runLocalModelProbe(m *config.ModelConfig) bool {
|
||||||
func modelProbeCacheKey(m *config.ModelConfig) string {
|
func modelProbeCacheKey(m *config.ModelConfig) string {
|
||||||
protocol, modelID := splitModel(m.Model)
|
protocol, modelID := splitModel(m.Model)
|
||||||
|
|
||||||
modelName := strings.ToLower(strings.TrimSpace(m.ModelName))
|
|
||||||
apiBaseRaw := modelProbeAPIBase(m)
|
apiBaseRaw := modelProbeAPIBase(m)
|
||||||
apiBase := strings.ToLower(strings.TrimRight(strings.TrimSpace(apiBaseRaw), "/"))
|
apiBase := strings.ToLower(strings.TrimRight(strings.TrimSpace(apiBaseRaw), "/"))
|
||||||
authMethod := strings.ToLower(strings.TrimSpace(m.AuthMethod))
|
|
||||||
connectMode := strings.ToLower(strings.TrimSpace(m.ConnectMode))
|
|
||||||
apiKeyFingerprint := modelProbeAPIKeyFingerprint(m.APIKey())
|
apiKeyFingerprint := modelProbeAPIKeyFingerprint(m.APIKey())
|
||||||
|
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.Grow(
|
b.Grow(len(protocol) + len(modelID) + len(apiBase) + len(apiKeyFingerprint) + 8)
|
||||||
len(modelName) + len(protocol) + len(modelID) + len(apiBase) + len(authMethod) +
|
|
||||||
len(connectMode) + len(apiKeyFingerprint) + 8,
|
|
||||||
)
|
|
||||||
b.WriteString(modelName)
|
|
||||||
b.WriteByte('|')
|
|
||||||
b.WriteString(protocol)
|
b.WriteString(protocol)
|
||||||
b.WriteByte('|')
|
b.WriteByte('|')
|
||||||
b.WriteString(modelID)
|
b.WriteString(modelID)
|
||||||
b.WriteByte('|')
|
b.WriteByte('|')
|
||||||
b.WriteString(apiBase)
|
b.WriteString(apiBase)
|
||||||
b.WriteByte('|')
|
b.WriteByte('|')
|
||||||
b.WriteString(authMethod)
|
|
||||||
b.WriteByte('|')
|
|
||||||
b.WriteString(connectMode)
|
|
||||||
b.WriteByte('|')
|
|
||||||
b.WriteString(apiKeyFingerprint)
|
b.WriteString(apiKeyFingerprint)
|
||||||
|
|
||||||
return b.String()
|
return b.String()
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,29 @@ func TestModelProbeCacheKey_NormalizesTrailingSlashInAPIBase(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModelProbeCacheKey_IgnoresDisplayAndConnectionFields(t *testing.T) {
|
||||||
|
base := &config.ModelConfig{
|
||||||
|
ModelName: "vllm-one",
|
||||||
|
Model: "vllm/custom-model",
|
||||||
|
APIBase: "http://127.0.0.1:8000/v1",
|
||||||
|
AuthMethod: "none",
|
||||||
|
ConnectMode: "http",
|
||||||
|
}
|
||||||
|
changed := &config.ModelConfig{
|
||||||
|
ModelName: "vllm-two",
|
||||||
|
Model: "vllm/custom-model",
|
||||||
|
APIBase: "http://127.0.0.1:8000/v1",
|
||||||
|
AuthMethod: "token",
|
||||||
|
ConnectMode: "ws",
|
||||||
|
}
|
||||||
|
|
||||||
|
k1 := modelProbeCacheKey(base)
|
||||||
|
k2 := modelProbeCacheKey(changed)
|
||||||
|
if k1 != k2 {
|
||||||
|
t.Fatalf("modelProbeCacheKey() should ignore non-probe fields, got %q vs %q", k1, k2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProbeLocalModelAvailability_SuccessBackoff(t *testing.T) {
|
func TestProbeLocalModelAvailability_SuccessBackoff(t *testing.T) {
|
||||||
resetModelProbeHooks(t)
|
resetModelProbeHooks(t)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue