-
Notifications
You must be signed in to change notification settings - Fork 330
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
test: restore showcase autogen IT #2895
Changes from 16 commits
7cfc510
457e542
9a8b6c3
57ffaf0
b146141
495b049
6ae8d97
edde192
7bef47a
e337c6e
b444b7c
deb732e
be9f316
662d764
a7e675c
f61d2bb
235478a
b17b1d8
2d0f4bc
c05b3a9
5b9fb60
d8e5a31
23f7e16
7f13152
2bd371c
407d35c
9bf447a
b0b695f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How many utility methods in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm moving them to |
||
|
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything below uses |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need these additional protos, same thing for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blakeli0 when removing the additional protos, the generated code has missing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing
I'll keep checking on the other params There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||||||||||||||||||||
|
@@ -130,6 +130,7 @@ public EchoSettings echoSettings( | |||||||||||||||||||||||||
clientSettingsBuilder | ||||||||||||||||||||||||||
.setCredentialsProvider(this.credentialsProvider) | ||||||||||||||||||||||||||
.setTransportChannelProvider(defaultTransportChannelProvider) | ||||||||||||||||||||||||||
.setEndpoint(EchoSettings.getDefaultEndpoint()) | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The error message:
It fails to resolve the endpoint if we don't explicitly set it:
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: Lines 115 to 121 in 0f94e07
Here we create the client with these settings: Lines 339 to 343 in 0f94e07
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I think this is an edge case due to the the showcase protos. The showcase protos have a The error above is complaining that we can't populate the 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 In the showcase ITs, we have this same problem. But we solve it by explicitly calling 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||||||||||||||||||||||||
|
@@ -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); | ||||||||||||||||||||||||||
|
@@ -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 = | ||||||||||||||||||||||||||
|
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.
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.