Skip to content

Commit b187879

Browse files
committed
TUN-8914: Add a new configuration to locally override the max-active-flows
## Summary This commit introduces a new command line flag, `--max-active-flows`, which allows overriding the remote configuration for the maximum number of active flows. The flag can be used with the `run` command, like `cloudflared tunnel --no-autoupdate run --token <TUNNEL_TOKEN> --max-active-flows 50000`, or set via an environment variable `TUNNEL_MAX_ACTIVE_FLOWS`. Note that locally-set values always take precedence over remote settings, even if the tunnel is remotely managed. Closes TUN-8914
1 parent 2feccd7 commit b187879

File tree

5 files changed

+134
-39
lines changed

5 files changed

+134
-39
lines changed

cmd/cloudflared/tunnel/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var (
126126
routeFailMsg = fmt.Sprintf("failed to provision routing, please create it manually via Cloudflare dashboard or UI; "+
127127
"most likely you already have a conflicting record there. You can also rerun this command with --%s to overwrite "+
128128
"any existing DNS records for this hostname.", overwriteDNSFlag)
129-
errDeprecatedClassicTunnel = fmt.Errorf("Classic tunnels have been deprecated, please use Named Tunnels. (https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/)")
129+
errDeprecatedClassicTunnel = errors.New("Classic tunnels have been deprecated, please use Named Tunnels. (https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/)")
130130
// TODO: TUN-8756 the list below denotes the flags that do not possess any kind of sensitive information
131131
// however this approach is not maintainble in the long-term.
132132
nonSecretFlagsList = []string{
@@ -214,6 +214,7 @@ var (
214214
"protocol",
215215
"overwrite-dns",
216216
"help",
217+
"max-active-flows",
217218
}
218219
)
219220

cmd/cloudflared/tunnel/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const (
3838
var (
3939
secretFlags = [2]*altsrc.StringFlag{credentialsContentsFlag, tunnelTokenFlag}
4040

41-
configFlags = []string{"autoupdate-freq", "no-autoupdate", "retries", "protocol", "loglevel", "transport-loglevel", "origincert", "metrics", "metrics-update-freq", "edge-ip-version", "edge-bind-address"}
41+
configFlags = []string{"autoupdate-freq", "no-autoupdate", "retries", "protocol", "loglevel", "transport-loglevel", "origincert", "metrics", "metrics-update-freq", "edge-ip-version", "edge-bind-address", "max-active-flows"}
4242
)
4343

4444
func logClientOptions(c *cli.Context, log *zerolog.Logger) {

cmd/cloudflared/tunnel/subcommands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ var (
230230
Usage: "Network diagnostics won't be performed",
231231
Value: false,
232232
}
233+
maxActiveFlowsFlag = &cli.Uint64Flag{
234+
Name: "max-active-flows",
235+
Usage: "Overrides the remote configuration for max active private network flows (TCP/UDP) that this cloudflared instance supports",
236+
EnvVars: []string{"TUNNEL_MAX_ACTIVE_FLOWS"},
237+
}
233238
)
234239

235240
func buildCreateCommand() *cli.Command {
@@ -705,6 +710,7 @@ func buildRunCommand() *cli.Command {
705710
tunnelTokenFlag,
706711
icmpv4SrcFlag,
707712
icmpv6SrcFlag,
713+
maxActiveFlowsFlag,
708714
}
709715
flags = append(flags, configureProxyFlags(false)...)
710716
return &cli.Command{

orchestration/orchestrator.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strconv"
78
"sync"
89
"sync/atomic"
910

10-
"github.com/pkg/errors"
11+
pkgerrors "github.com/pkg/errors"
1112
"github.com/rs/zerolog"
1213

13-
cfdflow "github.com/cloudflare/cloudflared/flow"
14-
1514
"github.com/cloudflare/cloudflared/config"
1615
"github.com/cloudflare/cloudflared/connection"
16+
cfdflow "github.com/cloudflare/cloudflared/flow"
1717
"github.com/cloudflare/cloudflared/ingress"
1818
"github.com/cloudflare/cloudflared/proxy"
1919
"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
@@ -117,6 +117,30 @@ func (o *Orchestrator) UpdateConfig(version int32, config []byte) *pogs.UpdateCo
117117
}
118118
}
119119

120+
// overrideRemoteWarpRoutingWithLocalValues overrides the ingress.WarpRoutingConfig that comes from the remote with
121+
// the local values if there is any.
122+
func (o *Orchestrator) overrideRemoteWarpRoutingWithLocalValues(remoteWarpRouting *ingress.WarpRoutingConfig) error {
123+
return o.overrideMaxActiveFlows(o.config.ConfigurationFlags["max-active-flows"], remoteWarpRouting)
124+
}
125+
126+
// overrideMaxActiveFlows checks the local configuration flags, and if a value is found for the flags.MaxActiveFlows
127+
// overrides the value that comes on the remote ingress.WarpRoutingConfig with the local value.
128+
func (o *Orchestrator) overrideMaxActiveFlows(maxActiveFlowsLocalConfig string, remoteWarpRouting *ingress.WarpRoutingConfig) error {
129+
// If max active flows isn't defined locally just use the remote value
130+
if maxActiveFlowsLocalConfig == "" {
131+
return nil
132+
}
133+
134+
maxActiveFlowsLocalOverride, err := strconv.ParseUint(maxActiveFlowsLocalConfig, 10, 64)
135+
if err != nil {
136+
return pkgerrors.Wrapf(err, "failed to parse %s", "max-active-flows")
137+
}
138+
139+
// Override the value that comes from the remote with the local value
140+
remoteWarpRouting.MaxActiveFlows = maxActiveFlowsLocalOverride
141+
return nil
142+
}
143+
120144
// The caller is responsible to make sure there is no concurrent access
121145
func (o *Orchestrator) updateIngress(ingressRules ingress.Ingress, warpRouting ingress.WarpRoutingConfig) error {
122146
select {
@@ -125,6 +149,11 @@ func (o *Orchestrator) updateIngress(ingressRules ingress.Ingress, warpRouting i
125149
default:
126150
}
127151

152+
// Overrides the local values, onto the remote values of the warp routing configuration
153+
if err := o.overrideRemoteWarpRoutingWithLocalValues(&warpRouting); err != nil {
154+
return pkgerrors.Wrap(err, "failed to merge local overrides into warp routing configuration")
155+
}
156+
128157
// Assign the internal ingress rules to the parsed ingress
129158
ingressRules.InternalRules = o.internalRules
130159

@@ -139,7 +168,7 @@ func (o *Orchestrator) updateIngress(ingressRules ingress.Ingress, warpRouting i
139168
// The downside is minimized because none of the ingress.OriginService implementation have that requirement
140169
proxyShutdownC := make(chan struct{})
141170
if err := ingressRules.StartOrigins(o.log, proxyShutdownC); err != nil {
142-
return errors.Wrap(err, "failed to start origin")
171+
return pkgerrors.Wrap(err, "failed to start origin")
143172
}
144173

145174
// Update the flow limit since the configuration might have changed

0 commit comments

Comments
 (0)