diff --git a/.chloggen/add-validation-for-rebound.yaml b/.chloggen/add-validation-for-rebound.yaml new file mode 100644 index 000000000000..d705b63a817f --- /dev/null +++ b/.chloggen/add-validation-for-rebound.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: filestorage + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add directory validation for compaction on-rebound + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35114] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/extension/storage/filestorage/config.go b/extension/storage/filestorage/config.go index 19e288a7655b..d52c10be68bb 100644 --- a/extension/storage/filestorage/config.go +++ b/extension/storage/filestorage/config.go @@ -53,7 +53,7 @@ type CompactionConfig struct { func (cfg *Config) Validate() error { var dirs []string - if cfg.Compaction.OnStart { + if cfg.Compaction.OnStart || cfg.Compaction.OnRebound { dirs = []string{cfg.Directory, cfg.Compaction.Directory} } else { dirs = []string{cfg.Directory} diff --git a/extension/storage/filestorage/config_test.go b/extension/storage/filestorage/config_test.go index 025bc0eecdb9..c467900e549e 100644 --- a/extension/storage/filestorage/config_test.go +++ b/extension/storage/filestorage/config_test.go @@ -95,3 +95,67 @@ func TestHandleProvidingFilePathAsDirWithAnError(t *testing.T) { require.Error(t, err) require.EqualError(t, err, file.Name()+" is not a directory") } + +func TestCompactionDirectory(t *testing.T) { + f := NewFactory() + tests := []struct { + name string + config func(*testing.T) *Config + err error + }{ + { + name: "directory-must-exists-error", + config: func(t *testing.T) *Config { + cfg := f.CreateDefaultConfig().(*Config) + cfg.Directory = t.TempDir() // actual directory + cfg.Compaction.Directory = "/not/a/dir" // not a directory + cfg.Compaction.OnRebound = true + cfg.Compaction.OnStart = true + return cfg + }, + err: os.ErrNotExist, + }, + { + name: "directory-must-exists-error-on-start", + config: func(t *testing.T) *Config { + cfg := f.CreateDefaultConfig().(*Config) + cfg.Directory = t.TempDir() // actual directory + cfg.Compaction.Directory = "/not/a/dir" // not a directory + cfg.Compaction.OnRebound = false + cfg.Compaction.OnStart = true + return cfg + }, + err: os.ErrNotExist, + }, + { + name: "directory-must-exists-error-on-rebound", + config: func(t *testing.T) *Config { + cfg := f.CreateDefaultConfig().(*Config) + cfg.Directory = t.TempDir() // actual directory + cfg.Compaction.Directory = "/not/a/dir" // not a directory + cfg.Compaction.OnRebound = true + cfg.Compaction.OnStart = false + return cfg + }, + err: os.ErrNotExist, + }, + { + name: "compaction-disabled-no-error", + config: func(t *testing.T) *Config { + cfg := f.CreateDefaultConfig().(*Config) + cfg.Directory = t.TempDir() // actual directory + cfg.Compaction.Directory = "/not/a/dir" // not a directory + cfg.Compaction.OnRebound = false + cfg.Compaction.OnStart = false + return cfg + }, + err: nil, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.ErrorIs(t, component.ValidateConfig(test.config(t)), test.err) + }) + } + +}