Skip to content

Commit

Permalink
agent/consuk: Rename RPCRate -> RPCRateLimit
Browse files Browse the repository at this point in the history
so that the field name is consistent across config structs.
  • Loading branch information
dnephin committed Sep 28, 2020
1 parent 1cb3b9c commit d2afe6d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ func newConsulConfig(runtimeCfg *config.RuntimeConfig, logger hclog.Logger) (*co

// Rate limiting for RPC calls.
if runtimeCfg.RPCRateLimit > 0 {
cfg.RPCRate = runtimeCfg.RPCRateLimit
cfg.RPCRateLimit = runtimeCfg.RPCRateLimit
}
if runtimeCfg.RPCMaxBurst > 0 {
cfg.RPCMaxBurst = runtimeCfg.RPCMaxBurst
Expand Down
23 changes: 16 additions & 7 deletions agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/config"
"github.com/hashicorp/consul/agent/connect"
"github.com/hashicorp/consul/agent/consul"
"github.com/hashicorp/consul/agent/debug"
"github.com/hashicorp/consul/agent/local"
"github.com/hashicorp/consul/agent/structs"
Expand All @@ -37,6 +38,7 @@ import (
"github.com/hashicorp/serf/serf"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/time/rate"
)

func makeReadOnlyAgentACL(t *testing.T, srv *HTTPHandlers) string {
Expand Down Expand Up @@ -1378,20 +1380,17 @@ func TestAgent_Reload(t *testing.T) {
`,
})

shim := &delegateConfigReloadShim{delegate: a.delegate}
a.delegate = shim
if err := a.reloadConfigInternal(cfg2); err != nil {
t.Fatalf("got error %v want nil", err)
}
if a.State.Service(structs.NewServiceID("redis-reloaded", nil)) == nil {
t.Fatal("missing redis-reloaded service")
}

if a.config.RPCRateLimit != 2 {
t.Fatalf("RPC rate not set correctly. Got %v. Want 2", a.config.RPCRateLimit)
}

if a.config.RPCMaxBurst != 200 {
t.Fatalf("RPC max burst not set correctly. Got %v. Want 200", a.config.RPCMaxBurst)
}
require.Equal(t, rate.Limit(2), shim.newCfg.RPCRateLimit)
require.Equal(t, 200, shim.newCfg.RPCMaxBurst)

for _, wp := range a.watchPlans {
if !wp.IsStopped() {
Expand All @@ -1400,6 +1399,16 @@ func TestAgent_Reload(t *testing.T) {
}
}

type delegateConfigReloadShim struct {
delegate
newCfg consul.ReloadableConfig
}

func (s *delegateConfigReloadShim) ReloadConfig(cfg consul.ReloadableConfig) error {
s.newCfg = cfg
return s.delegate.ReloadConfig(cfg)
}

// TestAgent_ReloadDoesNotTriggerWatch Ensure watches not triggered after reload
// see https://github.com/hashicorp/consul/issues/7446
func TestAgent_ReloadDoesNotTriggerWatch(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions agent/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,8 @@ type RuntimeConfig struct {

// RPCRateLimit and RPCMaxBurst control how frequently RPC calls are allowed
// to happen. In any large enough time interval, rate limiter limits the
// rate to RPCRate tokens per second, with a maximum burst size of
// RPCMaxBurst events. As a special case, if RPCRate == Inf (the infinite
// rate to RPCRateLimit tokens per second, with a maximum burst size of
// RPCMaxBurst events. As a special case, if RPCRateLimit == Inf (the infinite
// rate), RPCMaxBurst is ignored.
//
// See https://en.wikipedia.org/wiki/Token_bucket for more about token
Expand Down
2 changes: 1 addition & 1 deletion agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewClient(config *Config, deps Deps) (*Client, error) {
tlsConfigurator: deps.TLSConfigurator,
}

c.rpcLimiter.Store(rate.NewLimiter(config.RPCRate, config.RPCMaxBurst))
c.rpcLimiter.Store(rate.NewLimiter(config.RPCRateLimit, config.RPCMaxBurst))

if err := c.initEnterprise(); err != nil {
c.Shutdown()
Expand Down
6 changes: 3 additions & 3 deletions agent/consul/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func TestClient_RPC_RateLimit(t *testing.T) {
testrpc.WaitForLeader(t, s1.RPC, "dc1")

_, conf2 := testClientConfig(t)
conf2.RPCRate = 2
conf2.RPCRateLimit = 2
conf2.RPCMaxBurst = 2
c1 := newClient(t, conf2)

Expand Down Expand Up @@ -574,7 +574,7 @@ func TestClient_SnapshotRPC_RateLimit(t *testing.T) {
testrpc.WaitForLeader(t, s1.RPC, "dc1")

_, conf1 := testClientConfig(t)
conf1.RPCRate = 2
conf1.RPCRateLimit = 2
conf1.RPCMaxBurst = 2
c1 := newClient(t, conf1)

Expand Down Expand Up @@ -729,7 +729,7 @@ func TestClientServer_UserEvent(t *testing.T) {

func TestClient_ReloadConfig(t *testing.T) {
_, cfg := testClientConfig(t)
cfg.RPCRate = rate.Limit(500)
cfg.RPCRateLimit = rate.Limit(500)
cfg.RPCMaxBurst = 5000
deps := newDefaultDeps(t, &Config{NodeName: "node1", Datacenter: "dc1"})
c, err := NewClient(cfg, deps)
Expand Down
14 changes: 7 additions & 7 deletions agent/consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,16 @@ type Config struct {
// place, and a small jitter is applied to avoid a thundering herd.
RPCHoldTimeout time.Duration

// RPCRate and RPCMaxBurst control how frequently RPC calls are allowed
// RPCRateLimit and RPCMaxBurst control how frequently RPC calls are allowed
// to happen. In any large enough time interval, rate limiter limits the
// rate to RPCRate tokens per second, with a maximum burst size of
// RPCMaxBurst events. As a special case, if RPCRate == Inf (the infinite
// rate to RPCRateLimit tokens per second, with a maximum burst size of
// RPCMaxBurst events. As a special case, if RPCRateLimit == Inf (the infinite
// rate), RPCMaxBurst is ignored.
//
// See https://en.wikipedia.org/wiki/Token_bucket for more about token
// buckets.
RPCRate rate.Limit
RPCMaxBurst int
RPCRateLimit rate.Limit
RPCMaxBurst int

// RPCMaxConnsPerClient is the limit of how many concurrent connections are
// allowed from a single source IP.
Expand Down Expand Up @@ -573,8 +573,8 @@ func DefaultConfig() *Config {

CheckOutputMaxSize: checks.DefaultBufSize,

RPCRate: rate.Inf,
RPCMaxBurst: 1000,
RPCRateLimit: rate.Inf,
RPCMaxBurst: 1000,

TLSMinVersion: "tls10",

Expand Down
2 changes: 1 addition & 1 deletion agent/consul/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func TestRPC_RPCMaxConnsPerClient(t *testing.T) {

// Reload config with higher limit
rc := ReloadableConfig{
RPCRateLimit: s1.config.RPCRate,
RPCRateLimit: s1.config.RPCRateLimit,
RPCMaxBurst: s1.config.RPCMaxBurst,
RPCMaxConnsPerClient: 10,
}
Expand Down
2 changes: 1 addition & 1 deletion agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func NewServer(config *Config, flat Deps) (*Server, error) {
return nil, err
}

s.rpcLimiter.Store(rate.NewLimiter(config.RPCRate, config.RPCMaxBurst))
s.rpcLimiter.Store(rate.NewLimiter(config.RPCRateLimit, config.RPCMaxBurst))

configReplicatorConfig := ReplicatorConfig{
Name: logging.ConfigEntry,
Expand Down
4 changes: 2 additions & 2 deletions agent/consul/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ func TestServer_ReloadConfig(t *testing.T) {

dir1, s := testServerWithConfig(t, func(c *Config) {
c.Build = "1.5.0"
c.RPCRate = 500
c.RPCRateLimit = 500
c.RPCMaxBurst = 5000
})
defer os.RemoveAll(dir1)
Expand Down Expand Up @@ -1447,7 +1447,7 @@ func TestServer_ReloadConfig(t *testing.T) {
func TestServer_RPC_RateLimit(t *testing.T) {
t.Parallel()
_, conf1 := testServerConfig(t)
conf1.RPCRate = 2
conf1.RPCRateLimit = 2
conf1.RPCMaxBurst = 2
s1, err := newServer(t, conf1)
if err != nil {
Expand Down

0 comments on commit d2afe6d

Please sign in to comment.