Skip to content

Commit ee45f5d

Browse files
authored
Merge branch 'main' into bigtable-v2-samples
2 parents 96d45f9 + e1e4059 commit ee45f5d

11 files changed

Lines changed: 247 additions & 41 deletions

File tree

.github/workflows/librarian_generation_check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
name: Librarian generate diff check on pull requests
14+
name: Librarian - Generate diff check on pull requests
1515
on:
1616
pull_request:
1717

.github/workflows/showcase-version-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: Showcase Version Check
15+
name: Librarian - Showcase Version Check
1616

1717
on:
1818
schedule:

.github/workflows/update_librarian_googleapis.yaml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: Update librarian googleapis commitish
15+
name: Librarian - Update googleapis commitish and generate all
1616
on:
1717
schedule:
1818
- cron: '0 3 * * *' # Run once a day at 3:00 AM UTC
@@ -85,6 +85,7 @@ jobs:
8585
echo "has_changes=true" >> $GITHUB_OUTPUT
8686
fi
8787
- name: Install protoc
88+
if: steps.detect_librarian.outputs.has_changes == 'true'
8889
run: |
8990
set -e
9091
VERSION="33.2"
@@ -93,42 +94,37 @@ jobs:
9394
sudo unzip -o /tmp/protoc.zip
9495
protoc --version
9596
- uses: actions/setup-java@v4
97+
if: steps.detect_librarian.outputs.has_changes == 'true'
9698
with:
9799
java-version: "17"
98100
distribution: "temurin"
99101
cache: "maven"
100102
- name: Verify Java and Maven installation
103+
if: steps.detect_librarian.outputs.has_changes == 'true'
101104
run: |
102105
java -version
103106
if ! command -v mvn &> /dev/null; then
104107
sudo apt-get update && sudo apt-get install -y maven
105108
fi
106109
mvn -version
107110
- uses: actions/setup-python@v5
111+
if: steps.detect_librarian.outputs.has_changes == 'true'
108112
with:
109113
python-version: "3.12"
110114
cache: 'pip'
111115
- name: Run librarian install
116+
if: steps.detect_librarian.outputs.has_changes == 'true'
112117
run: |
113118
go run github.com/googleapis/librarian/cmd/librarian@latest install
114119
echo "$HOME/java_tools/bin" >> $GITHUB_PATH
115120
env:
116121
PYTHONPATH: ${{ github.workspace }}/sdk-platform-java/hermetic_build/library_generation/owlbot
117122
- name: Generate Libraries
118123
if: steps.detect_librarian.outputs.has_changes == 'true'
119-
id: generate
120124
run: |
121125
go run github.com/googleapis/librarian/cmd/librarian@latest generate --all
122-
git add .
123-
changed_files=$(git diff --cached --name-only)
124-
if [[ "${changed_files}" == "" ]]; then
125-
echo "has_changes=false" >> $GITHUB_OUTPUT
126-
echo "No changes in libraries"
127-
else
128-
echo "has_changes=true" >> $GITHUB_OUTPUT
129-
fi
130126
- name: Commit and Create PR
131-
if: steps.detect_librarian.outputs.has_changes == 'true' || steps.generate.outputs.has_changes == 'true'
127+
if: steps.detect_librarian.outputs.has_changes == 'true'
132128
env:
133129
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}
134130
PR_TITLE: "chore: update googleapis commitish to ${{ steps.commit.outputs.short_commit }}"
@@ -139,7 +135,7 @@ jobs:
139135
if [ "${{ github.event_name }}" = "pull_request" ]; then
140136
echo "=== PR Test: DRY RUN MODE ACTIVE ==="
141137
echo "Would have checked out branch: update-librarian-googleapis-main"
142-
echo "Would have committed with title: $PR_TITLE"
138+
echo "Would have committed configs with title: $PR_TITLE"
143139
echo "Would have pushed branch and created PR."
144140
exit 0
145141
fi
@@ -153,8 +149,22 @@ jobs:
153149
# Create and switch to the branch (force checkout -B to discard any local state on this branch name if it existed)
154150
git checkout -B "${current_branch}"
155151
156-
# Commit the changes (they are already staged by the Detect Changes step!)
157-
git commit -m "${PR_TITLE}"
152+
# 1. Commit Config Changes
153+
# Ensure they are staged
154+
git add librarian.yaml generation_config.yaml
155+
if ! git diff --cached --quiet; then
156+
git commit -m "${PR_TITLE}"
157+
else
158+
echo "No config changes to commit"
159+
fi
160+
161+
# 2. Commit Generated Code
162+
git add .
163+
if ! git diff --cached --quiet; then
164+
git commit -m "chore: generate libraries"
165+
else
166+
echo "No generated code changes to commit"
167+
fi
158168
159169
# Push to remote (force push to overwrite any stale branch on remote)
160170
git remote add remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${{ github.repository }}.git" || git remote set-url remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${{ github.repository }}.git"

