Skip to content

feat: add S3 chunk delimiter config to support MinIO running on Windows #16319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5111,6 +5111,12 @@ The `s3_storage_config` block configures the connection to Amazon S3 object stor
# CLI flag: -<prefix>.s3.insecure
[insecure: <boolean> | default = false]

# Delimiter used to replace the default delimiter ':' in chunk IDs when storing
# chunks. This is mainly intended when you run a MinIO instance on a Windows
# machine. You should not change this value inflight.
# CLI flag: -<prefix>.s3.chunk-delimiter
[chunk_delimiter: <string> | default = ""]

http_config:
# Timeout specifies a time limit for requests made by s3 Client.
# CLI flag: -<prefix>.s3.http.timeout
Expand Down
3 changes: 3 additions & 0 deletions pkg/loki/config_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ memberlist:
secret_access_key: def789
insecure: true
disable_dualstack: true
chunk_delimiter: "-"
http_config:
response_header_timeout: 5m`

Expand All @@ -299,6 +300,7 @@ memberlist:
assert.Equal(t, "", actual.SessionToken.String())
assert.Equal(t, true, actual.Insecure)
assert.True(t, actual.DisableDualstack)
assert.Equal(t, "-", actual.ChunkDelimiter)
assert.Equal(t, 5*time.Minute, actual.HTTPConfig.ResponseHeaderTimeout)
assert.Equal(t, false, actual.HTTPConfig.InsecureSkipVerify)

Expand Down Expand Up @@ -364,6 +366,7 @@ memberlist:
assert.Equal(t, "456abc", actual.SessionToken.String())
assert.Equal(t, true, actual.Insecure)
assert.False(t, actual.DisableDualstack)
assert.Equal(t, "", actual.ChunkDelimiter)
assert.Equal(t, 5*time.Minute, actual.HTTPConfig.ResponseHeaderTimeout)
assert.Equal(t, false, actual.HTTPConfig.InsecureSkipVerify)

Expand Down
26 changes: 20 additions & 6 deletions pkg/storage/chunk/client/aws/s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type S3Config struct {
SecretAccessKey flagext.Secret `yaml:"secret_access_key"`
SessionToken flagext.Secret `yaml:"session_token"`
Insecure bool `yaml:"insecure"`
ChunkDelimiter string `yaml:"chunk_delimiter"`
HTTPConfig HTTPConfig `yaml:"http_config"`
SignatureVersion string `yaml:"signature_version"`
StorageClass string `yaml:"storage_class"`
Expand Down Expand Up @@ -113,6 +114,7 @@ func (cfg *S3Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.Var(&cfg.SecretAccessKey, prefix+"s3.secret-access-key", "AWS Secret Access Key")
f.Var(&cfg.SessionToken, prefix+"s3.session-token", "AWS Session Token")
f.BoolVar(&cfg.Insecure, prefix+"s3.insecure", false, "Disable https on s3 connection.")
f.StringVar(&cfg.ChunkDelimiter, prefix+"s3.chunk-delimiter", "", "Delimiter used to replace the default delimiter ':' in chunk IDs when storing chunks. This is mainly intended when you run a MinIO instance on a Windows machine. You should not change this value inflight.")
f.BoolVar(&cfg.DisableDualstack, prefix+"s3.disable-dualstack", false, "Disable forcing S3 dualstack endpoint usage.")

cfg.SSEConfig.RegisterFlagsWithPrefix(prefix+"s3.sse.", f)
Expand Down Expand Up @@ -335,7 +337,7 @@ func (a *S3ObjectClient) objectAttributes(ctx context.Context, objectKey, method
lastErr = instrument.CollectedRequest(ctx, method, s3RequestDuration, instrument.ErrorCode, func(_ context.Context) error {
headObjectInput := &s3.HeadObjectInput{
Bucket: aws.String(a.bucketFromKey(objectKey)),
Key: aws.String(objectKey),
Key: aws.String(a.convertObjectKey(objectKey, true)),
}
headOutput, requestErr := a.S3.HeadObject(headObjectInput)
if requestErr != nil {
Expand Down Expand Up @@ -365,7 +367,7 @@ func (a *S3ObjectClient) DeleteObject(ctx context.Context, objectKey string) err
return instrument.CollectedRequest(ctx, "S3.DeleteObject", s3RequestDuration, instrument.ErrorCode, func(ctx context.Context) error {
deleteObjectInput := &s3.DeleteObjectInput{
Bucket: aws.String(a.bucketFromKey(objectKey)),
Key: aws.String(objectKey),
Key: aws.String(a.convertObjectKey(objectKey, true)),
}

_, err := a.S3.DeleteObjectWithContext(ctx, deleteObjectInput)
Expand Down Expand Up @@ -405,7 +407,7 @@ func (a *S3ObjectClient) GetObject(ctx context.Context, objectKey string) (io.Re
var requestErr error
resp, requestErr = a.hedgedS3.GetObjectWithContext(ctx, &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(objectKey),
Key: aws.String(a.convertObjectKey(objectKey, true)),
})
return requestErr
})
Expand Down Expand Up @@ -442,7 +444,7 @@ func (a *S3ObjectClient) GetObjectRange(ctx context.Context, objectKey string, o
var requestErr error
resp, requestErr = a.hedgedS3.GetObjectWithContext(ctx, &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(objectKey),
Key: aws.String(a.convertObjectKey(objectKey, true)),
Range: aws.String(fmt.Sprintf("bytes=%d-%d", offset, offset+length-1)),
})
return requestErr
Expand All @@ -467,7 +469,7 @@ func (a *S3ObjectClient) PutObject(ctx context.Context, objectKey string, object
putObjectInput := &s3.PutObjectInput{
Body: readSeeker,
Bucket: aws.String(a.bucketFromKey(objectKey)),
Key: aws.String(objectKey),
Key: aws.String(a.convertObjectKey(objectKey, true)),
StorageClass: aws.String(a.cfg.StorageClass),
}

Expand Down Expand Up @@ -504,7 +506,7 @@ func (a *S3ObjectClient) List(ctx context.Context, prefix, delimiter string) ([]

for _, content := range output.Contents {
storageObjects = append(storageObjects, client.StorageObject{
Key: *content.Key,
Key: a.convertObjectKey(*content.Key, false),
ModifiedAt: *content.LastModified,
})
}
Expand Down Expand Up @@ -617,3 +619,15 @@ func IsRetryableErr(err error) bool {
func (a *S3ObjectClient) IsRetryableErr(err error) bool {
return IsRetryableErr(err)
}

// convertObjectKey modifies the object key based on a delimiter and a mode flag determining conversion.
func (a *S3ObjectClient) convertObjectKey(objectKey string, toS3 bool) string {
if len(a.cfg.ChunkDelimiter) == 1 {
if toS3 {
objectKey = strings.ReplaceAll(objectKey, ":", a.cfg.ChunkDelimiter)
} else {
objectKey = strings.ReplaceAll(objectKey, a.cfg.ChunkDelimiter, ":")
}
}
return objectKey
}
Loading