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

fix: update regionTag to use service name #1047

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.Method;
Expand Down Expand Up @@ -124,7 +125,8 @@ private static Sample composeUnaryOrLroCallableSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down Expand Up @@ -278,7 +280,8 @@ private static Sample composePagedCallableSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setOverloadDisambiguation("Paged")
.setIsAsynchronous(true)
Expand Down Expand Up @@ -394,7 +397,7 @@ public static Sample composeLroCallableMethod(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientType.reference().name())
.setServiceName(ClassNames.getPureServiceName(clientType.reference().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.setOverloadDisambiguation("LRO")
Expand Down Expand Up @@ -531,7 +534,7 @@ public static Sample composePagedCallableMethod(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientType.reference().name())
.setServiceName(ClassNames.getPureServiceName(clientType.reference().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down Expand Up @@ -717,7 +720,8 @@ private static Sample composeStreamServerSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down Expand Up @@ -796,7 +800,8 @@ private static Sample composeStreamBidiSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down Expand Up @@ -928,7 +933,8 @@ private static Sample composeStreamClientSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.HttpBindings;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.Method;
Expand Down Expand Up @@ -206,7 +207,7 @@ public static Sample composeSetCredentialsSample(TypeNode clientType, TypeNode s
ExprStatement.withExpr(initSettingsVarExpr), ExprStatement.withExpr(initClientVarExpr));
RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientName)
.setServiceName(ClassNames.getPureServiceName(clientName))
.setRpcName(rpcName)
.setOverloadDisambiguation("setCredentialsProvider")
.build();
Expand Down Expand Up @@ -273,7 +274,7 @@ public static Sample composeSetEndpointSample(TypeNode clientType, TypeNode sett
.build();
RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientName)
.setServiceName(ClassNames.getPureServiceName(clientName))
.setRpcName(rpcName)
.setOverloadDisambiguation("setEndpoint")
.build();
Expand Down Expand Up @@ -346,7 +347,7 @@ public static Sample composeTransportSample(
ExprStatement.withExpr(initSettingsVarExpr), ExprStatement.withExpr(initClientVarExpr));
RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientName)
.setServiceName(ClassNames.getPureServiceName(clientName))
.setRpcName(rpcName)
.setOverloadDisambiguation("setCredentialsProvider")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.Method;
Expand Down Expand Up @@ -57,7 +58,8 @@ public static Sample composeEmptyServiceSample(TypeNode clientType) {

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName("emtpy")
.build();

Expand Down Expand Up @@ -169,7 +171,8 @@ static Sample composeSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setOverloadDisambiguation(
SampleComposerUtil.createOverloadDisambiguation(rpcMethodArgVarExprs))
Expand Down Expand Up @@ -243,7 +246,8 @@ static Sample composePagedSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setOverloadDisambiguation(
SampleComposerUtil.createOverloadDisambiguation(rpcMethodArgVarExprs))
Expand Down Expand Up @@ -293,7 +297,8 @@ static Sample composeLroSample(
}
RegionTag regionTag =
RegionTag.builder()
.setServiceName(clientVarExpr.variable().identifier().name())
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setRpcName(method.name())
.setOverloadDisambiguation(
SampleComposerUtil.createOverloadDisambiguation(rpcMethodArgVarExprs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package com.google.api.generator.gapic.composer.utils;

import com.google.api.generator.gapic.model.Service;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -25,6 +27,7 @@ public class ClassNames {
private static final String MOCK_SERVICE_CLASS_NAME_PATTERN = "Mock%s";
private static final String MOCK_SERVICE_IMPL_CLASS_NAME_PATTERN = "Mock%sImpl";
private static final String SERVICE_CLIENT_CLASS_NAME_PATTERN = "%sClient";
private static final String SERVICE_REGION_TAG_NAME_PATTERN = "%s";
private static final String SERVICE_CLIENT_TEST_CLASS_NAME_PATTERN = "%sClientTest";
private static final String SERVICE_CLIENT_TRANSPORT_TEST_CLASS_NAME_PATTERN = "%sClient%sTest";
private static final String SERVICE_SETTINGS_CLASS_NAME_PATTERN = "%sSettings";
Expand Down Expand Up @@ -120,4 +123,11 @@ private static String monolithBackwardsCompatibleName(String rawServiceName) {
? rawServiceName.replace("IAM", "Iam")
: rawServiceName;
}

// For region tags, the service name should not include `Client` in the name
public static String getPureServiceName(String serviceClassName) {
alicejli marked this conversation as resolved.
Show resolved Hide resolved
return String.format(
SERVICE_REGION_TAG_NAME_PATTERN,
Iterables.getFirst(Splitter.on("Client").split(serviceClassName), serviceClassName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public String generate() {
if (!apiVersion().isEmpty()) {
rt = rt + apiVersion() + "_";
}
rt = rt + "generated_" + serviceName() + "_" + rpcName();
rt = rt.toLowerCase() + "generated_" + serviceName() + "_" + rpcName();
// TODO: @alicejli overloadDisambiguation will need to be updated to match other languages
alicejli marked this conversation as resolved.
Show resolved Hide resolved
if (!overloadDisambiguation().isEmpty()) {
rt = rt + "_" + overloadDisambiguation();
}
Expand All @@ -148,7 +149,7 @@ public String generate() {
rt = rt + "_sync";
}

return rt.toLowerCase();
return rt;
}

public static CommentStatement generateTag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.bookshop.v1beta1.samples;

// [START goldensample_generated_bookshopclient_getbook_async]
// [START goldensample_generated_Bookshop_GetBook_async]
import com.google.api.core.ApiFuture;
import com.google.bookshop.v1beta1.Book;
import com.google.bookshop.v1beta1.BookshopClient;
Expand Down Expand Up @@ -48,4 +48,4 @@ public class AsyncGetBook {
}
}
}
// [END goldensample_generated_bookshopclient_getbook_async]
// [END goldensample_generated_Bookshop_GetBook_async]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.bookshop.v1beta1.samples;

// [START goldensample_generated_bookshopclient_create_setcredentialsprovider_sync]
// [START goldensample_generated_Bookshop_Create_SetCredentialsProvider_sync]
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.bookshop.v1beta1.BookshopClient;
import com.google.bookshop.v1beta1.BookshopSettings;
Expand All @@ -41,4 +41,4 @@ public class SyncCreateSetCredentialsProvider {
BookshopClient bookshopClient = BookshopClient.create(bookshopSettings);
}
}
// [END goldensample_generated_bookshopclient_create_setcredentialsprovider_sync]
// [END goldensample_generated_Bookshop_Create_SetCredentialsProvider_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.bookshop.v1beta1.samples;

// [START goldensample_generated_bookshopclient_create_setendpoint_sync]
// [START goldensample_generated_Bookshop_Create_SetEndpoint_sync]
import com.google.bookshop.v1beta1.BookshopClient;
import com.google.bookshop.v1beta1.BookshopSettings;
import com.google.bookshop.v1beta1.myEndpoint;
Expand All @@ -38,4 +38,4 @@ public class SyncCreateSetEndpoint {
BookshopClient bookshopClient = BookshopClient.create(bookshopSettings);
}
}
// [END goldensample_generated_bookshopclient_create_setendpoint_sync]
// [END goldensample_generated_Bookshop_Create_SetEndpoint_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.bookshop.v1beta1.samples;

// [START goldensample_generated_bookshopclient_getbook_sync]
// [START goldensample_generated_Bookshop_GetBook_sync]
import com.google.bookshop.v1beta1.Book;
import com.google.bookshop.v1beta1.BookshopClient;
import com.google.bookshop.v1beta1.GetBookRequest;
Expand Down Expand Up @@ -45,4 +45,4 @@ public class SyncGetBook {
}
}
}
// [END goldensample_generated_bookshopclient_getbook_sync]
// [END goldensample_generated_Bookshop_GetBook_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.bookshop.v1beta1.samples;

// [START goldensample_generated_bookshopclient_getbook_intlistbook_sync]
// [START goldensample_generated_Bookshop_GetBook_IntListbook_sync]
import com.google.bookshop.v1beta1.Book;
import com.google.bookshop.v1beta1.BookshopClient;
import java.util.ArrayList;
Expand All @@ -41,4 +41,4 @@ public class SyncGetBookIntListbook {
}
}
}
// [END goldensample_generated_bookshopclient_getbook_intlistbook_sync]
// [END goldensample_generated_Bookshop_GetBook_IntListbook_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.bookshop.v1beta1.samples;

// [START goldensample_generated_bookshopclient_getbook_stringlistbook_sync]
// [START goldensample_generated_Bookshop_GetBook_StringListbook_sync]
import com.google.bookshop.v1beta1.Book;
import com.google.bookshop.v1beta1.BookshopClient;
import java.util.ArrayList;
Expand All @@ -41,4 +41,4 @@ public class SyncGetBookStringListbook {
}
}
}
// [END goldensample_generated_bookshopclient_getbook_stringlistbook_sync]
// [END goldensample_generated_Bookshop_GetBook_StringListbook_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.testdata.v1.samples;