generation_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ libraries:
14421442
GAPICs:
14431443
- proto_path: google/iam/admin/v1
14441444
- api_shortname: iam-policy
1445-
name_pretty: IAM
1445+
name_pretty: Cloud IAM Policy
14461446
product_documentation: n/a
14471447
api_description: n/a
14481448
release_level: stable

java-datastore/datastore-v1-proto-client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@
107107
</exclusion>
108108
</exclusions>
109109
</dependency>
110+
<dependency>
111+
<groupId>com.google.api</groupId>
112+
<artifactId>gax</artifactId>
113+
<scope>test</scope>
114+
</dependency>
110115
</dependencies>
111116

112117
<build>

java-datastore/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/it/ITDatastoreProtoClientTest.java

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
import static com.google.datastore.v1.client.DatastoreHelper.makeFilter;
1919
import static com.google.datastore.v1.client.DatastoreHelper.makeValue;
2020

21+
import com.google.api.core.ApiClock;
22+
import com.google.api.core.ApiFuture;
23+
import com.google.api.core.NanoClock;
24+
import com.google.api.gax.retrying.BasicResultRetryAlgorithm;
25+
import com.google.api.gax.retrying.DirectRetryingExecutor;
26+
import com.google.api.gax.retrying.ExponentialRetryAlgorithm;
27+
import com.google.api.gax.retrying.ResultRetryAlgorithmWithContext;
28+
import com.google.api.gax.retrying.RetryAlgorithm;
29+
import com.google.api.gax.retrying.RetrySettings;
30+
import com.google.api.gax.retrying.RetryingFuture;
2131
import com.google.common.truth.Truth;
2232
import com.google.datastore.v1.Filter;
2333
import com.google.datastore.v1.KindExpression;
@@ -27,9 +37,13 @@
2737
import com.google.datastore.v1.client.Datastore;
2838
import com.google.datastore.v1.client.DatastoreException;
2939
import com.google.datastore.v1.client.DatastoreHelper;
40+
import com.google.rpc.Code;
3041
import java.io.IOException;
3142
import java.security.GeneralSecurityException;
43+
import java.time.Duration;
3244
import java.util.List;
45+
import java.util.concurrent.Callable;
46+
import java.util.concurrent.ExecutionException;
3347
import org.junit.Before;
3448
import org.junit.Test;
3549

@@ -48,7 +62,7 @@ public void setUp() throws GeneralSecurityException, IOException {
4862
}
4963

