diff --git a/pkg/cortex/modules.go b/pkg/cortex/modules.go index 9e72894f9e..9489fab2ec 100644 --- a/pkg/cortex/modules.go +++ b/pkg/cortex/modules.go @@ -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)