-
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 2 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 | ||||
---|---|---|---|---|---|---|
|
@@ -103,26 +103,40 @@ 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 { | ||||||
supportUpdatedAt := objstore.ValidateIterOptions(o.bucket.SupportedIterOptions(), objstore.WithUpdatedAt()) == nil | ||||||
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.
Suggested change
|
||||||
if supportUpdatedAt { | ||||||
iterParams = append(iterParams, objstore.WithUpdatedAt()) | ||||||
} | ||||||
|
||||||
err := o.bucket.IterWithAttributes(ctx, prefix, func(attrs objstore.IterObjectAttributes) error { | ||||||
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. let's also check if the provider supports |
||||||
// 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 supportUpdatedAt && !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 !supportUpdatedAt { | ||||||
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.
i don't like how this validation method turned out 😓 i think alternatively we could use