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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: restore showcase autogen IT #2895

Merged
merged 28 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7cfc510
chore: adapt `generate-showcase.sh` to hermetic build scripts
diegomarquezp May 15, 2024
457e542
fix permission issues
diegomarquezp May 15, 2024
9a8b6c3
add jar with dependencies and wrapper
diegomarquezp May 15, 2024
57ffaf0
remove unnecessary comments in pom
diegomarquezp May 16, 2024
b146141
final fixes to showcase script
diegomarquezp May 16, 2024
495b049
reformate
diegomarquezp May 16, 2024
6ae8d97
update showcase module
diegomarquezp May 16, 2024
edde192
restore clean install
diegomarquezp May 16, 2024
7bef47a
restore workflow
diegomarquezp May 16, 2024
e337c6e
fix yaml syntax
diegomarquezp May 16, 2024
b444b7c
simplify showcase ci
diegomarquezp May 16, 2024
deb732e
chore(main): release 5.3.0 (#2888)
release-please[bot] May 15, 2024
be9f316
add default endpoint to autoconfig composer
diegomarquezp May 17, 2024
662d764
update goldens
diegomarquezp May 17, 2024
a7e675c
update showcase
diegomarquezp May 17, 2024
f61d2bb
Merge remote-tracking branch 'origin/main' into fix-showcase-autogen-it
diegomarquezp May 17, 2024
235478a
update comments
diegomarquezp May 17, 2024
b17b1d8
fix showcase tests
diegomarquezp May 17, 2024
2d0f4bc
ignore vim swap files
diegomarquezp May 17, 2024
c05b3a9
fix `popd` comment
diegomarquezp May 17, 2024
5b9fb60
fix comment
diegomarquezp May 17, 2024
d8e5a31
transfer utility functions
diegomarquezp May 21, 2024
23f7e16
ignore vim swap files
diegomarquezp May 21, 2024
7f13152
partial transfer of util functions
diegomarquezp May 21, 2024
2bd371c
add sparse_clone function
diegomarquezp Jun 20, 2024
407d35c
use variable as argument to remove output folder
diegomarquezp Jun 20, 2024
9bf447a
remove unnecessary inputs to get_gapic_opts
diegomarquezp Jun 20, 2024
b0b695f
remove include_samples
diegomarquezp Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions .github/workflows/showcaseTests.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
name: Generator - Showcase Tests

on:
# Disable auto-triggering until this issue is fixed
# https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/2214
# push:
# branches:
# - main
# pull_request:
# paths:
# - 'spring-cloud-generator/**'
push:
branches:
- main
pull_request:
paths:
- 'spring-cloud-generator/**'
workflow_dispatch:

jobs:
showcaseTests:

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Setup Java 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Install buildozer
run: |
go install github.com/bazelbuild/buildtools/buildozer@latest
export PATH=$PATH:$(go env GOPATH)/bin
buildozer --version
- name: Install spring-cloud-gcp
# Installs spring-cloud-gcp from root,
# including spring-cloud-generator module
Expand All @@ -44,8 +38,6 @@ jobs:
run: |
set -x
set -e
export PATH=$PATH:$(go env GOPATH)/bin
buildozer --version
bash scripts/generate-showcase.sh
- name: Unit tests for showcase-spring-starter
# Runs showcase-spring-starter unit tests
Expand Down
23 changes: 22 additions & 1 deletion spring-cloud-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,28 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.google.cloud.generator.spring.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in order to run the spring generator jar using dependencies such as protobuf classes. This was something bazel took care about with the previous setup.

</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
161 changes: 114 additions & 47 deletions spring-cloud-generator/scripts/generate-showcase.sh
Original file line number Diff line number Diff line change
@@ -1,111 +1,178 @@
#!/bin/bash
set -e
set -ex

# To VERIFY: ./scripts/generate-showcase.sh
# To UPDATE: /scripts/generate-showcase.sh -u
UPDATE=0
# To verify: ./scripts/generate-showcase.sh
# To update: /scripts/generate-showcase.sh -u
update="false"
while getopts u flag
do
case "${flag}" in
u) UPDATE=1;;
u) update="true";;
esac
done

