-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add support for object attributes in Iter call #63
Conversation
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 like this change a lot!
prefixed_bucket.go
Outdated
return p.bkt.Iter(ctx, pdir, func(s string) error { | ||
return f(strings.TrimPrefix(s, p.prefix+DirDelim)) | ||
return p.bkt.Iter(ctx, pdir, func(s string, _ ObjectAttributes) error { | ||
return f(strings.TrimPrefix(s, p.prefix+DirDelim), EmptyObjectAttributes) |
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.
why wouldn't it be passed through here?
objstore.go
Outdated
// Entries are passed to function in sorted order. | ||
Iter(ctx context.Context, dir string, f func(string) error, options ...IterOption) error | ||
Iter(ctx context.Context, dir string, f func(name string, attrs ObjectAttributes) error, options ...IterOption) error |
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.
If we're already breaking this signature, I think we should instead make the whole thing pass only the ObjectAttributes
struct and add the Name
field to it.
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.
This makes sense, and would allow us to extend supported attributes in the future.
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.
Exactly!
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.
Rather than breaking the API, could we add a new API?
Yeah I will look into adding a new APi. I am still not sure how to handle cases where a provider does not support returning attributes. |
An idea may be having a function on the objstore client to check if the feature is supported. Then the Iter() contract is that if the feature is supported, attributes will be fetched, otherwise if the feature is not supported it will error out. It's caller responsability to check if the feature is supported by the actual objstore client and take an informed decision about requesting attributes or not. |
@fpetkovski are there plans to revive this pr? :) Loki project is planning to switch to thanos clients. Having this change will reduce the fanout of listing objects along with metadata which now requires Iter call followed by fetching attributes for all objects |
a85daeb
to
6ede0f1
Compare
This commit adds support for an IterWithAttributes on the bucket client. The method allows iterating through objects and getting multiple attributes into the callback function, removing the need to do an Iter followed by Attrs. For now, we only support getting the last updated time as an attribute, but the implementation allows adding more in the future. Not all buckets support this method. The client can check whether the bucket has support by calling the SupportedIterOptions method on the client. Co-authored-by: Ashwanth Goli <iamashwanth@gmail.com> Co-authored-by: Filip Petkovski <filip.petkovsky@gmail.com> Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
6ede0f1
to
3b23d35
Compare
@ashwanthgoli Please take a look again, your changes should be integrated now! |
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.
as far as I can see lgtm
objstore.go
Outdated
// WithUpdatedAt is an option that can be applied to Iter() to | ||
// include the last modified time in the attributes. | ||
// NB: Prefixes may not report last modified time. | ||
// This option is currently supported for the azure, aws, bos, gcs and filesystem providers. |
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.
nit: just to match the provider name
// This option is currently supported for the azure, aws, bos, gcs and filesystem providers. | |
// This option is currently supported for the azure, s3, bos, gcs and filesystem providers. |
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.
Good catch, thanks.
func (i *IterObjectAttributes) SetLastModified(t time.Time) { | ||
i.lastModified = t | ||
} |
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.
Curious question: why did we make assignments to lastModified come through a setter but not name?
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 wanted to make it explicit that lastModified
might not always be set, made it a private field so the getter contract can return time.Time, bool
providers/gcs/gcs.go
Outdated
delimiter = "" | ||
} | ||
|
||
query := &storage.Query{ | ||
it := b.bkt.Objects(ctx, &storage.Query{ |
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.
@fpetkovski i didn't realise this was only fetching Name
attribute before.
I think I removed changes from a previous commit of yours, we need to add it back :)
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.
Reverted the name attribute in the default case.
const op = OpIter | ||
b.metrics.ops.WithLabelValues(op).Inc() | ||
|
||
err := b.bkt.IterWithAttributes(ctx, dir, f, options...) |
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.
updates to b.metrics.opsDuration
metric is missing
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.
Should be there now. PTAL again.
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.
LGTM!
thank you! @fpetkovski |
94d26ca
to
3b23d35
Compare
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
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.
lgtm
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Add support for IterWithAttributes
This commit adds support for an IterWithAttributes on the bucket client.
The method allows iterating through objects and getting multiple attributes
into the callback function, removing the need to do an Iter followed by Attrs.
For now, we only support getting the last updated time as an attribute, but the
implementation allows adding more in the future.
Not all buckets support this method. The client can check whether the bucket has
support by calling the SupportedIterOptions method on the client.
Co-authored-by: Ashwanth Goli iamashwanth@gmail.com
Co-authored-by: Filip Petkovski filip.petkovsky@gmail.com
Signed-off-by: Filip Petkovski filip.petkovsky@gmail.com
Changes
IterWithAttributes
.Verification