[git-bridge] Make liveness detect a dead service

GitOrigin-RevId: 266f6db044eec8b362b07bdfed45f892dd272413
This commit is contained in:
Domagoj Kriskovic
2026-09-17 11:36:59 +00:00
committed by Copybot
parent e0a2af4bf6
commit 655034fb8e
3 changed files with 55 additions and 4 deletions
@@ -3,6 +3,9 @@ package uk.ac.ic.wlgitbridge.bridge;
import com.google.api.client.auth.oauth2.Credential;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
@@ -244,9 +247,28 @@ public class Bridge {
public boolean healthCheck() {
try {
dbStore.getNumProjects();
File rootDirectory = new File("/");
if (!rootDirectory.exists()) {
throw new Exception("bad filesystem state, root directory does not exist");
// Check the repo store volume (the PVC mounted at the repo store root), not the
// container root filesystem. A read-only or detached volume must fail the check.
File rootDirectory = repoStore.getRootDirectory();
if (rootDirectory == null || !rootDirectory.isDirectory()) {
throw new Exception("repo store root directory does not exist: " + rootDirectory);
}
// Write and read back a small probe file to confirm the volume is mounted read-write.
// Use the .wlgb directory (excluded from project purging) so we never touch project
// storage. A single fixed-name file is overwritten on each probe (never deleted), so we
// avoid churning through unique files and can't leave orphaned temp files behind. Both
// liveness and readiness probes write identical content, so this is safe under concurrent
// probes.
File wlgbDirectory = new File(rootDirectory, ".wlgb");
if (!wlgbDirectory.isDirectory()) {
throw new Exception("repo store .wlgb directory does not exist: " + wlgbDirectory);
}
Path probeFile = new File(wlgbDirectory, ".health_check").toPath();
byte[] payload = "ok".getBytes(StandardCharsets.UTF_8);
Files.write(probeFile, payload);
byte[] readBack = Files.readAllBytes(probeFile);
if (!Arrays.equals(payload, readBack)) {
throw new Exception("repo store health check file content mismatch: " + probeFile);
}
Log.debug("[HealthCheck] passed");
return true;
@@ -1,12 +1,17 @@
package uk.ac.ic.wlgitbridge.bridge;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Optional;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import uk.ac.ic.wlgitbridge.application.config.Config;
import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
import uk.ac.ic.wlgitbridge.bridge.db.ProjectState;
@@ -27,6 +32,8 @@ import uk.ac.ic.wlgitbridge.snapshot.getdoc.GetDocResult;
*/
public class BridgeTest {
@Rule public TemporaryFolder tempFolder = new TemporaryFolder();
private Bridge bridge;
private ProjectLock lock;
@@ -71,6 +78,28 @@ public class BridgeTest {
verify(gcJob).stop();
}
@Test
public void healthCheckPassesWhenRepoStoreRootIsWritable() throws IOException {
File rootDirectory = tempFolder.newFolder("repostore");
new File(rootDirectory, ".wlgb").mkdir();
when(repoStore.getRootDirectory()).thenReturn(rootDirectory);
assertTrue(bridge.healthCheck());
}
@Test
public void healthCheckFailsWhenRepoStoreRootIsMissing() {
File rootDirectory = new File(tempFolder.getRoot(), "does-not-exist");
when(repoStore.getRootDirectory()).thenReturn(rootDirectory);
assertFalse(bridge.healthCheck());
}
@Test
public void healthCheckFailsWhenWlgbDirectoryIsMissing() throws IOException {
File rootDirectory = tempFolder.newFolder("repostore");
when(repoStore.getRootDirectory()).thenReturn(rootDirectory);
assertFalse(bridge.healthCheck());
}
@Test
public void updatingRepositorySetsLastAccessedTime()
throws IOException, GitUserException, CannotAcquireLockException {
+1 -1
View File
@@ -5,7 +5,7 @@
VERSION=$(date +%y%m%d%H%M%S)
if [ -z "$GIT_BRIDGE_JVM_ARGS" ]; then
GIT_BRIDGE_JVM_ARGS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=50.0"
GIT_BRIDGE_JVM_ARGS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=50.0 -XX:+ExitOnOutOfMemoryError"
fi
if [ "$ENABLE_PROFILE_AGENT" = "true" ]; then