# For reusing bazel setup modifications and post-processing steps
source ./scripts/generate-steps.sh

# If not set, assume working directory is spring-cloud-generator
if [[ -z "$SPRING_GENERATOR_DIR" ]]; then
SPRING_GENERATOR_DIR=`pwd`
if [[ -z "${SPRING_GENERATOR_DIR}" ]]; then
SPRING_GENERATOR_DIR=$(pwd)
fi
SPRING_ROOT_DIR=${SPRING_GENERATOR_DIR}/..
SHOWCASE_STARTER_OLD_DIR=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter
SHOWCASE_STARTER_NEW_DIR=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter-generated
spring_root_dir=${SPRING_GENERATOR_DIR}/..
showcase_starter_old_dir=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter
showcase_starter_new_dir=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter-generated

# Verifies newly generated showcase-spring-starter against goldens
#
# $1 - directory containing existing showcase-spring-starter (golden)
# $2 - directory containing newly generated showcase-spring-starter
function verify(){
OLD_DIR=$1
NEW_DIR=$2
SHOWCASE_STARTER_DIFF=$(diff -r ${NEW_DIR}/src/main ${OLD_DIR}/src/main)
SHOWCASE_STARTER_POM_DIFF=$(diff -r ${NEW_DIR}/pom.xml ${OLD_DIR}/pom.xml)
if [ "$SHOWCASE_STARTER_DIFF" != "" ] || [ "$SHOWCASE_STARTER_POM_DIFF" != "" ]
old_dir=$1
new_dir=$2
showcase_starter_diff=$(diff -r ${new_dir}/src/main ${old_dir}/src/main)
showcase_starter_pom_diff=$(diff -r ${new_dir}/pom.xml ${old_dir}/pom.xml)
if [ "${showcase_starter_diff}" != "" ] || [ "${showcase_starter_pom_diff}" != "" ]
then
echo "Differences detected in generated showcase starter module: "
echo "Diff from src/main: "
echo $SHOWCASE_STARTER_DIFF
echo "${showcase_starter_diff}"
echo "Diff from pom.xml: "
echo $SHOWCASE_STARTER_POM_DIFF
echo "${showcase_starter_pom_diff}"
exit 1;
else
echo "No differences found in showcase-spring-starter"
rm -r ${NEW_DIR}
rm -r "${new_dir}"
fi
}

# Setup, generation, and post-processing steps for showcase-spring-starter
#
# $1 - target directory for generated starter
function generate_showcase_spring_starter(){
SHOWCASE_STARTER_DIR=$1
showcase_starter_dir=$1

# Compute the parent project version.
cd ${SPRING_ROOT_DIR}
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
cd ${SPRING_GENERATOR_DIR}
GAPIC_GENERATOR_JAVA_VERSION=$(mvn help:evaluate -Dexpression=gapic-generator-java-bom.version -q -DforceStdout)
pushd "${spring_root_dir}"
export project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
cd "${SPRING_GENERATOR_DIR}"
gapic_generator_java_version=$(mvn help:evaluate -Dexpression=gapic-generator-java-bom.version -q -DforceStdout)

if [[ -z "$GAPIC_GENERATOR_JAVA_VERSION" ]]; then
if [[ -z "${gapic_generator_java_version}" ]]; then
echo "Missing sdk-platform-java commitish to checkout"
exit 1
fi

# Clone sdk-platform-java (with showcase library)
git clone https://github.com/googleapis/sdk-platform-java.git
cd sdk-platform-java && git checkout "v${GAPIC_GENERATOR_JAVA_VERSION}"
if [[ ! -d "./sdk-platform-java" ]]; then
git clone https://github.com/googleapis/sdk-platform-java.git
fi
pushd sdk-platform-java
git checkout "v${gapic_generator_java_version}"

# We will use the generation tools from library_generation
pushd library_generation/utils
source utilities.sh
popd #library_generation/utils
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many utility methods in utilities.sh are we relying on? If it's not too much, I would prefer just duplicate the logic, because this creates dependencies of our hermetic build scripts, and we may accidentally break SpringCodeGen scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm moving them to generate-showcase-utilities


# Install showcase client libraries locally
cd showcase && mvn clean install
GAPIC_SHOWCASE_CLIENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
pushd showcase
# For local development, we cleanup any traces of previous runs
rm -rdf output
mvn clean install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything below uses ${output_folder}, but this uses literal value output.

gapic_showcase_client_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)

