Skip to content
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(storage): easier mocks with BucketMetadata #9886

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

coryan
Copy link
Contributor

@coryan coryan commented Sep 21, 2022

Populating all the fields for BucketMetadata was somewhat difficult. The class tried to prevent applications from setting fields that only the server would set. I thought about adding a BucketMetadataBuilder, but that would duplicate a lot of code without preventing anything. In addition, all the other libraries use protos that allow any field to be set, and that does not seemt to create a lot of trouble or confusion.

I also stopped using the "composition-by-private-inheritance" base because it does not save enough code. I expect this class will go away once I make similar changes to ObjectMetadata.

Part of the work for #8929, I also think it will help with #7142


This change is Reviewable

@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Sep 21, 2022
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: aa7232fc8376bd05196626afed08f828b89bf4fc

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Base: 94.17% // Head: 94.17% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (0ef6d38) compared to base (b3fc63c).
Patch coverage: 98.94% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9886   +/-   ##
=======================================
  Coverage   94.17%   94.17%           
=======================================
  Files        1495     1495           
  Lines      139977   140051   +74     
=======================================
+ Hits       131826   131896   +70     
- Misses       8151     8155    +4     
Impacted Files Coverage Δ
...e/cloud/storage/internal/bucket_metadata_parser.cc 98.36% <97.61%> (+0.30%) ⬆️
google/cloud/storage/bucket_metadata.cc 98.30% <100.00%> (+0.05%) ⬆️
google/cloud/storage/bucket_metadata.h 99.18% <100.00%> (+0.17%) ⬆️
...ud/storage/internal/grpc_bucket_metadata_parser.cc 92.42% <100.00%> (+0.11%) ⬆️
...le/cloud/storage/internal/curl_download_request.cc 88.29% <0.00%> (-1.01%) ⬇️
...cloud/pubsub/internal/subscription_session_test.cc 97.98% <0.00%> (-0.68%) ⬇️
google/cloud/pubsub/subscriber_connection_test.cc 97.75% <0.00%> (-0.57%) ⬇️
google/cloud/storage/internal/common_metadata.h 100.00% <0.00%> (ø)
google/cloud/pubsub/samples/samples.cc 90.77% <0.00%> (+0.07%) ⬆️
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@coryan coryan marked this pull request as ready for review September 21, 2022 19:18
@coryan coryan requested a review from a team as a code owner September 21, 2022 19:18
Copy link
Member

@scotthart scotthart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @coryan)

@coryan coryan enabled auto-merge (squash) September 21, 2022 19:26
Copy link
Contributor

@devbww devbww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q. Did you noticed the codecov warning? I wonder if we're doing something wrong (and perhaps the new uploader now tells us).

google/cloud/storage/bucket_metadata.h Show resolved Hide resolved
Comment on lines 199 to 202
if (!json.contains("owner")) return Status{};
Owner o;
o.entity = json["owner"].value("entity", "");
o.entity_id = json["owner"].value("entityId", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q. Are we at all concerned about repeated lookups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it is in the critical path for anything, but there is no reason to duplicate work either. Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without wanting to derail you any further, it seems like we could still go from 2 lookups to 1 using json.find("owner") (not that I'm familiar with the API).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking that in #9887

@coryan
Copy link
Contributor Author

coryan commented Sep 21, 2022

Q. Did you noticed the codecov warning? I wonder if we're doing something wrong (and perhaps the new uploader now tells us).

If you mean this one:

Current head 74f4ba0 differs from pull request most recent head aa7232f.

I ignore those, they have been around since approximately forever. I am not sure we are doing anything "wrong". My interpretation is that they happen whenever a PR starts is based on an older "HEAD" than the current one (e.g. because something was merged after the PR was created).

Populating all the fields for `BucketMetadata` was somewhat difficult.
The class tried to prevent applications from setting fields that only
the server would set.  I thought about adding a `BucketMetadataBuilder`,
but that would duplicate a lot of code without preventing anything. In
addition, all the other libraries use protos that allow any field to be
set, and that does not seemt to create a lot of trouble or confusion.

I also stopped using the "composition-by-private-inheritance" base
because it does not save enough code.  I expect this class will go away
once I make similar changes to `ObjectMetadata`.
@coryan coryan force-pushed the feat-storage-bucket-metadata-builder branch from aa7232f to 0ef6d38 Compare September 21, 2022 20:00
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 0ef6d38cca1ce45fa5033bbc60c2e7eb0e1a68b9

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@coryan coryan enabled auto-merge (squash) September 21, 2022 20:14
@devbww
Copy link
Contributor

devbww commented Sep 21, 2022

Current head 74f4ba0 differs from pull request most recent head aa7232f.

I ignore those, they have been around since approximately forever. I am not sure we are doing anything "wrong". My interpretation is that they happen whenever a PR starts is based on an older "HEAD" than the current one (e.g. because something was merged after the PR was created).

I was more interested in the other one Patch has no changes to coverable lines. I guess it is not actually a warning, but shouldn't "head" and "base" be different?

@coryan coryan merged commit 0930a10 into googleapis:main Sep 21, 2022
@coryan coryan deleted the feat-storage-bucket-metadata-builder branch September 21, 2022 20:57
@coryan
Copy link
Contributor Author

coryan commented Sep 21, 2022

I was more interested in the other one Patch has no changes to coverable lines. I guess it is not actually a warning, but shouldn't "head" and "base" be different?

Candidly I don't know. I tend to ignore those and only worry about large-ish changes in coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants