Skip to content

Commit 2fb17b5

Browse files
committed
Add s3 config to list objects version
Signed-off-by: SungJin1212 <[email protected]>
1 parent 3b5011b commit 2fb17b5

File tree

7 files changed

+105
-12
lines changed

7 files changed

+105
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [FEATURE] Ruler: Minimize chances of missed rule group evaluations that can occur due to OOM kills, bad underlying nodes, or due to an unhealthy ruler that appears in the ring as healthy. This feature is enabled via `-ruler.enable-ha-evaluation` flag. #6129
1010
* [FEATURE] Store Gateway: Add an in-memory chunk cache. #6245
1111
* [FEATURE] Chunk Cache: Support multi level cache and add metrics. #6249
12+
* [ENHANCEMENT] S3 Bucket Client: Add a list objects version configs to configure list api object version. #6280
1213
* [ENHANCEMENT] Query Frontend: Add new query stats metrics `cortex_query_samples_scanned_total` and `cortex_query_peak_samples` to track scannedSamples and peakSample per user. #6228
1314
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
1415
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207

docs/blocks-storage/querier.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ blocks_storage:
312312
# CLI flag: -blocks-storage.s3.send-content-md5
313313
[send_content_md5: <boolean> | default = true]
314314
315+
# The list api version. Supported values are: v1, v2, and ''.
316+
# CLI flag: -blocks-storage.s3.list-objects-version
317+
[list_objects_version: <string> | default = ""]
318+
315319
# The s3_sse_config configures the S3 server-side encryption.
316320
# The CLI flags prefix for this block config is: blocks-storage
317321
[sse: <s3_sse_config>]

docs/blocks-storage/store-gateway.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ blocks_storage:
403403
# CLI flag: -blocks-storage.s3.send-content-md5
404404
[send_content_md5: <boolean> | default = true]
405405
406+
# The list api version. Supported values are: v1, v2, and ''.
407+
# CLI flag: -blocks-storage.s3.list-objects-version
408+
[list_objects_version: <string> | default = ""]
409+
406410
# The s3_sse_config configures the S3 server-side encryption.
407411
# The CLI flags prefix for this block config is: blocks-storage
408412
[sse: <s3_sse_config>]

docs/configuration/config-file-reference.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ s3:
563563
# CLI flag: -alertmanager-storage.s3.send-content-md5
564564
[send_content_md5: <boolean> | default = true]
565565
566+
# The list api version. Supported values are: v1, v2, and ''.
567+
# CLI flag: -alertmanager-storage.s3.list-objects-version
568+
[list_objects_version: <string> | default = ""]
569+
566570
# The s3_sse_config configures the S3 server-side encryption.
567571
# The CLI flags prefix for this block config is: alertmanager-storage
568572
[sse: <s3_sse_config>]
@@ -842,6 +846,10 @@ s3:
842846
# CLI flag: -blocks-storage.s3.send-content-md5
843847
[send_content_md5: <boolean> | default = true]
844848
849+
# The list api version. Supported values are: v1, v2, and ''.
850+
# CLI flag: -blocks-storage.s3.list-objects-version
851+
[list_objects_version: <string> | default = ""]
852+
845853
# The s3_sse_config configures the S3 server-side encryption.
846854
# The CLI flags prefix for this block config is: blocks-storage
847855
[sse: <s3_sse_config>]
@@ -4611,6 +4619,10 @@ s3:
46114619
# CLI flag: -ruler-storage.s3.send-content-md5
46124620
[send_content_md5: <boolean> | default = true]
46134621
4622+
# The list api version. Supported values are: v1, v2, and ''.
4623+
# CLI flag: -ruler-storage.s3.list-objects-version
4624+
[list_objects_version: <string> | default = ""]
4625+
46144626
# The s3_sse_config configures the S3 server-side encryption.
46154627
# The CLI flags prefix for this block config is: ruler-storage
46164628
[sse: <s3_sse_config>]
@@ -4898,6 +4910,10 @@ s3:
48984910
# CLI flag: -runtime-config.s3.send-content-md5
48994911
[send_content_md5: <boolean> | default = true]
49004912
4913+
# The list api version. Supported values are: v1, v2, and ''.
4914+
# CLI flag: -runtime-config.s3.list-objects-version
4915+
[list_objects_version: <string> | default = ""]
4916+
49014917
# The s3_sse_config configures the S3 server-side encryption.
49024918
# The CLI flags prefix for this block config is: runtime-config
49034919
[sse: <s3_sse_config>]

