Skip to content

Commit 69e14c1

Browse files
committed
refactor: Mark storage.prefix as non experimental
This PR migrates from the experimental flag `storage.storage-prefix` to non experimental `storage.prefix` flag. This is on the back of a user that was not able to find this flag and reaching out in the community slack.
1 parent 3da96b8 commit 69e14c1

File tree

12 files changed

+93
-40
lines changed

12 files changed

+93
-40
lines changed

cmd/profilecli/bucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func newBucketWebTool(params *bucketWebToolParams) *bucketWebTool {
8080

8181
func initObjectStoreBucket(params *bucketWebToolParams) (phlareobj.Bucket, error) {
8282
objectStoreConfig := objstoreclient.Config{
83-
StoragePrefix: "",
83+
Prefix: "",
8484
StorageBackendConfig: objstoreclient.StorageBackendConfig{
8585
Backend: params.objectStoreType,
8686
GCS: gcs.Config{

cmd/profilecli/compact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func compact(ctx context.Context, src, dst string, metas []*block.Meta, shards i
6666
Directory: src,
6767
},
6868
},
69-
StoragePrefix: "",
69+
Prefix: "",
7070
}, "profilecli")
7171
if err != nil {
7272
return err

cmd/profilecli/query-blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ func getRemoteBucket(ctx context.Context, params *blocksQueryParams) (objstore.B
178178
BucketName: params.BucketName,
179179
},
180180
},
181-
StoragePrefix: fmt.Sprintf("%s/phlaredb", params.TenantID),
181+
Prefix: fmt.Sprintf("%s/phlaredb", params.TenantID),
182182
}, params.BucketName)
183183
}

cmd/pyroscope/help-all.txt.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ Usage of ./pyroscope:
917917
JSON either from a Google Developers Console client_credentials.json file, or a Google Developers service account key. Needs to be valid JSON, not a filesystem path.
918918
-storage.gcs.tls-handshake-timeout duration
919919
Maximum time to wait for a TLS handshake. 0 means no limit. (default 10s)
920+
-storage.prefix string
921+
Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet characters, hyphens, underscores, dots and forward slashes.
920922
-storage.s3.access-key-id string
921923
S3 access key ID
922924
-storage.s3.bucket-lookup-type string
@@ -958,7 +960,7 @@ Usage of ./pyroscope:
958960
-storage.s3.tls-handshake-timeout duration
959961
Maximum time to wait for a TLS handshake. 0 means no limit. (default 10s)
960962
-storage.storage-prefix string
961-
[experimental] Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet letters.
963+
[experimental] Deprecated: Use 'storage..prefix' instead. Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet characters, hyphens, underscores, dots and forward slashes.
962964
-storage.swift.auth-url string
963965
OpenStack Swift authentication URL
964966
-storage.swift.auth-version int

cmd/pyroscope/help.txt.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ Usage of ./pyroscope:
335335
JSON either from a Google Developers Console client_credentials.json file, or a Google Developers service account key. Needs to be valid JSON, not a filesystem path.
336336
-storage.gcs.tls-handshake-timeout duration
337337
Maximum time to wait for a TLS handshake. 0 means no limit. (default 10s)
338+
-storage.prefix string
339+
Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet characters, hyphens, underscores, dots and forward slashes.
338340
-storage.s3.access-key-id string
339341
S3 access key ID
340342
-storage.s3.bucket-name string

pkg/objstore/client/config.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"strings"
88

9+
"github.com/go-kit/log"
10+
"github.com/go-kit/log/level"
911
"github.com/samber/lo"
1012
"github.com/thanos-io/objstore"
1113

@@ -47,6 +49,7 @@ var (
4749
ErrStoragePrefixStartsWithSlash = errors.New("storage prefix starts with a slash")
4850
ErrStoragePrefixEmptyPathSegment = errors.New("storage prefix contains an empty path segment")
4951
ErrStoragePrefixInvalidCharacters = errors.New("storage prefix contains invalid characters: only alphanumeric, hyphen, underscore, dot, and no segement should be . or ..")
52+
ErrStoragePrefixBothFlagsSet = errors.New("both storage.prefix and storage.storage-prefix are set, please use only storage.prefix, as storage.storage-prefix is deprecated.")
5053
)
5154