pushd gapic-showcase
gapic_showcase_server_version=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)
popd #showcase/gapic-showcase

# Alternative: if showcase client library is available on Maven Central,
# Instead of downloading sdk-platform-java/showcase (for client library, and generation setup),
# Can instead download googleapis (for generation setup) and gapic-showcase (for protos)

# Modify sdk-platform-java/WORKSPACE
modify_workspace_file "../WORKSPACE" ".." "../../scripts/resources/googleapis_modification_string.txt"
# Modify sdk-platform-java/showcase/BUILD.bazel
buildozer 'new_load @spring_cloud_generator//:java_gapic_spring.bzl java_gapic_spring_library' BUILD.bazel:__pkg__
modify_build_file "BUILD.bazel"
output_folder=$(get_output_folder)
mkdir "${output_folder}"
pushd "${output_folder}"
protoc_version=$(get_protoc_version "${gapic_generator_java_version}")
os_architecture=$(detect_os_architecture)
download_protoc "${protoc_version}" "${os_architecture}"

# We now copy the spring-cloud-generator and gapic-generator-java jar into the output_folder the
# sdk-platform-java generation scripts work with.
spring_generator_jar_name="spring-cloud-generator-${project_version}-jar-with-dependencies.jar"
cp ~/.m2/repository/com/google/cloud/spring-cloud-generator/"${project_version}/${spring_generator_jar_name}" \
"${output_folder}"
chmod 555 ${output_folder}/*.jar

# We download gapic-showcase and prepare the protos in output_folder
sparse_clone https://github.com/googleapis/gapic-showcase.git "schema/google/showcase/v1beta1"
pushd gapic-showcase
git checkout "v${gapic_showcase_server_version}"
cp -r schema "${output_folder}"
popd #gapic-showcase

# We download googleapis and prepare the protos in output_folder
if [[ ! -d "./googleapis" ]]; then
sparse_clone https://github.com/googleapis/googleapis.git "google/iam/v1 google/cloud/location google/api google/longrunning google/rpc google/type"
fi
pushd googleapis
cp -r google "${output_folder}"
popd #gapic-showcase

burkedavison marked this conversation as resolved.
Show resolved Hide resolved
# Now we call protoc with a series of arguments we obtain from
# sdk-platform-java's utilities.sh and others that are hardcoded (and stable).
# Note that --java_gapic_spring_opt uses `get_gapic_opts` which will work
# since the BUILD rules take similar arguments

proto_path="schema/google/showcase/v1beta1"
proto_files=$(find "${proto_path}" -type f -name "*.proto" | LC_COLLATE=C sort)
gapic_additional_protos="google/iam/v1/iam_policy.proto google/cloud/location/locations.proto"
rest_numeric_enums="false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need these additional protos, same thing for rest_numeric_enums, transport, gapic_yaml, include_samples etc. Can you try to remove them and see if the checks are still passing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakeli0 when removing the additional protos, the generated code has missing iam methods. For example:

diff -r /usr/local/google/home/diegomarquezp/Desktop/spring-cloud-gcp/spring-cloud-generator/scripts/../showcase/showcase-spring-starter-generated/src/main/java/com/google/showcase/v1beta1/spring/SequenceServiceSpringAutoConfiguration.java /usr/local/google/home/diegomarquezp/Desktop/spring-cloud-gcp/spring-cloud-generator/scripts/../showcase/showcase-spring-starter/src/main/java/com/google/showcase/v1beta1/spring/SequenceServiceSpringAutoConfiguration.java
98a99,101
>     if (this.clientProperties.getUseRest()) {
>       return SequenceServiceSettings.defaultHttpJsonTransportProviderBuilder().build();
>     }
123c126,134
<     SequenceServiceSettings.Builder clientSettingsBuilder = SequenceServiceSettings.newBuilder();
---
>     SequenceServiceSettings.Builder clientSettingsBuilder;
>     if (this.clientProperties.getUseRest()) {
>       clientSettingsBuilder = SequenceServiceSettings.newHttpJsonBuilder();
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace("Using REST (HTTP/JSON) transport.");
>       }
>     } else {
>       clientSettingsBuilder = SequenceServiceSettings.newBuilder();
>     }
186a198,224
>       RetrySettings listLocationsRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.listLocationsSettings().getRetrySettings(), serviceRetry);
>       clientSettingsBuilder.listLocationsSettings().setRetrySettings(listLocationsRetrySettings);
> 
>       RetrySettings getLocationRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.getLocationSettings().getRetrySettings(), serviceRetry);
>       clientSettingsBuilder.getLocationSettings().setRetrySettings(getLocationRetrySettings);
> 
>       RetrySettings setIamPolicyRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.setIamPolicySettings().getRetrySettings(), serviceRetry);
>       clientSettingsBuilder.setIamPolicySettings().setRetrySettings(setIamPolicyRetrySettings);
> 
>       RetrySettings getIamPolicyRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.getIamPolicySettings().getRetrySettings(), serviceRetry);
>       clientSettingsBuilder.getIamPolicySettings().setRetrySettings(getIamPolicyRetrySettings);
> 
>       RetrySettings testIamPermissionsRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.testIamPermissionsSettings().getRetrySettings(), serviceRetry);
>       clientSettingsBuilder
>           .testIamPermissionsSettings()
>           .setRetrySettings(testIamPermissionsRetrySettings);
> 
254a293,346
>       }
>     }
>     Retry listLocationsRetry = clientProperties.getListLocationsRetry();
>     if (listLocationsRetry != null) {
>       RetrySettings listLocationsRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.listLocationsSettings().getRetrySettings(), listLocationsRetry);
>       clientSettingsBuilder.listLocationsSettings().setRetrySettings(listLocationsRetrySettings);
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace("Configured method-level retry settings for listLocations from properties.");
>       }
>     }
>     Retry getLocationRetry = clientProperties.getGetLocationRetry();
>     if (getLocationRetry != null) {
>       RetrySettings getLocationRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.getLocationSettings().getRetrySettings(), getLocationRetry);
>       clientSettingsBuilder.getLocationSettings().setRetrySettings(getLocationRetrySettings);
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace("Configured method-level retry settings for getLocation from properties.");
>       }
>     }
>     Retry setIamPolicyRetry = clientProperties.getSetIamPolicyRetry();
>     if (setIamPolicyRetry != null) {
>       RetrySettings setIamPolicyRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.setIamPolicySettings().getRetrySettings(), setIamPolicyRetry);
>       clientSettingsBuilder.setIamPolicySettings().setRetrySettings(setIamPolicyRetrySettings);
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace("Configured method-level retry settings for setIamPolicy from properties.");
>       }
>     }
>     Retry getIamPolicyRetry = clientProperties.getGetIamPolicyRetry();
>     if (getIamPolicyRetry != null) {
>       RetrySettings getIamPolicyRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.getIamPolicySettings().getRetrySettings(), getIamPolicyRetry);
>       clientSettingsBuilder.getIamPolicySettings().setRetrySettings(getIamPolicyRetrySettings);
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace("Configured method-level retry settings for getIamPolicy from properties.");
>       }
>     }
>     Retry testIamPermissionsRetry = clientProperties.getTestIamPermissionsRetry();
>     if (testIamPermissionsRetry != null) {
>       RetrySettings testIamPermissionsRetrySettings =
>           RetryUtil.updateRetrySettings(
>               clientSettingsBuilder.testIamPermissionsSettings().getRetrySettings(),
>               testIamPermissionsRetry);
>       clientSettingsBuilder
>           .testIamPermissionsSettings()
>           .setRetrySettings(testIamPermissionsRetrySettings);
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace(
>             "Configured method-level retry settings for testIamPermissions from properties.");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing rest_numeric_enums causes issues too:

diff -r /usr/local/google/home/diegomarquezp/Desktop/spring-cloud-gcp/spring-cloud-generator/scripts/../showcase/showcase-spring-starter-generated/src/main/java/com/google/showcase/v1beta1/spring/TestingSpringAutoConfiguration.java /usr/local/google/home/diegomarquezp/Desktop/spring-cloud-gcp/spring-cloud-generator/scripts/../showcase/showcase-spring-starter/src/main/java/com/google/showcase/v1beta1/spring/TestingSpringAutoConfiguration.java
96a97,99
>     if (this.clientProperties.getUseRest()) {
>       return TestingSettings.defaultHttpJsonTransportProviderBuilder().build();
>     }   
118c121,129
<     TestingSettings.Builder clientSettingsBuilder = TestingSettings.newBuilder();
---
>     TestingSettings.Builder clientSettingsBuilder;
>     if (this.clientProperties.getUseRest()) {
>       clientSettingsBuilder = TestingSettings.newHttpJsonBuilder();
>       if (LOGGER.isTraceEnabled()) {
>         LOGGER.trace("Using REST (HTTP/JSON) transport.");
>       }
>     } else {
>       clientSettingsBuilder = TestingSettings.newBuilder();
>     }   

I'll keep checking on the other params

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include_samples and gapic_yaml were unnecessary. The other ones produce changes if removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG, we can keep the ones produce changes.

transport="grpc+rest"
gapic_yaml=""
service_config="schema/google/showcase/v1beta1/showcase_grpc_service_config.json"
service_yaml="schema/google/showcase/v1beta1/showcase_v1beta1.yaml"
include_samples="false"
output_srcjar_zip_name="showcase_java_gapic_spring_raw.srcjar.zip"

"${protoc_path}"/protoc \
"--experimental_allow_proto3_optional" \
"--plugin=protoc-gen-java_gapic_spring=${SPRING_GENERATOR_DIR}/spring-cloud-generator-wrapper" \
"--java_gapic_spring_out=${output_folder}/${output_srcjar_zip_name}" \
"--java_gapic_spring_opt=$(get_gapic_opts "${transport}" "${rest_numeric_enums}" "${gapic_yaml}" "${service_config}" "${service_yaml}")" \
${proto_files} ${gapic_additional_protos} # Do not quote because this variable should not be treated as one long string.



# Invoke bazel target for generating showcase-spring-starter
bazelisk build --tool_java_language_version=17 --tool_java_runtime_version=remotejdk_17 //showcase:showcase_java_gapic_spring

# Post-process generated modules
copy_and_unzip "../bazel-bin/showcase/showcase_java_gapic_spring-spring.srcjar" "showcase_java_gapic_spring-spring.srcjar" "${SPRING_GENERATOR_DIR}/showcase" ${SHOWCASE_STARTER_DIR}
modify_starter_pom ${SHOWCASE_STARTER_DIR}/pom.xml "com.google.cloud" "gapic-showcase" $PROJECT_VERSION
unzip "${output_srcjar_zip_name}"
copy_and_unzip "${output_folder}/temp-codegen-spring.srcjar" "temp-codegen-spring.srcjar" "${SPRING_GENERATOR_DIR}/showcase" ${showcase_starter_dir}
modify_starter_pom "${showcase_starter_dir}/pom.xml" "com.google.cloud" "gapic-showcase" "${project_version}"

popd #output_folder

# Additional pom.xml modifications for showcase starter
# Add explicit gapic-showcase version
sed -i'' '/^ *<artifactId>gapic-showcase<\/artifactId>*/a \ \ \ \ \ \ <version>'"$GAPIC_SHOWCASE_CLIENT_VERSION"'</version>' ${SHOWCASE_STARTER_DIR}/pom.xml
sed -i'' '/^ *<artifactId>gapic-showcase<\/artifactId>*/a \ \ \ \ \ \ <version>'"${gapic_showcase_client_version}"'</version>' "${showcase_starter_dir}/pom.xml"
# Update relative path to parent pom (different repo structure from starters)
RELATIVE_PATH="\ \ \ \ <relativePath>..\/..\/..\/spring-cloud-gcp-starters\/pom.xml<\/relativePath>"
sed -i'' 's/^ *<relativePath>.*/'"$RELATIVE_PATH"'/g' ${SHOWCASE_STARTER_DIR}/pom.xml
relative_path="\ \ \ \ <relativePath>..\/..\/..\/spring-cloud-gcp-starters\/pom.xml<\/relativePath>"
sed -i'' 's/^ *<relativePath>.*/'"${relative_path}"'/g' ${showcase_starter_dir}/pom.xml

