Skip to content

Commit

Permalink
Add logic for handling default filesystem root dir
Browse files Browse the repository at this point in the history
We started using a BucketClient for the filesystem where the default directory is an empty string: https://github.com/cortexproject/cortex/blob/af9e20c54ee97f409008f3e86541c5dfa5038e22/pkg/storage/bucket/filesystem/config.go#L17

When we create the new bucket, https://github.com/cortexproject/cortex/blob/526a6d935a948119cf74033a9f79391786022222/vendor/github.com/thanos-io/objstore/providers/filesystem/filesystem.go#L46 uses `filepath.Abs("")` which will use the current working directory as the root directory.

Fixes: cortexproject#6219

Signed-off-by: Charlie Le <[email protected]>
  • Loading branch information
CharlieTLe committed Sep 21, 2024
1 parent d829d65 commit 6dbccee
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/cortex/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ func (t *Cortex) initRuntimeConfig() (services.Service, error) {
registerer := prometheus.WrapRegistererWithPrefix("cortex_", prometheus.DefaultRegisterer)
logger := util_log.Logger
bucketClientFactory := func(ctx context.Context) (objstore.Bucket, error) {
// When directory is an empty string but the runtime-config.file is an absolute path,
// the filesystem.NewBucketClient will treat it as a relative path based on the current working directory
// that the process is running in.
if t.Cfg.RuntimeConfig.StorageConfig.Backend == bucket.Filesystem {
if t.Cfg.RuntimeConfig.StorageConfig.Filesystem.Directory == "" {
// Check if runtime-config.file is an absolute path
if t.Cfg.RuntimeConfig.LoadPath[0] == '/' {
// If it is, set the directory to the root directory so that the filesystem bucket
// will treat it as an absolute path. This is to maintain backwards compatibility
// with the previous behavior of the runtime-config.file of allowing relative and absolute paths.
t.Cfg.RuntimeConfig.StorageConfig.Filesystem.Directory = "/"
}
}
}
return bucket.NewClient(ctx, t.Cfg.RuntimeConfig.StorageConfig, "runtime-config", logger, registerer)
}
serv, err := runtimeconfig.New(t.Cfg.RuntimeConfig, registerer, logger, bucketClientFactory)
Expand Down

0 comments on commit 6dbccee

Please sign in to comment.