mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(shared-state): read calibrator counters without the limiter latch
The shared calibration refresh read through the limiter. A Redis error there latched the chat route's limiter store for five seconds. The refresh now reads the store directly, as the shared-state loop does.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package traefikllmgateway
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -92,3 +93,23 @@ func TestSharedStateOffIdenticalCalibrator(t *testing.T) {
|
||||
t.Fatalf("store touched with sharedState off: %d reads, %d writes", len(rec.reads), len(rec.writes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedCalibrationReadErrorDoesNotLatchLimiter(t *testing.T) {
|
||||
a, _, store, _, _ := sharedGatewayPair(t, nil)
|
||||
shareLimiterStore(a, store)
|
||||
for i := 0; i < smartCalibMinSamples; i++ {
|
||||
observeShared(a, "alpha", "a1", 1000, 400)
|
||||
}
|
||||
a.refreshRouterLearning(a.limiter.now())
|
||||
if got := a.tokenCalib.promptTokens("alpha", "a1", 1000); got != 400 {
|
||||
t.Fatalf("setup: shared estimate = %d, want 400", got)
|
||||
}
|
||||
store.setFail(errors.New("redis down"))
|
||||
a.refreshRouterLearning(a.limiter.now())
|
||||
if a.limiter.storeLatched() {
|
||||
t.Error("a failed shared-state read latched the chat route's limiter store")
|
||||
}
|
||||
if got := a.tokenCalib.promptTokens("alpha", "a1", 1000); got != 400 {
|
||||
t.Errorf("estimate after a failed read = %d, want the previous 400", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user