# Run google-java-format on generated code
run_formatter ${SHOWCASE_STARTER_DIR}
run_formatter "${showcase_starter_dir}"

# Remove downloaded repos
rm -rf ${SPRING_GENERATOR_DIR}/sdk-platform-java
popd #showcase
popd #sdk-platform-java
rm -rdf ${SPRING_GENERATOR_DIR}/sdk-platform-java
rm -rdf gapic-showcase
popd #spring_root_dir
}

if [[ UPDATE -ne 0 ]]; then
if [[ "${update}" == "true" ]]; then
echo "Running script to perform showcase-spring-starter update"
generate_showcase_spring_starter ${SHOWCASE_STARTER_OLD_DIR}
generate_showcase_spring_starter ${showcase_starter_old_dir}
else
echo "Running script to perform showcase-spring-starter verification"
generate_showcase_spring_starter ${SHOWCASE_STARTER_NEW_DIR}
verify ${SHOWCASE_STARTER_OLD_DIR} ${SHOWCASE_STARTER_NEW_DIR}
generate_showcase_spring_starter ${showcase_starter_new_dir}
verify ${showcase_starter_old_dir} ${showcase_starter_new_dir}
fi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* 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.
Expand Down Expand Up @@ -134,6 +134,7 @@ public ComplianceSettings complianceSettings(
clientSettingsBuilder
.setCredentialsProvider(this.credentialsProvider)
.setTransportChannelProvider(defaultTransportChannelProvider)
.setEndpoint(ComplianceSettings.getDefaultEndpoint())
.setHeaderProvider(this.userAgentHeaderProvider());
if (this.clientProperties.getQuotaProjectId() != null) {
clientSettingsBuilder.setQuotaProjectId(this.clientProperties.getQuotaProjectId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* 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.
Expand Down Expand Up @@ -130,6 +130,7 @@ public EchoSettings echoSettings(
clientSettingsBuilder
.setCredentialsProvider(this.credentialsProvider)
.setTransportChannelProvider(defaultTransportChannelProvider)
.setEndpoint(EchoSettings.getDefaultEndpoint())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is what we want when creating client settings. We can follow up with proper changes in gax.
cc: @lqiu96

Copy link
Contributor

@lqiu96 lqiu96 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the error message if you don't add this line to set the endpoint? Ideally, we shouldn't have to set the endpoint ourselves but for this PR, I think it's fine we can't resolve the issue here.

Or if this isn't becuase of an error, is this because we're using an old version of the generator. Or perhaps this is just something spring generator does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the error message if you don't add this line to set the endpoint?

The error message:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'echoClient' defined in com.google.showcase.v1beta1.spring.EchoSpringAutoConfiguration: Failed to instantiate [com.google.showcase.v1beta1.EchoClient]: Factory method 'echoClient' threw exception with message: Invalid host or port: .googleapis.com 443
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1335)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1165)

It fails to resolve the endpoint if we don't explicitly set it: Invalid host or port: .googleapis.com 443

Or if this isn't because of an error, is this because we're using an old version of the generator. Or perhaps this is just something spring generator does?

I don't think this is very different from a normal use case of instantiating a client with a few settings.

Here we create the settings:

@Bean
@ConditionalOnMissingBean
public EchoSettings echoSettings(
@Qualifier("defaultEchoTransportChannelProvider")
TransportChannelProvider defaultTransportChannelProvider)
throws IOException {
EchoSettings.Builder clientSettingsBuilder;

Here we create the client with these settings:

@Bean
@ConditionalOnMissingBean
public EchoClient echoClient(EchoSettings echoSettings) throws IOException {
return EchoClient.create(echoSettings);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails to resolve the endpoint if we don't explicitly set it: Invalid host or port: .googleapis.com 443

Ah, I think this is an edge case due to the the showcase protos. The showcase protos have a default_host value that won't match a "normal" google endpoint. For example, the echo proto's service_host value: https://github.com/googleapis/gapic-showcase/blob/4e7c30a5d5df8aac30e8b8f1e6f71809fa9d20f6/schema/google/showcase/v1beta1/echo.proto#L45
where as a normal endpoint would be something like cloudassets.googleapis.com.

The error above is complaining that we can't populate the serviceName part of the endpoint and that's because the showcase protos don't have one. That's why you'd have to explicitly call setEndpoint() yourself.

This looks like it's changing the code inside the generator, which I believe would impact all of spring code gen. The endpoint normally should be constructed internally for non-showcase services and I believe having the generator explicitly call setEndpoint() may be imcompatible with enabling certain features.

In the showcase ITs, we have this same problem. But we solve it by explicitly calling setEndpoint() in the handwritten layers: https://github.com/googleapis/sdk-platform-java/blob/5799827a864be627bac03969cc178efc9d6170aa/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java#L67

I'm not too familiar with the showcase autogen ITs. Are there any handwritten parts that we can do something similar or are these the only tests that are generated + run?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any handwritten parts that we can do something similar or are these the only tests that are generated + run?

This is the handwritten test.Compare to GAPIC showcase tests, this test though does not create a client, instead, it fetches the client from existing Spring beans. So it's hard to override the endpoint in the tests since the whole point of SpringCodeGen is to create a client for customers.

I think this change might be unavoidable for now, and should not impact any existing features, because SpringCodeGen does not expose a property for customers to set endpoint or universe domain either. We can revisit this decision once we get to implement universe domain in spring-cloud-gcp. WDYT @lqiu96 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'm not too familiar with spring so I don't know of a way to do this, but we are going to have to remove the explicit setting for the default endpoint at some point (i.e. whenever we enable universe domain). This will require a workaround for the showcase clients in the future or more configurations generated by the generator.

I think for now we can proceed with explicitly setting the default endpoint.

.setHeaderProvider(this.userAgentHeaderProvider());
if (this.clientProperties.getQuotaProjectId() != null) {
clientSettingsBuilder.setQuotaProjectId(this.clientProperties.getQuotaProjectId());
Expand Down Expand Up @@ -159,6 +160,13 @@ public EchoSettings echoSettings(
clientSettingsBuilder.echoSettings().getRetrySettings(), serviceRetry);
clientSettingsBuilder.echoSettings().setRetrySettings(echoRetrySettings);

RetrySettings echoErrorDetailsRetrySettings =
RetryUtil.updateRetrySettings(
clientSettingsBuilder.echoErrorDetailsSettings().getRetrySettings(), serviceRetry);
clientSettingsBuilder
.echoErrorDetailsSettings()
.setRetrySettings(echoErrorDetailsRetrySettings);

RetrySettings pagedExpandRetrySettings =
RetryUtil.updateRetrySettings(
clientSettingsBuilder.pagedExpandSettings().getRetrySettings(), serviceRetry);
Expand Down Expand Up @@ -225,6 +233,20 @@ public EchoSettings echoSettings(
LOGGER.trace("Configured method-level retry settings for echo from properties.");
}
}
Retry echoErrorDetailsRetry = clientProperties.getEchoErrorDetailsRetry();
if (echoErrorDetailsRetry != null) {
RetrySettings echoErrorDetailsRetrySettings =
RetryUtil.updateRetrySettings(
clientSettingsBuilder.echoErrorDetailsSettings().getRetrySettings(),
echoErrorDetailsRetry);
clientSettingsBuilder
.echoErrorDetailsSettings()
.setRetrySettings(echoErrorDetailsRetrySettings);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(
"Configured method-level retry settings for echoErrorDetails from properties.");
}
}
Retry pagedExpandRetry = clientProperties.getPagedExpandRetry();
if (pagedExpandRetry != null) {
RetrySettings pagedExpandRetrySettings =
Expand Down
Loading
Loading