-
Notifications
You must be signed in to change notification settings - Fork 237
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 userProject in java-storage #1205
base: branch-2.2.x
Are you sure you want to change the base?
Conversation
/gcbrun |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## branch-2.2.x #1205 +/- ##
==================================================
+ Coverage 80.82% 80.87% +0.05%
- Complexity 2413 2425 +12
==================================================
Files 167 168 +1
Lines 10790 10836 +46
Branches 1198 1204 +6
==================================================
+ Hits 8721 8764 +43
+ Misses 1541 1536 -5
- Partials 528 536 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -43,10 +44,14 @@ | |||
public class GoogleCloudStorageClientGrpcTracingInterceptor implements ClientInterceptor { | |||
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); | |||
public static final String IDEMPOTENCY_TOKEN_HEADER = "x-goog-gcs-idempotency-token"; | |||
public static final String USER_PROJECT_HEADER = "x-goog-user-project"; |
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 are we doing this as an interceptor? Why not veneer provide this as a config while creating the client. Even better, they should be able to figure this out from the GCE VM they are running (if it is running from VM), correct?
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 are we doing this as an interceptor?
This is Trace interceptor, here we trace the request for userProject
filed. If this field is in headers we do log it. It points towards the requesterPays filed being set for gcsbucket in request.
Why not veneer provide this as a config while creating the client.
Via this code we are not updating the header to use the provided project but other way round. Java-storage client do provide a way for requester-pays to be set.
No. It's a userProject header is the one which carries information of requesterpays
feature of gcs bucket. This has nothing to with the account/project the VM is in. This feature can even be used from machines which are not part of GCP.
@@ -114,6 +116,8 @@ public class GoogleCloudStorageClientImpl extends ForwardingGoogleCloudStorage { | |||
? createStorage( | |||
credentials, options, gRPCInterceptors, pCUExecutorService, downscopedAccessTokenFn) | |||
: clientLibraryStorage; | |||
this.requesterPaysManager = |
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.
Looks like we are adding more than the userProject in this PR? If yes, please update the PR descriptions.
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.
No. it is very specific to requesterPays feature. RequesterPaysManager is created with an idea that multiple GoogleCloundStorage client will be able to share the same caching logic of requesterPaysInfo.
default: | ||
return ErrorType.UNKNOWN; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean userProjectMissing(Exception 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.
rename to isUserProjectMissingError?
} | ||
|
||
public boolean requesterShouldPay(String bucketName) { | ||
if (bucketName == null) { |
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.
when can this happen?
import java.util.function.Function; | ||
|
||
@VisibleForTesting | ||
public class RequesterPaysManager { |
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 not using this in the JSON path as well? Looks like now autobuckets will be there in both GCSImpl and GCSClientImpl?
@@ -270,6 +279,15 @@ private Storage createStorage( | |||
.getService(); | |||
} | |||
|
|||
private Boolean shouldRequesterPay(String bucketName) { |
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 not move this to RequestPaysManager?
@@ -582,6 +586,10 @@ private BlobSourceOption[] generateReadOptions(BlobId blobId) { | |||
blobReadOptions.add( | |||
BlobSourceOption.decryptionKey(storageOptions.getEncryptionKey().value())); | |||
} | |||
if (requesterShouldPay.apply((blobId.getBucket()))) { |
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 can't we have this as a boolean value per GCSClientReadChannel? i.e. what is the value of recomputing this for reach GCS ReadChannel?
public void before() throws IOException { | ||
bucketHelper = new TestBucketHelper("dataproc-requesterpays"); | ||
testBucket = bucketHelper.getUniqueBucketPrefix(); | ||
// Initalizing a storage client as gcsio abstraction don't offer a way to ingested |
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.
ingest
bucketHelper = new TestBucketHelper("dataproc-requesterpays"); | ||
testBucket = bucketHelper.getUniqueBucketPrefix(); | ||
// Initalizing a storage client as gcsio abstraction don't offer a way to ingested | ||
// "requesterPays" filed while creating bucket. |
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.
field
} | ||
|
||
@Test | ||
public void requesterPays_autoMode() throws Exception { |
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.
Do we need testing no-auto use cases?
.setMode(RequesterPaysMode.CUSTOM) | ||
.setBuckets(requesterPaysBuckets) | ||
.build(); | ||
RequesterPaysManager manager = new RequesterPaysManager(options, this::shouldRequesterPays); |
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.
consider moving this to "before test" method
No description provided.