Skip to content

Commit 2222f71

Browse files
authored
Merge pull request #10 from hashicorp/chappie/NET-824/flags
Add ability to pass in flags for consul dataplane
2 parents da9ed47 + b922920 commit 2222f71

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

cmd/consul-dataplane/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ var (
3232

3333
useCentralTelemetryConfig bool
3434

35-
adminBindAddr string
36-
adminBindPort int
37-
readyBindAddr string
38-
readyBindPort int
35+
adminBindAddr string
36+
adminBindPort int
37+
readyBindAddr string
38+
readyBindPort int
39+
envoyConcurrency int
3940

4041
xdsBindAddr string
4142
xdsBindPort int
@@ -72,6 +73,7 @@ func init() {
7273
flag.IntVar(&adminBindPort, "envoy-admin-bind-port", 19000, "The port on which the Envoy admin server will be available.")
7374
flag.StringVar(&readyBindAddr, "envoy-ready-bind-address", "", "The address on which Envoy's readiness probe will be available.")
7475
flag.IntVar(&readyBindPort, "envoy-ready-bind-port", 0, "The port on which Envoy's readiness probe will be available.")
76+
flag.IntVar(&envoyConcurrency, "envoy-concurrency", 2, "The envoy concurrency denotes the number of threads that envoy will use https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency.")
7577

7678
flag.StringVar(&xdsBindAddr, "xds-bind-addr", "127.0.0.1", "The address on which the Envoy xDS server will be available.")
7779
flag.IntVar(&xdsBindPort, "xds-bind-port", 0, "The port on which the Envoy xDS server will be available.")
@@ -127,6 +129,8 @@ func main() {
127129
AdminBindPort: adminBindPort,
128130
ReadyBindAddress: readyBindAddr,
129131
ReadyBindPort: readyBindPort,
132+
EnvoyConcurrency: envoyConcurrency,
133+
ExtraArgs: flag.Args(),
130134
},
131135
XDSServer: &consuldp.XDSServer{
132136
BindAddress: xdsBindAddr,

pkg/consuldp/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ 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
79+
// ExtraArgs are the extra arguments passed to envoy at startup of the proxy
80+
ExtraArgs []string
7781
}
7882

7983
// XDSServer contains the configuration of the xDS server.

pkg/consuldp/consul_dataplane.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +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-
})
180+
proxy, err := envoy.NewProxy(cdp.envoyProxyConfig(cfg))
185181
if err != nil {
186182
cdp.logger.Error("failed to create new proxy", "error", err)
187183
return fmt.Errorf("failed to create new proxy: %w", err)
@@ -210,3 +206,25 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
210206
}()
211207
return <-doneCh
212208
}
209+
210+
func (cdp *ConsulDataplane) envoyProxyConfig(cfg []byte) envoy.ProxyConfig {
211+
setConcurrency := true
212+
extraArgs := cdp.cfg.Envoy.ExtraArgs
213+
// Users could set the concurrency as an extra args. Take that as priority for best ux
214+
// experience.
215+
for _, v := range extraArgs {
216+
if v == "--concurrency" {
217+
setConcurrency = false
218+
}
219+
}
220+
if setConcurrency {
221+
extraArgs = append(extraArgs, fmt.Sprintf("--concurrency %v", cdp.cfg.Envoy.EnvoyConcurrency))
222+
}
223+
224+
return envoy.ProxyConfig{
225+
Logger: cdp.logger,
226+
LogJSON: cdp.cfg.Logging.LogJSON,
227+
BootstrapConfig: cfg,
228+
ExtraArgs: extraArgs,
229+
}
230+
}

0 commit comments

Comments
 (0)