pkg/storage/bucket/s3/bucket_client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ func newS3Config(cfg Config) (s3.Config, error) {
102102
Transport: cfg.HTTP.Transport,
103103
},
104104
// Enforce signature version 2 if CLI flag is set
105-
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
106-
BucketLookupType: bucketLookupType,
107-
AWSSDKAuth: cfg.AccessKeyID == "",
105+
ListObjectsVersion: cfg.ListObjectsVersion,
106+
SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
107+
BucketLookupType: bucketLookupType,
108+
AWSSDKAuth: cfg.AccessKeyID == "",
108109
}, nil
109110
}
110111

pkg/storage/bucket/s3/config.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,21 @@ const (
3131
BucketAutoLookup = "auto"
3232
BucketVirtualHostLookup = "virtual-hosted"
3333
BucketPathLookup = "path"
34+
35+
ListObjectsVersionV1 = "v1"
36+
ListObjectsVersionV2 = "v2"
3437
)
3538

3639
var (
3740
supportedSignatureVersions = []string{SignatureVersionV4, SignatureVersionV2}
3841
supportedSSETypes = []string{SSEKMS, SSES3}
3942
supportedBucketLookupTypes = []string{BucketAutoLookup, BucketVirtualHostLookup, BucketPathLookup}
43+
supportedListObjectsVersion = []string{ListObjectsVersionV1, ListObjectsVersionV2}
4044
errUnsupportedSignatureVersion = errors.New("unsupported signature version")
4145
errUnsupportedSSEType = errors.New("unsupported S3 SSE type")
4246
errInvalidSSEContext = errors.New("invalid S3 SSE encryption context")
4347
errInvalidBucketLookupType = errors.New("invalid bucket lookup type")
48+
errInvalidListObjectsVersion = errors.New("invalid list object version")
4449
)
4550

