Skip to content

Commit 2127d93

Browse files
author
Chris Chapman
committed
Move envoy concurrency as top level config into consuldp
1 parent 6646e26 commit 2127d93

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

cmd/consul-dataplane/main.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"flag"
6-
"fmt"
76
"log"
87
"os"
98
"os/signal"
@@ -83,17 +82,6 @@ func validateFlags() {
8382
}
8483
}
8584

86-
func extraEnvoyArguments() []string {
87-
extraEnvoyArgs := flag.Args()
88-
if extraEnvoyArgs == nil {
89-
extraEnvoyArgs = []string{}
90-
}
91-
concurrency := fmt.Sprintf("--concurrency %v", envoyConcurrency)
92-
// to ensure precedence of arguements we prepend before extraArgs so that subsequent params override the
93-
// last set value
94-
return append([]string{concurrency}, extraEnvoyArgs...)
95-
}
96-
9785
func main() {
9886

9987
flag.Parse()
@@ -130,7 +118,8 @@ func main() {
130118
AdminBindPort: adminBindPort,
131119
ReadyBindAddress: readyBindAddr,
132120
ReadyBindPort: readyBindPort,
133-
ExtraArgs: extraEnvoyArguments(),
121+
EnvoyConcurrency: envoyConcurrency,
122+
ExtraArgs: flag.Args(),
134123
},
135124
XDSServer: &consuldp.XDSServer{
136125
BindAddress: xdsBindAddr,

pkg/consuldp/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type EnvoyConfig struct {
7474
ReadyBindAddress string
7575
// ReadyBindPort is the port on which the Envoy readiness probe will be available.
7676
ReadyBindPort int
77+
// EnvoyConcurrency is the envoy concurrency https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency
78+
EnvoyConcurrency int
7779
// ExtraArgs are the extra arguments passed to envoy at startup of the proxy
7880
ExtraArgs []string
7981
}

pkg/consuldp/consul_dataplane.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
177177
}
178178
cdp.logger.Debug("generated envoy bootstrap config", "config", string(cfg))
179179

180-
proxy, err := envoy.NewProxy(envoy.ProxyConfig{
181-
Logger: cdp.logger,
182-
LogJSON: cdp.cfg.Logging.LogJSON,
183-
BootstrapConfig: cfg,
184-
ExtraArgs: cdp.cfg.Envoy.ExtraArgs,
185-
})
180+
proxy, err := envoy.NewProxy(cdp.envoyProxyConfig(cfg))
186181
if err != nil {
187182
cdp.logger.Error("failed to create new proxy", "error", err)
188183
return fmt.Errorf("failed to create new proxy: %w", err)
@@ -211,3 +206,18 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
211206
}()
212207
return <-doneCh
213208
}
209+
210+
func (cdp *ConsulDataplane) envoyProxyConfig(cfg []byte) envoy.ProxyConfig {
211+
// Translate the concurrency parameter to the envoy parameter.
212+
concurrency := fmt.Sprintf("--concurrency %v", cdp.cfg.Envoy.EnvoyConcurrency)
213+
// Prepend so that if the consumer also specifies a concurrency level their specification should take
214+
// precedence.
215+
extraArgs := append([]string{concurrency}, cdp.cfg.Envoy.ExtraArgs...)
216+
217+
return envoy.ProxyConfig{
218+
Logger: cdp.logger,
219+
LogJSON: cdp.cfg.Logging.LogJSON,
220+
BootstrapConfig: cfg,
221+
ExtraArgs: extraArgs,
222+
}
223+
}

0 commit comments

Comments
 (0)