-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat(thanos): make use of the new function IterWithAttributes #14793
Changes from all commits
cd567f4
62b09af
ea6f2e9
71aa42a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package bucket | |
import ( | ||
"context" | ||
"io" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/go-kit/log" | ||
|
@@ -16,6 +17,7 @@ import ( | |
type ObjectClientAdapter struct { | ||
bucket, hedgedBucket objstore.Bucket | ||
logger log.Logger | ||
supportsUpdatedAt bool | ||
isRetryableErr func(err error) bool | ||
} | ||
|
||
|
@@ -25,9 +27,10 @@ func NewObjectClientAdapter(bucket, hedgedBucket objstore.Bucket, logger log.Log | |
} | ||
|
||
o := &ObjectClientAdapter{ | ||
bucket: bucket, | ||
hedgedBucket: hedgedBucket, | ||
logger: log.With(logger, "component", "bucket_to_object_client_adapter"), | ||
bucket: bucket, | ||
hedgedBucket: hedgedBucket, | ||
logger: log.With(logger, "component", "bucket_to_object_client_adapter"), | ||
supportsUpdatedAt: slices.Contains(bucket.SupportedIterOptions(), objstore.UpdatedAt), | ||
// default to no retryable errors. Override with WithRetryableErrFunc | ||
isRetryableErr: func(_ error) bool { | ||
return false | ||
|
@@ -103,26 +106,39 @@ func (o *ObjectClientAdapter) List(ctx context.Context, prefix, delimiter string | |
|
||
// If delimiter is empty we want to list all files | ||
if delimiter == "" { | ||
iterParams = append(iterParams, objstore.WithRecursiveIter) | ||
iterParams = append(iterParams, objstore.WithRecursiveIter()) | ||
} | ||
|
||
err := o.bucket.Iter(ctx, prefix, func(objectKey string) error { | ||
if o.supportsUpdatedAt { | ||
iterParams = append(iterParams, objstore.WithUpdatedAt()) | ||
} | ||
|
||
err := o.bucket.IterWithAttributes(ctx, prefix, func(attrs objstore.IterObjectAttributes) error { | ||
// CommonPrefixes are keys that have the prefix and have the delimiter | ||
// as a suffix | ||
objectKey := attrs.Name | ||
if delimiter != "" && strings.HasSuffix(objectKey, delimiter) { | ||
commonPrefixes = append(commonPrefixes, client.StorageCommonPrefix(objectKey)) | ||
return nil | ||
} | ||
|
||
// TODO: remove this once thanos support IterWithAttributes | ||
attr, err := o.bucket.Attributes(ctx, objectKey) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get attributes for %s", objectKey) | ||
lastModified, ok := attrs.LastModified() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should fail if lastModified is not set, callers of |
||
if o.supportsUpdatedAt && !ok { | ||
return errors.Errorf("failed to get lastModified for %s", objectKey) | ||
} | ||
// Some providers do not support supports UpdatedAt option. For those we need | ||
// to make an additional request to get the last modified time. | ||
if !o.supportsUpdatedAt { | ||
attr, err := o.bucket.Attributes(ctx, objectKey) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get attributes for %s", objectKey) | ||
} | ||
lastModified = attr.LastModified | ||
} | ||
|
||
storageObjects = append(storageObjects, client.StorageObject{ | ||
Key: objectKey, | ||
ModifiedAt: attr.LastModified, | ||
ModifiedAt: lastModified, | ||
}) | ||
|
||
return nil | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's also check if the provider supports
UpdatedAt
option, if not we should make a follow-up Attributes call to fetch it given the callers ofList
might use theModifiedAt
field