5064
@Test
51-
public void testQuerySplitterWithDefaultDb() throws DatastoreException {
65+
public void testQuerySplitterWithDefaultDb() throws Exception {
5266
Filter propertyFilter =
5367
makeFilter("foo", PropertyFilter.Operator.EQUAL, makeValue("value")).build();
5468
Query query =
@@ -59,8 +73,7 @@ public void testQuerySplitterWithDefaultDb() throws DatastoreException {
5973

6074
PARTITION = PartitionId.newBuilder().setProjectId(PROJECT_ID).build();
6175

62-
List<Query> splits =
63-
DatastoreHelper.getQuerySplitter().getSplits(query, PARTITION, 2, DATASTORE);
76+
List<Query> splits = getSplitsWithRetry(query, PARTITION, 2, DATASTORE);
6477
Truth.assertThat(splits).isNotEmpty();
6578
splits.forEach(
6679
split -> {
@@ -70,7 +83,7 @@ public void testQuerySplitterWithDefaultDb() throws DatastoreException {
7083
}
7184

7285
@Test
73-
public void testQuerySplitterWithDb() throws DatastoreException {
86+
public void testQuerySplitterWithDb() throws Exception {
7487
Filter propertyFilter =
7588
makeFilter("foo", PropertyFilter.Operator.EQUAL, makeValue("value")).build();
7689
Query query =
@@ -81,8 +94,7 @@ public void testQuerySplitterWithDb() throws DatastoreException {
8194

8295
PARTITION = PartitionId.newBuilder().setProjectId(PROJECT_ID).setDatabaseId("test-db").build();
8396

84-
List<Query> splits =
85-
DatastoreHelper.getQuerySplitter().getSplits(query, PARTITION, 2, DATASTORE);
97+
List<Query> splits = getSplitsWithRetry(query, PARTITION, 2, DATASTORE);
8698

8799
Truth.assertThat(splits).isNotEmpty();
88100
splits.forEach(
@@ -91,4 +103,85 @@ public void testQuerySplitterWithDb() throws DatastoreException {
91103
Truth.assertThat(split.getFilter()).isEqualTo(propertyFilter);
92104
});
93105
}
106+
107+
/**
108+
* A generic helper method that executes a {@link Callable} with retries using the GAX retrying
109+
* framework.
110+
*
111+
* <p>It configures a {@link DirectRetryingExecutor} with the provided {@link RetrySettings} and
112+
* the custom {@link ResultRetryAlgorithmWithContext}.
113+
*
114+
* @param callable the action to execute
115+
* @param retrySettings the retry configuration (backoff, max attempts, timeouts)
116+
* @param resultRetryAlgorithm the algorithm to determine if a failed attempt should be retried
117+
* @return the result of the callable execution
118+
* @throws Exception if the execution fails after all retry attempts.
119+
*/
120+
private static <V> V runWithRetry(
121+
Callable<V> callable,
122+
RetrySettings retrySettings,
123+
ResultRetryAlgorithmWithContext<V> resultRetryAlgorithm)
124+
throws Exception {
125+
ApiClock clock = NanoClock.getDefaultClock();
126+
// We must wrap the result algorithm and timed algorithm into a RetryAlgorithm
127+
// as required by DirectRetryingExecutor.
128+
RetryAlgorithm<V> retryAlgorithm =
129+
new RetryAlgorithm<>(
130+
resultRetryAlgorithm, new ExponentialRetryAlgorithm(retrySettings, clock));
131+
132+
DirectRetryingExecutor<V> executor = new DirectRetryingExecutor<>(retryAlgorithm);
133+
RetryingFuture<V> future = executor.createFuture(callable);
134+
135+
ApiFuture<V> submittedFuture = executor.submit(future);
136+
137+
try {
138+
return submittedFuture.get();
139+
} catch (ExecutionException e) {
140+
Throwable cause = e.getCause();
141+
// submittedFuture.get() wraps any exception thrown during execution in an ExecutionException.
142+
// We unwrap and rethrow the actual cause (Exception or Error) directly so that test failures
143+
// report the root cause (e.g., DatastoreException or AssertionError) instead of the wrapper.
144+
if (cause instanceof Exception) {
145+
throw (Exception) cause;
146+
}
147+
if (cause instanceof Error) {
148+
throw (Error) cause;
149+
}
150+
throw e;
151+
} catch (InterruptedException e) {
152+
// Restore the interrupted status before rethrowing, as per Java concurrency best practices.
153+
Thread.currentThread().interrupt();
154+
throw e;
155+
}
156+
}
157+
158+
// This low-level Datastore client (proto-over-HTTP) does not have built-in retry logic
159+
// (unlike the high-level google-cloud-datastore gRPC client). We must explicitly retry
160+
// here to handle transient backend errors (such as Code.INTERNAL auth issues).
161+
// We reuse GAX retrying utilities here in the test to implement this backoff/retry.
162+
private static List<Query> getSplitsWithRetry(
163+
Query query, PartitionId partition, int numSplits, Datastore datastore) throws Exception {
164+
// Fail fast configuration to avoid long wait times during test failures
165+
RetrySettings retrySettings =
166+
RetrySettings.newBuilder()
167+
.setMaxAttempts(3)
168+
.setInitialRetryDelayDuration(Duration.ofMillis(200))
169+
.setRetryDelayMultiplier(1.5)
170+
.setMaxRetryDelayDuration(Duration.ofMillis(500))
171+
.setTotalTimeoutDuration(Duration.ofSeconds(2))
172+
.build();
173+
return runWithRetry(
174+
() -> DatastoreHelper.getQuerySplitter().getSplits(query, partition, numSplits, datastore),
175+
retrySettings,
176+
new BasicResultRetryAlgorithm<List<Query>>() {
177+
@Override
178+
public boolean shouldRetry(Throwable prevThrowable, List<Query> prevResult) {
179+
if (prevThrowable instanceof DatastoreException) {
180+
DatastoreException de = (DatastoreException) prevThrowable;
181+
return de.getCode() == Code.INTERNAL;
182+
}
183+
return false;
184+
}
185+
});
186+
}
94187
}

java-datastore/google-cloud-datastore-utils/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
</exclusion>
8585
</exclusions>
8686
</dependency>
87+
<dependency>
88+
<groupId>com.google.api</groupId>
89+
<artifactId>gax</artifactId>
90+
<scope>test</scope>
91+
</dependency>
8792
</dependencies>
8893

8994
<build>

0 commit comments

Comments
 (0)