implement configurable getDownstreamWorker timeout (#5007)
* implement configurable getDownstreamWorker timeout * add parsing test * typos * fix tests * fix worker tests * 0 is a valid value
This commit is contained in:
1 parent
1a8e954513
commit
350ac90a57
4 files changed
+278
-29
No files matched your search
@@ -210,6 +210,12 @@ type Controller struct {
|
||||
LivenessTimeToStale any `hcl:"liveness_time_to_stale"`
|
||||
LivenessTimeToStaleDuration time.Duration `hcl:"-"`
|
||||
|
||||
// TODO: This isn't documented (on purpose) because the right place for this
|
||||
// is central configuration so you can't drift across controllers and workers
|
||||
// but we don't have that yet.
|
||||
GetDownstreamWorkersTimeout any `hcl:"get_downstream_workers_timeout"`
|
||||
GetDownstreamWorkersTimeoutDuration time.Duration `hcl:"-"`
|
||||
|
||||
// SchedulerRunJobInterval is the time interval between waking up the
|
||||
// scheduler to run pending jobs.
|
||||
//
|
||||
@@ -279,6 +285,13 @@ type Worker struct {
|
||||
StatusCallTimeout any `hcl:"status_call_timeout"`
|
||||
StatusCallTimeoutDuration time.Duration `hcl:"-"`
|
||||
|
||||
// GetDownstreamWorkersTimeout represents the period of time (as a duration) timeout
|
||||
// for GetDownstreamWorkers call in DownstreamWorkerTicker
|
||||
//
|
||||
// TODO: This is currently not documented and considered internal.
|
||||
GetDownstreamWorkersTimeout any `hcl:"get_downstream_workers_timeout"`
|
||||
GetDownstreamWorkersTimeoutDuration time.Duration `hcl:"-"`
|
||||
|
||||
// SuccessfulStatusGracePeriod represents the period of time (as a duration)
|
||||
// that the worker will wait before disconnecting connections if it cannot
|
||||
// successfully complete a status report to a controller. This cannot be
|
||||
@@ -648,6 +661,21 @@ func Parse(d string) (*Config, error) {
|
||||
return nil, errors.New("Controller liveness time to stale value is negative")
|
||||
}
|
||||
|
||||
getDownstreamWorkersTimeout := result.Controller.GetDownstreamWorkersTimeout
|
||||
if util.IsNil(getDownstreamWorkersTimeout) {
|
||||
getDownstreamWorkersTimeout = os.Getenv("BOUNDARY_CONTROLLER_GET_DOWNSTREAM_WORKERS_TIMEOUT")
|
||||
}
|
||||
if getDownstreamWorkersTimeout != nil {
|
||||
t, err := parseutil.ParseDurationSecond(getDownstreamWorkersTimeout)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("error trying to parse controller get_downstream_workers_timeout: %w", err)
|
||||
}
|
||||
result.Controller.GetDownstreamWorkersTimeoutDuration = t
|
||||
}
|
||||
if result.Controller.GetDownstreamWorkersTimeoutDuration < 0 {
|
||||
return nil, errors.New("get downstream workers timeout must be greater than 0")
|
||||
}
|
||||
|
||||
if result.Controller.MaxPageSizeRaw != nil {
|
||||
switch t := result.Controller.MaxPageSizeRaw.(type) {
|
||||
case string:
|
||||
@@ -785,6 +813,21 @@ func Parse(d string) (*Config, error) {
|
||||
return nil, errors.New("Status call timeout value is negative")
|
||||
}
|
||||
|
||||
getDownstreamWorkersTimeoutDuration := result.Worker.GetDownstreamWorkersTimeout
|
||||
if util.IsNil(getDownstreamWorkersTimeoutDuration) {
|
||||
getDownstreamWorkersTimeoutDuration = os.Getenv("BOUNDARY_WORKER_GET_DOWNSTREAM_WORKERS_TIMEOUT")
|
||||
}
|
||||
if getDownstreamWorkersTimeoutDuration != nil {
|
||||
t, err := parseutil.ParseDurationSecond(getDownstreamWorkersTimeoutDuration)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("error trying to parse worker get_downstream_workers_timeout: %w", err)
|
||||
}
|
||||
result.Worker.GetDownstreamWorkersTimeoutDuration = t
|
||||
}
|
||||
if result.Worker.GetDownstreamWorkersTimeoutDuration < 0 {
|
||||
return nil, errors.New("get downstream workers timeout must be greater than 0")
|
||||
}
|
||||
|
||||
successfulStatusGracePeriod := result.Worker.SuccessfulStatusGracePeriod
|
||||
if util.IsNil(successfulStatusGracePeriod) {
|
||||
successfulStatusGracePeriod = os.Getenv("BOUNDARY_WORKER_SUCCESSFUL_STATUS_GRACE_PERIOD")
|
||||
|
||||
@@ -2832,6 +2832,190 @@ func TestSetupWorkerInitialUpstreams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDownstreamWorkersTimeout(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
wantController bool
|
||||
wantWorker bool
|
||||
wantControllerTimeout time.Duration
|
||||
wantWorkerTimeout time.Duration
|
||||
assertErr func(*testing.T, error)
|
||||
}{
|
||||
{
|
||||
name: "controller_valid_time_value",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
get_downstream_workers_timeout = "10s"
|
||||
}`,
|
||||
wantControllerTimeout: 10 * time.Second,
|
||||
wantWorkerTimeout: 0,
|
||||
wantController: true,
|
||||
wantWorker: false,
|
||||
assertErr: nil,
|
||||
},
|
||||
{
|
||||
name: "worker_valid_time_value",
|
||||
in: `
|
||||
worker {
|
||||
name = "example-worker"
|
||||
get_downstream_workers_timeout = "5s"
|
||||
}`,
|
||||
wantControllerTimeout: 0,
|
||||
wantWorkerTimeout: 5 * time.Second,
|
||||
wantController: false,
|
||||
wantWorker: true,
|
||||
assertErr: nil,
|
||||
},
|
||||
{
|
||||
name: "both_valid_time_value",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
get_downstream_workers_timeout = "5s"
|
||||
}
|
||||
worker {
|
||||
name = "example-worker"
|
||||
get_downstream_workers_timeout = "500ms"
|
||||
}`,
|
||||
wantControllerTimeout: 5 * time.Second,
|
||||
wantWorkerTimeout: 500 * time.Millisecond,
|
||||
wantController: true,
|
||||
wantWorker: true,
|
||||
assertErr: nil,
|
||||
},
|
||||
{
|
||||
name: "both_unspecified_defaults_to_zero",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
}
|
||||
worker {
|
||||
name = "example-worker"
|
||||
}`,
|
||||
wantController: true,
|
||||
wantWorker: true,
|
||||
wantControllerTimeout: 0,
|
||||
wantWorkerTimeout: 0,
|
||||
assertErr: nil,
|
||||
},
|
||||
{
|
||||
name: "controller_int_value_no_unit_assumes_seconds",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
get_downstream_workers_timeout = 100
|
||||
}`,
|
||||
wantController: true,
|
||||
wantWorker: false,
|
||||
wantControllerTimeout: 100 * time.Second,
|
||||
wantWorkerTimeout: 0,
|
||||
},
|
||||
{
|
||||
name: "worker_int_value_no_unit_assumes_seconds",
|
||||
in: `
|
||||
worker {
|
||||
name = "example-worker"
|
||||
get_downstream_workers_timeout = 30
|
||||
}`,
|
||||
wantController: false,
|
||||
wantWorker: true,
|
||||
wantWorkerTimeout: 30 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "controller_invalid_bool_value",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
get_downstream_workers_timeout = true
|
||||
}`,
|
||||
wantController: true,
|
||||
wantWorker: false,
|
||||
assertErr: func(t *testing.T, err error) {
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, `error trying to parse controller get_downstream_workers_timeout`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "worker_invalid_bool_value",
|
||||
in: `
|
||||
worker {
|
||||
name = "example-worker"
|
||||
get_downstream_workers_timeout = false
|
||||
}`,
|
||||
wantController: false,
|
||||
wantWorker: true,
|
||||
assertErr: func(t *testing.T, err error) {
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, `error trying to parse worker get_downstream_workers_timeout`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "controller_invalid_empty_value",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
get_downstream_workers_timeout = ""
|
||||
}`,
|
||||
wantController: true,
|
||||
wantWorker: false,
|
||||
wantControllerTimeout: 0,
|
||||
},
|
||||
{
|
||||
name: "worker_invalid_empty_value",
|
||||
in: `
|
||||
worker {
|
||||
name = "example-worker"
|
||||
get_downstream_workers_timeout = ""
|
||||
}`,
|
||||
wantController: false,
|
||||
wantWorker: true,
|
||||
wantWorkerTimeout: 0,
|
||||
},
|
||||
{
|
||||
name: "controller_invalid_zero_value",
|
||||
in: `
|
||||
controller {
|
||||
name = "example-controller"
|
||||
get_downstream_workers_timeout = "0s"
|
||||
}`,
|
||||
wantController: true,
|
||||
wantWorker: false,
|
||||
wantControllerTimeout: 0,
|
||||
},
|
||||
{
|
||||
name: "worker_invalid_zero_value",
|
||||
in: `
|
||||
worker {
|
||||
name = "example-worker"
|
||||
get_downstream_workers_timeout = "0s"
|
||||
}`,
|
||||
wantController: false,
|
||||
wantWorker: true,
|
||||
wantWorkerTimeout: 0,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c, err := Parse(tt.in)
|
||||
if tt.assertErr != nil {
|
||||
tt.assertErr(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
if tt.wantController {
|
||||
require.NotNil(t, c.Controller)
|
||||
require.Equal(t, tt.wantControllerTimeout, c.Controller.GetDownstreamWorkersTimeoutDuration)
|
||||
}
|
||||
if tt.wantWorker {
|
||||
require.NotNil(t, c.Worker)
|
||||
require.Equal(t, tt.wantWorkerTimeout, c.Worker.GetDownstreamWorkersTimeoutDuration)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxPageSize(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in new issue
Block a user