Skip to content

Commit

Permalink
Merge pull request #1177 from dmattia/dmattia/concurrency_flag
Browse files Browse the repository at this point in the history
Added configurable parallelism pool size
  • Loading branch information
lkysow authored Oct 27, 2020
2 parents 3ab63bc + c24c500 commit c789e1a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
GitlabWebhookSecretFlag = "gitlab-webhook-secret" // nolint: gosec
HidePrevPlanComments = "hide-prev-plan-comments"
LogLevelFlag = "log-level"
ParallelPoolSize = "parallel-pool-size"
AllowDraftPRs = "allow-draft-prs"
PortFlag = "port"
RepoConfigFlag = "repo-config"
Expand Down Expand Up @@ -101,6 +102,7 @@ const (
DefaultGHHostname = "github.com"
DefaultGitlabHostname = "gitlab.com"
DefaultLogLevel = "info"
DefaultParallelPoolSize = 15
DefaultPort = 4141
DefaultTFDownloadURL = "https://releases.hashicorp.com"
DefaultTFEHostname = "app.terraform.io"
Expand Down Expand Up @@ -331,6 +333,10 @@ var boolFlags = map[string]boolFlag{
},
}
var intFlags = map[string]intFlag{
ParallelPoolSize: {
description: "Max size of the wait group that runs parallel plans and applies (if enabled).",
defaultValue: DefaultParallelPoolSize,
},
PortFlag: {
description: "Port to bind to.",
defaultValue: DefaultPort,
Expand Down Expand Up @@ -553,6 +559,9 @@ func (s *ServerCmd) setDefaults(c *server.UserConfig) {
if c.LogLevel == "" {
c.LogLevel = DefaultLogLevel
}
if c.ParallelPoolSize == 0 {
c.ParallelPoolSize = DefaultParallelPoolSize
}
if c.Port == 0 {
c.Port = DefaultPort
}
Expand Down
1 change: 1 addition & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var testFlags = map[string]interface{}{
LogLevelFlag: "debug",
AllowDraftPRs: true,
PortFlag: 8181,
ParallelPoolSize: 100,
RepoAllowlistFlag: "github.com/runatlantis/atlantis",
RequireApprovalFlag: true,
RequireMergeableFlag: true,
Expand Down
6 changes: 6 additions & 0 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ Values are chosen in this order:
```
Log level. Defaults to `info`.

* ### `--parallel-pool-size`
```bash
atlantis server --parallel-pool-size=100
```
Max size of the wait group that runs parallel plans and applies (if enabled). Defaults to `15`

* ### `--port`
```bash
atlantis server --port=8080
Expand Down
5 changes: 4 additions & 1 deletion server/events/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type DefaultCommandRunner struct {
Logger logging.SimpleLogging
// AllowForkPRs controls whether we operate on pull requests from forks.
AllowForkPRs bool
// ParallelPoolSize controls the size of the wait group used to run
// parallel plans and applies (if enabled).
ParallelPoolSize int
// AllowForkPRsFlag is the name of the flag that controls fork PR's. We use
// this in our error message back to the user on a forked PR so they know
// how to enable this functionality.
Expand Down Expand Up @@ -402,7 +405,7 @@ func (c *DefaultCommandRunner) runProjectCmdsParallel(cmds []models.ProjectComma
var results []models.ProjectResult
mux := &sync.Mutex{}

wg := sizedwaitgroup.New(15)
wg := sizedwaitgroup.New(c.ParallelPoolSize)
for _, pCmd := range cmds {
pCmd := pCmd
var execute func()
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
SilenceVCSStatusNoPlans: userConfig.SilenceVCSStatusNoPlans,
DisableApplyAll: userConfig.DisableApplyAll,
DisableAutoplan: userConfig.DisableAutoplan,
ParallelPoolSize: userConfig.ParallelPoolSize,
ProjectCommandBuilder: &events.DefaultProjectCommandBuilder{
ParserValidator: validator,
ProjectFinder: &events.DefaultProjectFinder{},
Expand Down
1 change: 1 addition & 0 deletions server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type UserConfig struct {
GitlabWebhookSecret string `mapstructure:"gitlab-webhook-secret"`
HidePrevPlanComments bool `mapstructure:"hide-prev-plan-comments"`
LogLevel string `mapstructure:"log-level"`
ParallelPoolSize int `mapstructure:"parallel-pool-size"`
PlanDrafts bool `mapstructure:"allow-draft-prs"`
Port int `mapstructure:"port"`
RepoConfig string `mapstructure:"repo-config"`
Expand Down

0 comments on commit c789e1a

Please sign in to comment.