-
Notifications
You must be signed in to change notification settings - Fork 119
Conversation
Codecov Report
@@ Coverage Diff @@
## master #432 +/- ##
============================================
+ Coverage 69.11% 70.35% +1.24%
- Complexity 635 685 +50
============================================
Files 140 143 +3
Lines 3014 3097 +83
Branches 230 237 +7
============================================
+ Hits 2083 2179 +96
+ Misses 843 831 -12
+ Partials 88 87 -1
Continue to review full report at Codecov.
|
PTAL |
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-all.zip |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
this.clientLibName = name; | ||
this.clientLibVersion = version; | ||
return this; | ||
public String getJvmToken() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
transportToken = null; | ||
|
||
resourceHeaderKey = "google-cloud-resource-prefix"; | ||
resourceToken = null; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
/** Returns the current version of GAX. */ | ||
public static String getGaxVersion() { | ||
String version = PropertiesProvider.loadProperty(gaxProperties, GAX_PROPERTY_FILE, "version"); | ||
return version != null ? version : DEFAULT_VERSION; | ||
return GAX_VERSION; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
gax/build.gradle
Outdated
classes { | ||
dependsOn createProperties | ||
} | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@Test | ||
public void testGaxGrpcVersion() { | ||
String gaxGrpcVersion = GaxGrpcProperties.getGaxGrpcVersion(); | ||
assertNotNull(gaxGrpcVersion); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Metadata.Key.of(header.getKey(), Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
// User-Agent is overridden on gRPC level. The custom User-Agent is supposed to be provided | ||
// differently and only merging with gRPC default value for User-Agent is permitted. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
gax-grpc/build.gradle
Outdated
classes { | ||
dependsOn createProperties | ||
} | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
/** Provides meta-data properties stored in a properties file. */ | ||
@BetaApi | ||
public class PropertiesProvider { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import static com.google.common.truth.Truth.*; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Ping. Update on status here? |
Dependent on googleapis/gax-java#432 Usage: // For manual/semi-manual clients: // Resource Manager // Translate // Compute // Storage // Datastore // Dns // BigQuery // // Logging // Firestore // Spanner HeaderProvider headerProvider = FixedHeaderProvider.create("user-agent", "my-client-name", "custom-header", "custom stuff"); LanguageServiceSettings settings = LanguageServiceSettings.newBuilder().setHeaderProvider(headerProvider).build(); LanguageServiceClient client = LanguageServiceClient.create(settings); // For generated clients: // All others, except Pub/Sub HeaderProvider headerProvider = FixedHeaderProvider.create("user-agent", "my-client-name", "custom-header", "custom stuff"); DatastoreOptions options = DatastoreOptions.newBuilder().setHeaderProvider(headerProvider).build(); Datastore datastore = options.getService(); // Note, PubSub is supported only partially. Full support is dependent on migration of PubSub from Grpc stubs to Gapic stubs
@rdayal there the second part of this change (much bigger than expected originally): googleapis/google-cloud-java#2690 |
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.
Some initial comments on your latest iteration
public static class Builder extends ApiClientHeaderProvider.Builder { | ||
public Builder() { | ||
super(); | ||
setTransportToken("grpc", GaxGrpcProperties.getGrpcVersion()); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if (listElementType instanceof Class) { | ||
headerValue = ImmutableList.of(fromString((Class) listElementType, value)); | ||
} else { | ||
throw new IllegalArgumentException(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
// It seems only String and Long have chances of being used. Not adding other | ||
// classes to avoid having dead code, even though without them this looks incomplete. | ||
throw new IllegalArgumentException(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import java.util.Map; | ||
import org.junit.Test; | ||
|
||
/* |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return this; | ||
} | ||
|
||
public String getGeneratedLibToken() { | ||
return generatedLibToken; | ||
} | ||
|
||
public Builder setGeneratedLibToken(String generatedLibToken) { | ||
this.generatedLibToken = generatedLibToken; | ||
public Builder setGeneratedLibToken(String name, String version) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@garrettjonesgoogle PTAL |
…s, sent by generated clients.
@garrettjonesgoogle PTAL |
* client library making API calls. | ||
*/ | ||
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.") | ||
public class GrpcClientHeaderProvider extends ApiClientHeaderProvider { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Metadata.Key.of(header.getKey(), Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
// User-Agent is overridden on gRPC level. The custom User-Agent is supposed to be provided | ||
// differently and only merging with gRPC default value for User-Agent is permitted. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return jvmToken; | ||
} | ||
|
||
public Builder setJvmToken(String version) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
return gapicVersion; | ||
return GrpcClientHeaderProvider.newBuilder() | ||
.setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(OperationsSettings.class)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return new LocalChannelProvider(new LocalAddress(addressString), null); | ||
} | ||
|
||
public boolean validateSentHeader(String headerKey, Pattern headerPattern) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
private static class LocalHeaderInterceptor implements ClientInterceptor { | ||
private final ClientInterceptor delegate; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
public static Builder newBuilder() { | ||
return ApiClientHeaderProvider.newBuilder().setTransportToken("httpjson", ""); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return generatedRuntimeToken; | ||
} | ||
|
||
public Builder setGeneratedRuntimeToken(String version) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
if (builder.getResourceHeaderKey() != null && builder.getResourceToken() != null) { | ||
headersBuilder.put(builder.getResourceHeaderKey(), builder.getResourceToken()); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -73,6 +73,9 @@ | |||
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.") | |||
public abstract Map<String, String> getHeaders(); | |||
|
|||
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.") | |||
protected abstract Map<String, String> getInternalHeaders(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
PTAL |
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 (of course, as usual, wait until the toolkit and google-cloud-java PRs are approved before merging this)
return jvmToken; | ||
} | ||
|
||
public Builder setJvmToken(String version) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Removed most of the scary reflection methods, since I'm not sure how performant they are (the setHeaders() method will be called for each request). The simplified version is pretty ugly and not generric, but should be ok for practical usage.
User-Agent
header with custom value (the only way User-Agent can be modified).ApiClientHeaderProvider