Skip to content

Commit

Permalink
Merge pull request #10707 from hashicorp/v1.0.2-deploy-query-param
Browse files Browse the repository at this point in the history
deployment query rate limit (#10706)
  • Loading branch information
schmichael committed Jun 4, 2021
2 parents fff533a + c74ab42 commit 3803490
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.2-backport (Unreleased)

* server: Make deployment rate limiting configurable for high volume loads [[GH-10706](https://github.com/hashicorp/nomad/pull/10706)]

## 1.0.2 (January 14, 2020)

IMPROVEMENTS:
Expand Down
10 changes: 10 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hashicorp/nomad/helper/pluginutils/loader"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad"
"github.com/hashicorp/nomad/nomad/deploymentwatcher"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/raft"
Expand Down Expand Up @@ -418,6 +419,15 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) {
conf.RPCMaxConnsPerClient = limit
}

// Set deployment rate limit
if rate := agentConfig.Server.DeploymentQueryRateLimit; rate == 0 {
conf.DeploymentQueryRateLimit = deploymentwatcher.LimitStateQueriesPerSecond
} else if rate > 0 {
conf.DeploymentQueryRateLimit = rate
} else {
return nil, fmt.Errorf("deploy_query_rate_limit must be greater than 0")
}

return conf, nil
}

Expand Down
8 changes: 8 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ type ServerConfig struct {

// ExtraKeysHCL is used by hcl to surface unexpected keys
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`

// DeploymentQueryRateLimit is in queries per second and is used by the
// DeploymentWatcher to throttle the amount of simultaneously deployments
DeploymentQueryRateLimit float64 `hcl:"deploy_query_rate_limit"`
}

// ServerJoin is used in both clients and servers to bootstrap connections to
Expand Down Expand Up @@ -1424,6 +1428,10 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
result.DefaultSchedulerConfig = &c
}

if b.DeploymentQueryRateLimit != 0 {
result.DeploymentQueryRateLimit = b.DeploymentQueryRateLimit
}

// Add the schedulers
result.EnabledSchedulers = append(result.EnabledSchedulers, b.EnabledSchedulers...)

Expand Down
6 changes: 6 additions & 0 deletions nomad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/memberlist"
"github.com/hashicorp/nomad/helper/pluginutils/loader"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/deploymentwatcher"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/scheduler"
Expand Down Expand Up @@ -354,6 +355,10 @@ type Config struct {
// AgentShutdown is used to call agent.Shutdown from the context of a Server
// It is used primarily for licensing
AgentShutdown func() error

// DeploymentQueryRateLimit is in queries per second and is used by the
// DeploymentWatcher to throttle the amount of simultaneously deployments
DeploymentQueryRateLimit float64
}

// CheckVersion is used to check if the ProtocolVersion is valid
Expand Down Expand Up @@ -438,6 +443,7 @@ func DefaultConfig() *Config {
ServiceSchedulerEnabled: false,
},
},
DeploymentQueryRateLimit: deploymentwatcher.LimitStateQueriesPerSecond,
}

// Enable all known schedulers by default
Expand Down
2 changes: 1 addition & 1 deletion nomad/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ func (s *Server) setupDeploymentWatcher() error {
raftShim,
s.staticEndpoints.Deployment,
s.staticEndpoints.Job,
deploymentwatcher.LimitStateQueriesPerSecond,
s.config.DeploymentQueryRateLimit,
deploymentwatcher.CrossDeploymentUpdateBatchDuration,
)

Expand Down

0 comments on commit 3803490

Please sign in to comment.