5255
type ErrInvalidCharactersInStoragePrefix struct {
@@ -116,7 +119,8 @@ func (cfg *StorageBackendConfig) Validate() error {
116119
type Config struct {
117120
StorageBackendConfig `yaml:",inline"`
118121

119-
StoragePrefix string `yaml:"storage_prefix" category:"experimental"`
122+
Prefix string `yaml:"prefix"`
123+
DeprecatedStoragePrefix string `yaml:"storage_prefix" category:"experimental"` // Deprecated: use Prefix instead
120124

121125
// Not used internally, meant to allow callers to wrap Buckets
122126
// created using this config
@@ -130,7 +134,8 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
130134

131135
func (cfg *Config) RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir string, f *flag.FlagSet) {
132136
cfg.StorageBackendConfig.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir, f)
133-
f.StringVar(&cfg.StoragePrefix, prefix+"storage-prefix", "", "Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet letters.")
137+
f.StringVar(&cfg.Prefix, prefix+"prefix", "", "Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet characters, hyphens, underscores, dots and forward slashes.")
138+
f.StringVar(&cfg.DeprecatedStoragePrefix, prefix+"storage-prefix", "", "Deprecated: Use '"+prefix+".prefix' instead. Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet characters, hyphens, underscores, dots and forward slashes.")
134139
}
135140

136141
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
@@ -176,8 +181,22 @@ func validStoragePrefix(prefix string) error {
176181
return nil
177182
}
178183

179-
func (cfg *Config) Validate() error {
180-
if err := validStoragePrefix(cfg.StoragePrefix); err != nil {
184+
func (cfg *Config) getPrefix() string {
185+
if cfg.Prefix != "" {
186+
return cfg.Prefix
187+
}
188+
189+
return cfg.DeprecatedStoragePrefix
190+
}
191+
192+
func (cfg *Config) Validate(logger log.Logger) error {
193+
if cfg.DeprecatedStoragePrefix != "" {
194+
if cfg.Prefix != "" {
195+
return ErrStoragePrefixBothFlagsSet
196+
}
197+
level.Warn(logger).Log("msg", "bucket config has a deprecated storage.storage-prefix flag set. Please, use storage.prefix instead.")
198+
}
199+
if err := validStoragePrefix(cfg.getPrefix()); err != nil {
181200
return err
182201
}
183202

pkg/objstore/client/factory.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func NewBucket(ctx context.Context, cfg Config, name string) (phlareobj.Bucket,
2424
)
2525
logger := phlarecontext.Logger(ctx)
2626
reg := phlarecontext.Registry(ctx)
27+
prefixPath := cfg.getPrefix()
2728

2829
switch cfg.Backend {
2930
case S3:
@@ -52,10 +53,10 @@ func NewBucket(ctx context.Context, cfg Config, name string) (phlareobj.Bucket,
5253
if err != nil {
5354
return nil, err
5455
}
55-
if cfg.StoragePrefix == "" {
56+
if prefixPath == "" {
5657
return fs, nil
5758
}
58-
return phlareobj.NewPrefixedBucket(fs, cfg.StoragePrefix), nil
59+
return phlareobj.NewPrefixedBucket(fs, prefixPath), nil
5960
default:
6061
return nil, ErrUnsupportedStorageBackend
6162
}
@@ -73,8 +74,8 @@ func NewBucket(ctx context.Context, cfg Config, name string) (phlareobj.Bucket,
7374
}
7475
bkt := phlareobj.NewBucket(objtracing.WrapWithTraces(objstore.WrapWithMetrics(backendClient, reg, name)))
7576

76-
if cfg.StoragePrefix != "" {
77-
bkt = phlareobj.NewPrefixedBucket(bkt, cfg.StoragePrefix)
77+
if prefixPath != "" {
78+
bkt = phlareobj.NewPrefixedBucket(bkt, prefixPath)
7879
}
7980
return bkt, nil
8081
}

pkg/objstore/client/factory_test.go

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path"
1313
"testing"
1414

15+
"github.com/go-kit/log"
1516
"github.com/grafana/dskit/flagext"
1617
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
@@ -106,70 +107,98 @@ func TestClient_ConfigValidation(t *testing.T) {
106107
name string
107108
cfg Config
108109
expectedError error
110+
expectedLog string
109111
}{
110112
{
111-
name: "storage_prefix/valid",
112-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "helloWORLD123"},
113+
name: "prefix/valid",
114+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "helloWORLD123"},
113115
},
114116
{
115-
name: "storage_prefix/valid-subdir",
116-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "hello/world/env"},
117+
name: "prefix/valid-subdir",
118+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "hello/world/env"},
117119
},
118120
{
119-
name: "storage_prefix/valid-subdir-trailing-slash",
120-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "hello/world/env/"},
121+
name: "prefix/valid-subdir-trailing-slash",
122+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "hello/world/env/"},
121123
},
122124
{
123-
name: "storage_prefix/invalid-directory-up",
124-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: ".."},
125+
name: "prefix/invalid-directory-up",
126+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: ".."},
125127
expectedError: ErrStoragePrefixInvalidCharacters,
126128
},
127129
{
128-
name: "storage_prefix/invalid-directory",
129-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "."},
130+
name: "prefix/invalid-directory",
131+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "."},
130132
expectedError: ErrStoragePrefixInvalidCharacters,
131133
},
132134
{
133-
name: "storage_prefix/invalid-absolute-path",
134-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "/hello/world"},
135+
name: "prefix/invalid-absolute-path",
136+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "/hello/world"},
135137
expectedError: ErrStoragePrefixStartsWithSlash,
136138
},
137139
{
138-
name: "storage_prefix/invalid-..-in-a-path-segement",
139-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "hello/../test"},
140+
name: "prefix/invalid-..-in-a-path-segement",
141+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "hello/../test"},
140142
expectedError: ErrStoragePrefixInvalidCharacters,
141143
},
142144
{
143-
name: "storage_prefix/invalid-empty-path-segement",
144-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "hello//test"},
145+
name: "prefix/invalid-empty-path-segement",
146+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "hello//test"},
145147
expectedError: ErrStoragePrefixEmptyPathSegment,
146148
},
147149
{
148-
name: "storage_prefix/invalid-emoji",
149-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "👋"},
150+
name: "prefix/invalid-emoji",
151+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "👋"},
150152
expectedError: ErrStoragePrefixInvalidCharacters,
151153
},
152154
{
153-
name: "storage_prefix/invalid-emoji",
154-
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, StoragePrefix: "hello!world"},
155+
name: "prefix/invalid-emoji",
156+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, Prefix: "hello!world"},
155157
expectedError: ErrStoragePrefixInvalidCharacters,
156158
},
157159
{
158160
name: "unsupported backend",
159161
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: "flash drive"}},
160162
expectedError: ErrUnsupportedStorageBackend,
161163
},
164+
{
165+
name: "prefix/valid-legacy-subdir-trailing-slash",
166+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, DeprecatedStoragePrefix: "hello/world/env/"},
167+
expectedLog: "config has a deprecated storage.storage-prefix flag set",
168+
},
169+
{
170+
name: "prefix/invalid-emoji",
171+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, DeprecatedStoragePrefix: "hello!world"},
172+
expectedError: ErrStoragePrefixInvalidCharacters,
173+
expectedLog: "config has a deprecated storage.storage-prefix flag set",
174+
},
175+
{
176+
name: "prefix/invalid-both-configs",
177+
cfg: Config{StorageBackendConfig: StorageBackendConfig{Backend: Filesystem}, DeprecatedStoragePrefix: "hello-world1", Prefix: "hello-world2"},
178+
expectedError: ErrStoragePrefixBothFlagsSet,
179+
},
162180
}
163181