// [START goldensample_generated_deprecatedserviceclient_fastfibonacci_async]
// [START goldensample_generated_DeprecatedService_FastFibonacci_async]
import com.google.api.core.ApiFuture;
import com.google.protobuf.Empty;
import com.google.testdata.v1.DeprecatedServiceClient;
Expand All @@ -42,4 +42,4 @@ public class AsyncFastFibonacci {
}
}
}
// [END goldensample_generated_deprecatedserviceclient_fastfibonacci_async]
// [END goldensample_generated_DeprecatedService_FastFibonacci_async]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.testdata.v1.samples;

// [START goldensample_generated_deprecatedserviceclient_slowfibonacci_async]
// [START goldensample_generated_DeprecatedService_SlowFibonacci_async]
import com.google.api.core.ApiFuture;
import com.google.protobuf.Empty;
import com.google.testdata.v1.DeprecatedServiceClient;
Expand All @@ -42,4 +42,4 @@ public class AsyncSlowFibonacci {
}
}
}
// [END goldensample_generated_deprecatedserviceclient_slowfibonacci_async]
// [END goldensample_generated_DeprecatedService_SlowFibonacci_async]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.testdata.v1.samples;

// [START goldensample_generated_deprecatedserviceclient_create_setcredentialsprovider_sync]
// [START goldensample_generated_DeprecatedService_Create_SetCredentialsProvider_sync]
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.testdata.v1.DeprecatedServiceClient;
import com.google.testdata.v1.DeprecatedServiceSettings;
Expand All @@ -42,4 +42,4 @@ public class SyncCreateSetCredentialsProvider {
DeprecatedServiceClient.create(deprecatedServiceSettings);
}
}
// [END goldensample_generated_deprecatedserviceclient_create_setcredentialsprovider_sync]
// [END goldensample_generated_DeprecatedService_Create_SetCredentialsProvider_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.testdata.v1.samples;