4651
// HTTPConfig stores the http.Transport configuration for the s3 minio client.
@@ -58,15 +63,16 @@ func (cfg *HTTPConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
5863

5964
// Config holds the config options for an S3 backend
6065
type Config struct {
61-
Endpoint string `yaml:"endpoint"`
62-
Region string `yaml:"region"`
63-
BucketName string `yaml:"bucket_name"`
64-
SecretAccessKey flagext.Secret `yaml:"secret_access_key"`
65-
AccessKeyID string `yaml:"access_key_id"`
66-
Insecure bool `yaml:"insecure"`
67-
SignatureVersion string `yaml:"signature_version"`
68-
BucketLookupType string `yaml:"bucket_lookup_type"`
69-
SendContentMd5 bool `yaml:"send_content_md5"`
66+
Endpoint string `yaml:"endpoint"`
67+
Region string `yaml:"region"`
68+
BucketName string `yaml:"bucket_name"`
69+
SecretAccessKey flagext.Secret `yaml:"secret_access_key"`
70+
AccessKeyID string `yaml:"access_key_id"`
71+
Insecure bool `yaml:"insecure"`
72+
SignatureVersion string `yaml:"signature_version"`
73+
BucketLookupType string `yaml:"bucket_lookup_type"`
74+
SendContentMd5 bool `yaml:"send_content_md5"`
75+
ListObjectsVersion string `yaml:"list_objects_version"`
7076

7177
SSE SSEConfig `yaml:"sse"`
7278
HTTP HTTPConfig `yaml:"http"`
@@ -88,6 +94,7 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
8894
f.StringVar(&cfg.SignatureVersion, prefix+"s3.signature-version", SignatureVersionV4, fmt.Sprintf("The signature version to use for authenticating against S3. Supported values are: %s.", strings.Join(supportedSignatureVersions, ", ")))
8995
f.StringVar(&cfg.BucketLookupType, prefix+"s3.bucket-lookup-type", BucketAutoLookup, fmt.Sprintf("The s3 bucket lookup style. Supported values are: %s.", strings.Join(supportedBucketLookupTypes, ", ")))
9096
f.BoolVar(&cfg.SendContentMd5, prefix+"s3.send-content-md5", true, "If true, attach MD5 checksum when upload objects and S3 uses MD5 checksum algorithm to verify the provided digest. If false, use CRC32C algorithm instead.")
97+
f.StringVar(&cfg.ListObjectsVersion, prefix+"s3.list-objects-version", "", fmt.Sprintf("The list api version. Supported values are: %s, and ''.", strings.Join(supportedListObjectsVersion, ", ")))
9198
cfg.SSE.RegisterFlagsWithPrefix(prefix+"s3.sse.", f)
9299
cfg.HTTP.RegisterFlagsWithPrefix(prefix, f)
93100
}
@@ -100,6 +107,11 @@ func (cfg *Config) Validate() error {
100107
if !util.StringsContain(supportedBucketLookupTypes, cfg.BucketLookupType) {
101108
return errInvalidBucketLookupType
102109
}
110+
if cfg.ListObjectsVersion != "" {
111+
if !util.StringsContain(supportedListObjectsVersion, cfg.ListObjectsVersion) {
112+
return errInvalidListObjectsVersion
113+
}
114+
}
103115

104116
if err := cfg.SSE.Validate(); err != nil {
105117
return err

pkg/storage/bucket/s3/config_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,61 @@ func TestSSEConfig_Validate(t *testing.T) {
168168
}
169169
}
170170

171+
func TestS3Config_Validate(t *testing.T) {
172+
tests := map[string]struct {
173+
cfg *Config
174+
expectedErr error
175+
}{
176+
"should pass with valid config": {
177+
cfg: &Config{
178+
SignatureVersion: SignatureVersionV4,
179+
BucketLookupType: BucketAutoLookup,
180+
ListObjectsVersion: ListObjectsVersionV2,
181+
},
182+
expectedErr: nil,
183+
},
184+
"should fail with invalid signature version": {
185+
cfg: &Config{
186+
SignatureVersion: "v3",
187+
BucketLookupType: BucketAutoLookup,
188+
ListObjectsVersion: ListObjectsVersionV2,
189+
},
190+
expectedErr: errUnsupportedSignatureVersion,
191+
},
192+
"should fail with invalid bucket lookup type": {
193+
cfg: &Config{
194+
SignatureVersion: SignatureVersionV4,
195+
BucketLookupType: "dummy",
196+
ListObjectsVersion: ListObjectsVersionV2,
197+
},
198+
expectedErr: errInvalidBucketLookupType,
199+
},
200+
"should fail with invalid list objects version": {
201+
cfg: &Config{
202+
SignatureVersion: SignatureVersionV4,
203+
BucketLookupType: BucketAutoLookup,
204+
ListObjectsVersion: "v3",
205+
},
206+
expectedErr: errInvalidListObjectsVersion,
207+
},
208+
"should pass with empty list objects version": {
209+
cfg: &Config{
210+
SignatureVersion: SignatureVersionV4,
211+
BucketLookupType: BucketAutoLookup,
212+
ListObjectsVersion: "",
213+
},
214+
expectedErr: nil,
215+
},
216+
}
217+
218+
for testName, test := range tests {
219+
t.Run(testName, func(t *testing.T) {
220+
err := test.cfg.Validate()
221+
require.Equal(t, test.expectedErr, err)
222+
})
223+
}
224+
}
225+
171226
func TestSSEConfig_BuildMinioConfig(t *testing.T) {
172227
tests := map[string]struct {
173228
cfg *SSEConfig

0 commit comments

Comments
 (0)