From d45ff81063426906d65a5b4e6c0db63fe0de27c9 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 23 May 2024 08:31:23 +0300 Subject: [PATCH] test recent check period Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/vttablet/tabletserver/throttle/throttler.go | 3 +++ go/vt/vttablet/tabletserver/throttle/throttler_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/go/vt/vttablet/tabletserver/throttle/throttler.go b/go/vt/vttablet/tabletserver/throttle/throttler.go index 9a576eeb2d6..0aed6bf6075 100644 --- a/go/vt/vttablet/tabletserver/throttle/throttler.go +++ b/go/vt/vttablet/tabletserver/throttle/throttler.go @@ -271,6 +271,9 @@ func NewThrottler(env tabletenv.Env, srvTopoServer srvtopo.Server, ts *topo.Serv throttler.dormantPeriod = dormantPeriod throttler.recentCheckDormantDiff = int64(throttler.dormantPeriod / recentCheckRateLimiterInterval) throttler.recentCheckDiff = int64(1 * time.Second / recentCheckRateLimiterInterval) + if throttler.recentCheckDiff < 1 { + throttler.recentCheckDiff = 1 + } throttler.StoreMetricsThreshold(defaultThrottleLagThreshold.Seconds()) //default throttler.readSelfThrottleMetric = func(ctx context.Context, p *mysql.Probe) *mysql.MySQLThrottleMetric { diff --git a/go/vt/vttablet/tabletserver/throttle/throttler_test.go b/go/vt/vttablet/tabletserver/throttle/throttler_test.go index 41fb944817b..dadd6f59991 100644 --- a/go/vt/vttablet/tabletserver/throttle/throttler_test.go +++ b/go/vt/vttablet/tabletserver/throttle/throttler_test.go @@ -185,6 +185,13 @@ func newTestThrottler() *Throttler { return throttler } +func TestInitThrottler(t *testing.T) { + throttler := newTestThrottler() + assert.Equal(t, 5*time.Second, throttler.dormantPeriod) + assert.EqualValues(t, 5, throttler.recentCheckDormantDiff) + assert.EqualValues(t, 3, throttler.recentCheckDiff) +} + func TestIsAppThrottled(t *testing.T) { throttler := Throttler{ throttledApps: cache.New(cache.NoExpiration, 0),