182+
logBuf := new(bytes.Buffer)
183+
logger := log.NewLogfmtLogger(logBuf)
184+
164185
for _, tc := range testCases {
165186
tc := tc
166187
t.Run(tc.name, func(t *testing.T) {
167-
actualErr := tc.cfg.Validate()
188+
// Reset log buffer
189+
logBuf.Reset()
190+
191+
actualErr := tc.cfg.Validate(logger)
168192
if tc.expectedError != nil {
169193
assert.Equal(t, actualErr, tc.expectedError)
170194
} else {
171195
assert.NoError(t, actualErr)
172196
}
197+
if tc.expectedLog != "" {
198+
assert.Contains(t, logBuf.String(), tc.expectedLog)
199+
} else {
200+
assert.Empty(t, logBuf.String())
201+
}
173202
})
174203
}
175204
}
@@ -185,7 +214,7 @@ func TestNewPrefixedBucketClient(t *testing.T) {
185214
Directory: tempDir,
186215
},
187216
},
188-
StoragePrefix: "prefix",
217+
Prefix: "prefix",
189218
}
190219

191220
client, err := NewBucket(ctx, cfg, "test")

pkg/objstore/reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Test_FileSystem(t *testing.T) {
2121
Directory: testDir,
2222
},
2323
},
24-
StoragePrefix: "testdata/",
24+
Prefix: "testdata/",
2525
}, "foo")
2626
require.NoError(t, err)
2727

pkg/phlare/phlare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (c *Config) Validate() error {
300300
return err
301301
}
302302

303-
if err := c.Storage.Bucket.Validate(); err != nil {
303+
if err := c.Storage.Bucket.Validate(util.Logger); err != nil {
304304
return err
305305
}
306306

0 commit comments

Comments
 (0)