// [START goldensample_generated_deprecatedserviceclient_create_setendpoint_sync]
// [START goldensample_generated_DeprecatedService_Create_SetEndpoint_sync]
import com.google.testdata.v1.DeprecatedServiceClient;
import com.google.testdata.v1.DeprecatedServiceSettings;
import com.google.testdata.v1.myEndpoint;
Expand All @@ -39,4 +39,4 @@ public class SyncCreateSetEndpoint {
DeprecatedServiceClient.create(deprecatedServiceSettings);
}
}
// [END goldensample_generated_deprecatedserviceclient_create_setendpoint_sync]
// [END goldensample_generated_DeprecatedService_Create_SetEndpoint_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.testdata.v1.samples;

// [START goldensample_generated_deprecatedserviceclient_fastfibonacci_sync]
// [START goldensample_generated_DeprecatedService_FastFibonacci_sync]
import com.google.protobuf.Empty;
import com.google.testdata.v1.DeprecatedServiceClient;
import com.google.testdata.v1.FibonacciRequest;
Expand All @@ -39,4 +39,4 @@ public class SyncFastFibonacci {
}
}
}
// [END goldensample_generated_deprecatedserviceclient_fastfibonacci_sync]
// [END goldensample_generated_DeprecatedService_FastFibonacci_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.testdata.v1.samples;

// [START goldensample_generated_deprecatedserviceclient_slowfibonacci_sync]
// [START goldensample_generated_DeprecatedService_SlowFibonacci_sync]
import com.google.protobuf.Empty;
import com.google.testdata.v1.DeprecatedServiceClient;
import com.google.testdata.v1.FibonacciRequest;
Expand All @@ -39,4 +39,4 @@ public class SyncSlowFibonacci {
}
}
}
// [END goldensample_generated_deprecatedserviceclient_slowfibonacci_sync]
// [END goldensample_generated_DeprecatedService_SlowFibonacci_sync]
Loading