feat: new worker config for minimumAvailableCapacity

This commit is contained in:
Damian Debkowski authored and Elim Tsiagbey committed 2024-04-05 16:45:52 -04:00
1 parent f483d1417c
commit aea473c77b
10 files changed
+322 -68

No files matched your search

+56 -48
View File
@@ -66,54 +66,55 @@ type Command struct {
controller *controller.Controller
worker *worker.Worker
flagLogLevel string
flagLogFormat string
flagCombineLogs bool
flagLoginName string
flagPassword string
flagUnprivilegedLoginName string
flagUnprivilegedPassword string
flagIdSuffix string
flagSecondaryIdSuffix string
flagHostAddress string
flagTargetDefaultPort int
flagTargetSessionMaxSeconds int
flagTargetSessionConnectionLimit int
flagControllerApiListenAddr string
flagControllerClusterListenAddr string
flagControllerPublicClusterAddr string
flagControllerOnly bool
flagWorkerAuthKey string
flagWorkerProxyListenAddr string
flagWorkerPublicAddr string
flagOpsListenAddr string
flagUiPassthroughDir string
flagRecoveryKey string
flagDatabaseUrl string
flagContainerImage string
flagDisableDatabaseDestruction bool
flagEventFormat string
flagAudit string
flagObservations string
flagTelemetry string
flagSysEvents string
flagEveryEventAllowFilters []string
flagEveryEventDenyFilters []string
flagCreateLoopbackPlugin bool
flagPluginExecutionDir string
flagSkipPlugins bool
flagSkipOidcAuthMethodCreation bool
flagSkipLdapAuthMethodCreation bool
flagSkipAliasTargetCreation bool
flagWorkerDnsServer string
flagWorkerAuthMethod string
flagWorkerAuthStorageDir string
flagWorkerAuthStorageSkipCleanup bool
flagWorkerAuthWorkerRotationInterval time.Duration
flagWorkerAuthCaCertificateLifetime time.Duration
flagWorkerAuthDebuggingEnabled bool
flagWorkerRecordingStorageDir string
flagBsrKey string
flagLogLevel string
flagLogFormat string
flagCombineLogs bool
flagLoginName string
flagPassword string
flagUnprivilegedLoginName string
flagUnprivilegedPassword string
flagIdSuffix string
flagSecondaryIdSuffix string
flagHostAddress string
flagTargetDefaultPort int
flagTargetSessionMaxSeconds int
flagTargetSessionConnectionLimit int
flagControllerApiListenAddr string
flagControllerClusterListenAddr string
flagControllerPublicClusterAddr string
flagControllerOnly bool
flagWorkerAuthKey string
flagWorkerProxyListenAddr string
flagWorkerPublicAddr string
flagOpsListenAddr string
flagUiPassthroughDir string
flagRecoveryKey string
flagDatabaseUrl string
flagContainerImage string
flagDisableDatabaseDestruction bool
flagEventFormat string
flagAudit string
flagObservations string
flagTelemetry string
flagSysEvents string
flagEveryEventAllowFilters []string
flagEveryEventDenyFilters []string
flagCreateLoopbackPlugin bool
flagPluginExecutionDir string
flagSkipPlugins bool
flagSkipOidcAuthMethodCreation bool
flagSkipLdapAuthMethodCreation bool
flagSkipAliasTargetCreation bool
flagWorkerDnsServer string
flagWorkerAuthMethod string
flagWorkerAuthStorageDir string
flagWorkerAuthStorageSkipCleanup bool
flagWorkerAuthWorkerRotationInterval time.Duration
flagWorkerAuthCaCertificateLifetime time.Duration
flagWorkerAuthDebuggingEnabled bool
flagWorkerRecordingStorageDir string
flagWorkerRecordingStorageMinimumAvailableCapacity string
flagBsrKey string
}
func (c *Command) Synopsis() string {
@@ -426,6 +427,12 @@ func (c *Command) Flags() *base.FlagSets {
Usage: "Specifies the directory to store worker session recordings in dev mode. If not provided a temp directory will be created. Session recording is an Enterprise-only feature.",
})
f.StringVar(&base.StringVar{
Name: "worker-recording-storage-minimum-available-capacity",
Target: &c.flagWorkerRecordingStorageMinimumAvailableCapacity,
Usage: "Specifies the minimum amount of available disk space a worker needs in the recording storage directory to process sessions with session recording enabled. Input should be a capacity string: 4kib or 3GB. Defaults to 500mib.",
})
f.BoolVar(&base.BoolVar{
Name: "worker-auth-storage-skip-cleanup",
Target: &c.flagWorkerAuthStorageSkipCleanup,
@@ -528,6 +535,7 @@ func (c *Command) Run(args []string) int {
if !c.flagControllerOnly {
c.Config.Worker.AuthStoragePath = c.flagWorkerAuthStorageDir
c.Config.Worker.RecordingStoragePath = c.flagWorkerRecordingStorageDir
c.Config.Worker.RecordingStorageMinimumAvailableCapacity = c.flagWorkerRecordingStorageMinimumAvailableCapacity
if c.Config.Worker.RecordingStoragePath == "" {
// Create a temp dir for recording storage
+1
View File
@@ -71,6 +71,7 @@ func TestCommand_Flags(t *testing.T) {
assert.Contains(completions, "-worker-auth-method")
assert.Contains(completions, "-worker-auth-storage-dir")
assert.Contains(completions, "-worker-recording-storage-dir")
assert.Contains(completions, "-worker-recording-storage-minimum-available-capacity")
assert.Contains(completions, "-worker-auth-storage-skip-cleanup")
// keep adding assertions for other flags which should be set as a result of cmd.Flags()
+29 -4
View File
@@ -23,6 +23,7 @@ import (
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/event"
"github.com/hashicorp/boundary/internal/ratelimit"
"github.com/hashicorp/boundary/internal/storage"
"github.com/hashicorp/boundary/internal/util"
kms_plugin_assets "github.com/hashicorp/boundary/plugins/kms"
"github.com/hashicorp/boundary/sdk/wrapper"
@@ -196,7 +197,7 @@ type Controller struct {
// TODO: This isn't documented (on purpose) because the right place for this
// is central configuration so you can't drift across controllers, but we
// don't have that yet.
WorkerStatusGracePeriod interface{} `hcl:"worker_status_grace_period"`
WorkerStatusGracePeriod any `hcl:"worker_status_grace_period"`
WorkerStatusGracePeriodDuration time.Duration `hcl:"-"`
// LivenessTimeToStale represents the period of time (as a duration) after
@@ -206,7 +207,7 @@ type Controller struct {
// TODO: This isn't documented (on purpose) because the right place for this
// is central configuration so you can't drift across controllers, but we
// don't have that yet.
LivenessTimeToStale interface{} `hcl:"liveness_time_to_stale"`
LivenessTimeToStale any `hcl:"liveness_time_to_stale"`
LivenessTimeToStaleDuration time.Duration `hcl:"-"`
// SchedulerRunJobInterval is the time interval between waking up the
@@ -275,7 +276,7 @@ type Worker struct {
// canceling it to try again.
//
// TODO: This is currently not documented and considered internal.
StatusCallTimeout interface{} `hcl:"status_call_timeout"`
StatusCallTimeout any `hcl:"status_call_timeout"`
StatusCallTimeoutDuration time.Duration `hcl:"-"`
// SuccessfulStatusGracePeriod represents the period of time (as a duration)
@@ -284,7 +285,7 @@ type Worker struct {
// less than StatusCallTimeout.
//
// TODO: This is currently not documented and considered internal.
SuccessfulStatusGracePeriod interface{} `hcl:"successful_status_grace_period"`
SuccessfulStatusGracePeriod any `hcl:"successful_status_grace_period"`
SuccessfulStatusGracePeriodDuration time.Duration `hcl:"-"`
// AuthStoragePath represents the location a worker stores its node credentials, if set
@@ -294,6 +295,15 @@ type Worker struct {
// they are sync'ed to the corresponding storage bucket. The path must already exist.
RecordingStoragePath string `hcl:"recording_storage_path"`
// RecordingStorageMinimumAvailableCapacity represents the minimum amount of available
// disk space a worker needs in the path defined by RecordingStoragePath for processing
// sessions with recording enabled. The expected input value for this field is a
// “capacity string“. Supported suffixes are kb, kib, mb, mib, gb, gib, tb, tib, which
// are not case sensitive. We use a raw interface for parsing so that users can input a
// "capacity string" which is converted into a uint64 value that is measured in bytes.
RecordingStorageMinimumAvailableCapacity any `hcl:"recording_storage_minimum_available_capacity"`
RecordingStorageMinimumAvailableDiskSpace uint64 `hcl:"-"`
// ControllerGeneratedActivationToken is a controller-generated activation
// token used to register this worker to the cluster. It can be a path, env
// var, or direct value.
@@ -790,6 +800,21 @@ func Parse(d string) (*Config, error) {
return nil, errors.New("Successful status grace period value is negative")
}
if !util.IsNil(result.Worker.RecordingStorageMinimumAvailableCapacity) {
if result.Worker.RecordingStoragePath == "" {
return nil, errors.New("recording_storage_path cannot be empty when providing recording_storage_minimum_available_capacity")
}
recordingStorageMinimumAvailableDiskSpace, err := parseutil.ParseCapacityString(result.Worker.RecordingStorageMinimumAvailableCapacity)
if err != nil {
return result, err
}
result.Worker.RecordingStorageMinimumAvailableDiskSpace = recordingStorageMinimumAvailableDiskSpace
}
// RecordingStorageMinimumAvailableDiskSpace defaults to 500MiB when not set by the user
if result.Worker.RecordingStoragePath != "" && result.Worker.RecordingStorageMinimumAvailableDiskSpace == 0 {
result.Worker.RecordingStorageMinimumAvailableDiskSpace = storage.DefaultMinimumAvailableDiskSpace
}
switch {
case result.Worker.StatusCallTimeoutDuration == 0 && result.Worker.SuccessfulStatusGracePeriodDuration == 0:
// Nothing
+148
View File
@@ -575,6 +575,154 @@ func TestDevWorkerCredentialStoragePath(t *testing.T) {
}
}
func TestDevWorkerRecordingStorageMinimumAvailableCapacity(t *testing.T) {
t.Parallel()
td := t.TempDir()
tests := []struct {
name string
devWorkerProvidedConfiguration string
storagePath string
storageCapacity string
expectedDiskSpace uint64
expectedErrMsg string
}{
{
name: "empty storage with empty capacity",
devWorkerProvidedConfiguration: `
listener "tcp" {
purpose = "proxy"
}
worker {
name = "w_1234567890"
description = "A default worker created in dev mode"
initial_upstreams = ["127.0.0.1"]
tags {
type = ["dev", "local"]
}
}
`,
expectedDiskSpace: 0,
storagePath: "",
},
{
name: "empty storage path with set capacity",
devWorkerProvidedConfiguration: `
listener "tcp" {
purpose = "proxy"
}
worker {
name = "w_1234567890"
description = "A default worker created in dev mode"
initial_upstreams = ["127.0.0.1"]
tags {
type = ["dev", "local"]
}
recording_storage_minimum_available_capacity = "4kib"
}
`,
expectedErrMsg: "recording_storage_path cannot be empty when providing recording_storage_minimum_available_capacity",
},
{
name: "storage path with empty capacity defaults to 500mib",
devWorkerProvidedConfiguration: fmt.Sprintf(`
listener "tcp" {
purpose = "proxy"
}
worker {
name = "w_1234567890"
description = "A default worker created in dev mode"
initial_upstreams = ["127.0.0.1"]
tags {
type = ["dev", "local"]
}
recording_storage_path = "%v"
}
`, td),
storagePath: td,
expectedDiskSpace: 524288000,
},
{
name: "storage path with capacity string",
devWorkerProvidedConfiguration: fmt.Sprintf(`
listener "tcp" {
purpose = "proxy"
}
worker {
name = "w_1234567890"
description = "A default worker created in dev mode"
initial_upstreams = ["127.0.0.1"]
tags {
type = ["dev", "local"]
}
recording_storage_path = "%v"
recording_storage_minimum_available_capacity = "4kib"
}
`, td),
storagePath: td,
expectedDiskSpace: 4096,
},
{
name: "storage path with raw byte value",
devWorkerProvidedConfiguration: fmt.Sprintf(`
listener "tcp" {
purpose = "proxy"
}
worker {
name = "w_1234567890"
description = "A default worker created in dev mode"
initial_upstreams = ["127.0.0.1"]
tags {
type = ["dev", "local"]
}
recording_storage_path = "%v"
recording_storage_minimum_available_capacity = "4096"
}
`, td),
storagePath: td,
expectedDiskSpace: 4096,
},
{
name: "storage path with invalid capacity input",
devWorkerProvidedConfiguration: fmt.Sprintf(`
listener "tcp" {
purpose = "proxy"
}
worker {
name = "w_1234567890"
description = "A default worker created in dev mode"
initial_upstreams = ["127.0.0.1"]
tags {
type = ["dev", "local"]
}
recording_storage_path = "%v"
recording_storage_minimum_available_capacity = "gib"
}
`, td),
storagePath: td,
expectedErrMsg: "could not parse capacity from input",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parsed, err := Parse(devConfig + tt.devWorkerProvidedConfiguration)
if tt.expectedErrMsg != "" {
require.Error(t, err)
assert.ErrorContains(t, err, tt.expectedErrMsg)
return
}
require.NoError(t, err)
assert.Equal(t, tt.storagePath, parsed.Worker.RecordingStoragePath)
assert.Equal(t, tt.expectedDiskSpace, parsed.Worker.RecordingStorageMinimumAvailableDiskSpace)
})
}
}
func TestDevWorkerRecordingStoragePath(t *testing.T) {
t.Parallel()
td := t.TempDir()