Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add env to enable throttlerV2 #4313

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions router/throttler/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,23 @@ func (f *factory) Get(destName, destID string) Throttler {
config: conf,
}

var adaptiveConf adaptiveThrottleConfig
adaptiveConf.readThrottlingConfig(f.config, destName, destID)
var limitFactorMeasurement stats.Measurement = nil
if f.Stats != nil {
limitFactorMeasurement = f.Stats.NewTaggedStat("adaptive_throttler_limit_factor", stats.GaugeType, stats.Tags{
"destinationId": destID,
"destType": destName,
})
}
at := &adaptiveThrottler{
limiter: f.adaptiveLimiter,
algorithm: newAdaptiveAlgorithm(f.config, adaptiveConf.window),
config: adaptiveConf,
limitFactorMeasurement: limitFactorMeasurement,
var at Throttler = &noOpThrottler{}
if f.config.GetBool("Router.throttlerV2.enabled", true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, should this be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it true by default because the actual idea is to run both adaptive and static together. We are only going to set it as false if adaptive causes an issue after the release

var adaptiveConf adaptiveThrottleConfig
adaptiveConf.readThrottlingConfig(f.config, destName, destID)
var limitFactorMeasurement stats.Measurement = nil
if f.Stats != nil {
limitFactorMeasurement = f.Stats.NewTaggedStat("adaptive_throttler_limit_factor", stats.GaugeType, stats.Tags{
"destinationId": destID,
"destType": destName,
})
}
at = &adaptiveThrottler{
limiter: f.adaptiveLimiter,
algorithm: newAdaptiveAlgorithm(f.config, adaptiveConf.window),
config: adaptiveConf,
limitFactorMeasurement: limitFactorMeasurement,
}
}

f.throttlers[destID] = &switchingThrottler{
Expand Down
21 changes: 20 additions & 1 deletion router/throttler/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func TestFactory(t *testing.T) {
config := config.New()
t.Run("when adaptive throttling is enabled", func(t *testing.T) {
config := config.New()
config.Set("Router.throttler.adaptive.enabled", true)
maxLimit := int64(300)
config.Set("Router.throttler.adaptive.maxLimit", maxLimit)
Expand Down Expand Up @@ -52,6 +52,25 @@ func TestFactory(t *testing.T) {
}, 2*time.Second, 100*time.Millisecond, "limit: %d, expectedLimit: %d", ta.getLimit(), maxLimit*5/10)
})
})

t.Run("when throttlerV2 is false", func(t *testing.T) {
config := config.New()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]: Variable 'config' collides with imported package name

Suggested change
config := config.New()
conf := config.New()

config.Set("Router.throttlerV2.enabled", false)
config.Set("Router.throttler.destName.timeWindow", time.Second)
config.Set("Router.throttler.destName.limit", int64(100))
f, err := NewFactory(config, nil)
require.NoError(t, err)
defer f.Shutdown()
ta := f.Get("destName", "destID")
require.Eventually(t, func() bool {
return ta.getLimit() == int64(100)
}, 2*time.Second, 100*time.Millisecond)

config.Set("Router.throttler.adaptive.enabled", true)
require.Eventually(t, func() bool {
return ta.getLimit() == int64(0)
}, 2*time.Second, 100*time.Millisecond)
})
}

func floatCheck(a, b int64) bool {
Expand Down
Loading