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

add support for userProject in java-storage #1205

Open
wants to merge 2 commits into
base: branch-2.2.x
Choose a base branch
from

Conversation

singhravidutt
Copy link
Contributor

No description provided.

@singhravidutt
Copy link
Contributor Author

/gcbrun

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 72.00000% with 14 lines in your changes missing coverage. Please review.

Project coverage is 80.87%. Comparing base (2152f44) to head (6c75bb1).
Report is 10 commits behind head on branch-2.2.x.

Files with missing lines Patch % Lines
...oogleCloudStorageClientGrpcTracingInterceptor.java 66.66% 2 Missing and 2 partials ⚠️
...oud/hadoop/gcsio/GoogleCloudStorageClientImpl.java 57.14% 3 Missing ⚠️
...oop/gcsio/GoogleCloudStorageClientReadChannel.java 25.00% 2 Missing and 1 partial ⚠️
...oogle/cloud/hadoop/gcsio/RequesterPaysManager.java 88.23% 1 Missing and 1 partial ⚠️
...ogle/cloud/hadoop/util/GrpcErrorTypeExtractor.java 33.33% 0 Missing and 2 partials ⚠️
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     
Flag Coverage Δ
hadoop2integrationtest 64.00% <66.00%> (+0.01%) ⬆️
hadoop2unittest 67.05% <42.00%> (-0.13%) ⬇️
hadoop3integrationtest 63.85% <66.00%> (+<0.01%) ⬆️
hadoop3unittest 67.11% <42.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@singhravidutt singhravidutt marked this pull request as ready for review July 5, 2024 10:05
@@ -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";
Copy link
Contributor

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?

Copy link
Contributor Author

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 =
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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()))) {
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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 {
Copy link
Contributor

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);
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants