-
Notifications
You must be signed in to change notification settings - Fork 52
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: Update Gapic generator and Gax to emit api-versioning via header #2671
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1eb09c2
add to ApiClientHeaderProvider and composer to emit header.
zhumin8 87be9f6
adding a golden test with api-version.
zhumin8 c0c8286
test: revert golden changes due to adding api-version to echo proto.
zhumin8 0a77f41
fix: avoid repeating logic.
zhumin8 c1febc9
test: test addition and changes with dedicated proto for testing this…
zhumin8 aef94cf
fix: remove redundant var for test.
zhumin8 96b954d
fix: fix mistake in manual merging.
zhumin8 24f2a5e
test: update showcase goldens after showcase changes in v0.33.0
zhumin8 aea6e77
test: remove redundant test after parameterizing.
zhumin8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: test addition and changes with dedicated proto for testing this…
… feat
- Loading branch information
commit c1febc9e80de15bf21cb52158dbd1b12ff44909b
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
248 changes: 248 additions & 0 deletions
248
...com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettings.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
package com.google.api.version.test.stub; | ||
|
||
import com.google.api.core.ApiFunction; | ||
import com.google.api.gax.core.GaxProperties; | ||
import com.google.api.gax.core.GoogleCredentialsProvider; | ||
import com.google.api.gax.core.InstantiatingExecutorProvider; | ||
import com.google.api.gax.grpc.GaxGrpcProperties; | ||
import com.google.api.gax.grpc.GrpcTransportChannel; | ||
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; | ||
import com.google.api.gax.retrying.RetrySettings; | ||
import com.google.api.gax.rpc.ApiClientHeaderProvider; | ||
import com.google.api.gax.rpc.ClientContext; | ||
import com.google.api.gax.rpc.StatusCode; | ||
import com.google.api.gax.rpc.StubSettings; | ||
import com.google.api.gax.rpc.TransportChannelProvider; | ||
import com.google.api.gax.rpc.UnaryCallSettings; | ||
import com.google.api.version.test.EchoRequest; | ||
import com.google.api.version.test.EchoResponse; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Lists; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import javax.annotation.Generated; | ||
|
||
// AUTO-GENERATED DOCUMENTATION AND CLASS. | ||
/** | ||
* Settings class to configure an instance of {@link EchoWithVersionStub}. | ||
* | ||
* <p>The default instance has everything set to sensible defaults: | ||
* | ||
* <ul> | ||
* <li>The default service address (localhost) and default port (7469) are used. | ||
* <li>Credentials are acquired automatically through Application Default Credentials. | ||
* <li>Retries are configured for idempotent methods but not for non-idempotent methods. | ||
* </ul> | ||
* | ||
* <p>The builder of this class is recursive, so contained classes are themselves builders. When | ||
* build() is called, the tree of builders is called to create the complete settings object. | ||
* | ||
* <p>For example, to set the total timeout of echoWithVersionMethod to 30 seconds: | ||
* | ||
* <pre>{@code | ||
* // This snippet has been automatically generated and should be regarded as a code template only. | ||
* // It will require modifications to work: | ||
* // - It may require correct/in-range values for request initialization. | ||
* // - It may require specifying regional endpoints when creating the service client as shown in | ||
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library | ||
* EchoWithVersionStubSettings.Builder echoWithVersionSettingsBuilder = | ||
* EchoWithVersionStubSettings.newBuilder(); | ||
* echoWithVersionSettingsBuilder | ||
* .echoWithVersionMethodSettings() | ||
* .setRetrySettings( | ||
* echoWithVersionSettingsBuilder | ||
* .echoWithVersionMethodSettings() | ||
* .getRetrySettings() | ||
* .toBuilder() | ||
* .setTotalTimeout(Duration.ofSeconds(30)) | ||
* .build()); | ||
* EchoWithVersionStubSettings echoWithVersionSettings = echoWithVersionSettingsBuilder.build(); | ||
* }</pre> | ||
*/ | ||
@Generated("by gapic-generator-java") | ||
public class EchoWithVersionStubSettings extends StubSettings<EchoWithVersionStubSettings> { | ||
/** The default scopes of the service. */ | ||
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES = | ||
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build(); | ||
|
||
private final UnaryCallSettings<EchoRequest, EchoResponse> echoWithVersionMethodSettings; | ||
|
||
/** Returns the object with the settings used for calls to echoWithVersionMethod. */ | ||
public UnaryCallSettings<EchoRequest, EchoResponse> echoWithVersionMethodSettings() { | ||
return echoWithVersionMethodSettings; | ||
} | ||
|
||
public EchoWithVersionStub createStub() throws IOException { | ||
if (getTransportChannelProvider() | ||
.getTransportName() | ||
.equals(GrpcTransportChannel.getGrpcTransportName())) { | ||
return GrpcEchoWithVersionStub.create(this); | ||
} | ||
throw new UnsupportedOperationException( | ||
String.format( | ||
"Transport not supported: %s", getTransportChannelProvider().getTransportName())); | ||
} | ||
|
||
/** Returns a builder for the default ExecutorProvider for this service. */ | ||
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { | ||
return InstantiatingExecutorProvider.newBuilder(); | ||
} | ||
|
||
/** Returns the default service endpoint. */ | ||
public static String getDefaultEndpoint() { | ||
return "localhost:7469"; | ||
} | ||
|
||
/** Returns the default mTLS service endpoint. */ | ||
public static String getDefaultMtlsEndpoint() { | ||
return "localhost:7469"; | ||
} | ||
|
||
/** Returns the default service scopes. */ | ||
public static List<String> getDefaultServiceScopes() { | ||
return DEFAULT_SERVICE_SCOPES; | ||
} | ||
|
||
/** Returns a builder for the default credentials for this service. */ | ||
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { | ||
return GoogleCredentialsProvider.newBuilder() | ||
.setScopesToApply(DEFAULT_SERVICE_SCOPES) | ||
.setUseJwtAccessWithScope(true); | ||
} | ||
|
||
/** Returns a builder for the default ChannelProvider for this service. */ | ||
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { | ||
return InstantiatingGrpcChannelProvider.newBuilder() | ||
.setMaxInboundMessageSize(Integer.MAX_VALUE); | ||
} | ||
|
||
public static TransportChannelProvider defaultTransportChannelProvider() { | ||
return defaultGrpcTransportProviderBuilder().build(); | ||
} | ||
|
||
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { | ||
return ApiClientHeaderProvider.newBuilder() | ||
.setGeneratedLibToken( | ||
"gapic", GaxProperties.getLibraryVersion(EchoWithVersionStubSettings.class)) | ||
.setTransportToken(GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()) | ||
.setApiVersionToken("fake_version"); | ||
} | ||
|
||
/** Returns a new builder for this class. */ | ||
public static Builder newBuilder() { | ||
return Builder.createDefault(); | ||
} | ||
|
||
/** Returns a new builder for this class. */ | ||
public static Builder newBuilder(ClientContext clientContext) { | ||
return new Builder(clientContext); | ||
} | ||
|
||
/** Returns a builder containing all the values of this settings class. */ | ||
public Builder toBuilder() { | ||
return new Builder(this); | ||
} | ||
|
||
protected EchoWithVersionStubSettings(Builder settingsBuilder) throws IOException { | ||
super(settingsBuilder); | ||
|
||
echoWithVersionMethodSettings = settingsBuilder.echoWithVersionMethodSettings().build(); | ||
} | ||
|
||
/** Builder for EchoWithVersionStubSettings. */ | ||
public static class Builder extends StubSettings.Builder<EchoWithVersionStubSettings, Builder> { | ||
private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders; | ||
private final UnaryCallSettings.Builder<EchoRequest, EchoResponse> | ||
echoWithVersionMethodSettings; | ||
private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>> | ||
RETRYABLE_CODE_DEFINITIONS; | ||
|
||
static { | ||
ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions = | ||
ImmutableMap.builder(); | ||
definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList())); | ||
RETRYABLE_CODE_DEFINITIONS = definitions.build(); | ||
} | ||
|
||
private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS; | ||
|
||
static { | ||
ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder(); | ||
RetrySettings settings = null; | ||
settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); | ||
definitions.put("no_retry_params", settings); | ||
RETRY_PARAM_DEFINITIONS = definitions.build(); | ||
} | ||
|
||
protected Builder() { | ||
this(((ClientContext) null)); | ||
} | ||
|
||
protected Builder(ClientContext clientContext) { | ||
super(clientContext); | ||
|
||
echoWithVersionMethodSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); | ||
|
||
unaryMethodSettingsBuilders = | ||
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(echoWithVersionMethodSettings); | ||
initDefaults(this); | ||
} | ||
|
||
protected Builder(EchoWithVersionStubSettings settings) { | ||
super(settings); | ||
|
||
echoWithVersionMethodSettings = settings.echoWithVersionMethodSettings.toBuilder(); | ||
|
||
unaryMethodSettingsBuilders = | ||
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(echoWithVersionMethodSettings); | ||
} | ||
|
||
private static Builder createDefault() { | ||
Builder builder = new Builder(((ClientContext) null)); | ||
|
||
builder.setTransportChannelProvider(defaultTransportChannelProvider()); | ||
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); | ||
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); | ||
builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); | ||
builder.setSwitchToMtlsEndpointAllowed(true); | ||
|
||
return initDefaults(builder); | ||
} | ||
|
||
private static Builder initDefaults(Builder builder) { | ||
builder | ||
.echoWithVersionMethodSettings() | ||
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) | ||
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); | ||
|
||
return builder; | ||
} | ||
|
||
/** | ||
* Applies the given settings updater function to all of the unary API methods in this service. | ||
* | ||
* <p>Note: This method does not support applying settings to streaming methods. | ||
*/ | ||
public Builder applyToAllUnaryMethods( | ||
ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) { | ||
super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); | ||
return this; | ||
} | ||
|
||
public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() { | ||
return unaryMethodSettingsBuilders; | ||
} | ||
|
||
/** Returns the builder for the settings used for calls to echoWithVersionMethod. */ | ||
public UnaryCallSettings.Builder<EchoRequest, EchoResponse> echoWithVersionMethodSettings() { | ||
return echoWithVersionMethodSettings; | ||
} | ||
|
||
@Override | ||
public EchoWithVersionStubSettings build() throws IOException { | ||
return new EchoWithVersionStubSettings(this); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoWithVersionMethod.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.api.version.test.stub.samples; | ||
|
||
// [START goldensample_generated_EchoWithVersionStubSettings_EchoWithVersionMethod_sync] | ||
import com.google.api.version.test.stub.EchoWithVersionStubSettings; | ||
import java.time.Duration; | ||
|
||
public class SyncEchoWithVersionMethod { | ||
|
||
public static void main(String[] args) throws Exception { | ||
syncEchoWithVersionMethod(); | ||
} | ||
|
||
public static void syncEchoWithVersionMethod() throws Exception { | ||
// This snippet has been automatically generated and should be regarded as a code template only. | ||
// It will require modifications to work: | ||
// - It may require correct/in-range values for request initialization. | ||
// - It may require specifying regional endpoints when creating the service client as shown in | ||
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library | ||
EchoWithVersionStubSettings.Builder echoWithVersionSettingsBuilder = | ||
EchoWithVersionStubSettings.newBuilder(); | ||
echoWithVersionSettingsBuilder | ||
.echoWithVersionMethodSettings() | ||
.setRetrySettings( | ||
echoWithVersionSettingsBuilder | ||
.echoWithVersionMethodSettings() | ||
.getRetrySettings() | ||
.toBuilder() | ||
.setTotalTimeout(Duration.ofSeconds(30)) | ||
.build()); | ||
EchoWithVersionStubSettings echoWithVersionSettings = echoWithVersionSettingsBuilder.build(); | ||
} | ||
} | ||
// [END goldensample_generated_EchoWithVersionStubSettings_EchoWithVersionMethod_sync] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Now that this is included as a parameterized test. I don't think we need this method anymore.
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.
Ah. good catch. Done aea6e77.