mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(timestream-influxdb): rediscover endpoints after reboot (#7259)
* fix(timestream-influxdb): rediscover endpoints after reboot Resolve the current container endpoint after Docker restarts, then use it for readiness and instance/cluster persistence, including failed readiness. Preserve preferred-network selection and existing resource ownership. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> * fix(timestream-influxdb): refresh all endpoints on member reboot Publish the rediscovered shared-container endpoint through the owning cluster when RebootDbInstance addresses a cluster member. Preserve standalone instance updates and propagate success or readiness failure to the cluster and every member. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> * test(timestream-influxdb): cover both reboot entrypoints in one matrix Parameterize shared cluster/member reboot assertions over the entrypoint and readiness outcome. Add the missing unhealthy cluster reboot case while preserving endpoint and member-state assertions. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> * fix(timestream-influxdb): retain effective network when restarting Resolve the restart network through the same service, global and current-container fallback used at creation. Preserve aggregate endpoint propagation, readiness deadlines and host-mode port resolution. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> --------- Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
105d6732f3
commit
65e9522433
4 files changed
+149
-7
No files matched your search
+8
-5
@@ -293,7 +293,9 @@ public class TimestreamInfluxDbService implements Resettable {
|
||||
if (hasDataPlane(containerId)) {
|
||||
instance.setStatus("REBOOTING");
|
||||
instances.put(key(region, instance.getId()), instance);
|
||||
restartAsync(DB_INSTANCE, instance.getAccountId(), region, instance.getId(),
|
||||
String clusterId = instance.getDbClusterId();
|
||||
restartAsync(clusterId == null ? DB_INSTANCE : DB_CLUSTER, instance.getAccountId(), region,
|
||||
clusterId == null ? instance.getId() : clusterId,
|
||||
new InfluxDbEndpoint(containerId, instance.getEndpoint(), instance.getPort()));
|
||||
}
|
||||
return new Reported<>(instance, "REBOOTING");
|
||||
@@ -852,13 +854,14 @@ public class TimestreamInfluxDbService implements Resettable {
|
||||
private void restartAsync(String resourceType, String accountId, String region, String resourceId,
|
||||
InfluxDbEndpoint endpoint) {
|
||||
executor.execute(() -> {
|
||||
InfluxDbEndpoint restarted = endpoint;
|
||||
try {
|
||||
containerManager.restart(endpoint.containerId());
|
||||
containerManager.waitUntilReady(endpoint);
|
||||
applyDataPlane(resourceType, accountId, region, resourceId, null, endpoint, AVAILABLE);
|
||||
restarted = containerManager.restart(endpoint.containerId());
|
||||
containerManager.waitUntilReady(restarted);
|
||||
applyDataPlane(resourceType, accountId, region, resourceId, null, restarted, AVAILABLE);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.errorv(e, "Failed to reboot the InfluxDB container for {0} {1}", resourceType, resourceId);
|
||||
applyDataPlane(resourceType, accountId, region, resourceId, null, endpoint, "REBOOT_FAILED");
|
||||
applyDataPlane(resourceType, accountId, region, resourceId, null, restarted, "REBOOT_FAILED");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+4
-1
@@ -186,8 +186,11 @@ public class TimestreamInfluxDbContainerManager implements ContainerTeardown {
|
||||
}
|
||||
}
|
||||
|
||||
public void restart(String containerId) {
|
||||
public InfluxDbEndpoint restart(String containerId) {
|
||||
lifecycleManager.getDockerClient().restartContainerCmd(containerId).exec();
|
||||
EndpointInfo endpoint = lifecycleManager.resolveEndpoint(containerId, INFLUX_PORT,
|
||||
containerBuilder.resolveDockerNetwork(config.services().timestreamInfluxdb().dockerNetwork()).orElse(null));
|
||||
return new InfluxDbEndpoint(containerId, endpoint.host(), endpoint.port());
|
||||
}
|
||||
|
||||
public void stop(String resourceId, String containerId) {
|
||||
|
||||
+65
@@ -17,6 +17,9 @@ import io.github.hectorvent.floci.services.timestreaminfluxdb.model.DbInstance;
|
||||
import io.github.hectorvent.floci.services.timestreaminfluxdb.model.DbParameterGroup;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.List;
|
||||
@@ -57,6 +60,8 @@ class TimestreamInfluxDbServiceTest {
|
||||
when(containerManager.legacyVolumeName(anyString())).thenAnswer(inv -> LEGACY_PREFIX + inv.getArgument(0));
|
||||
when(containerManager.start(anyString(), anyString(), anyString(), anyString(), any(), anyMap()))
|
||||
.thenReturn(new InfluxDbEndpoint("container-1", "localhost", 18086));
|
||||
when(containerManager.restart("container-1"))
|
||||
.thenReturn(new InfluxDbEndpoint("container-1", "localhost", 18086));
|
||||
SecretsManagerService secrets = mock(SecretsManagerService.class);
|
||||
Secret secret = mock(Secret.class);
|
||||
when(secret.getArn()).thenReturn("arn:aws:secretsmanager:us-east-1:000000000000:secret:influx");
|
||||
@@ -162,6 +167,66 @@ class TimestreamInfluxDbServiceTest {
|
||||
assertEquals("REBOOT_FAILED", service.getDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION).getStatus());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void rebootProbesAndPersistsTheRediscoveredEndpoint(boolean unhealthy) throws Exception {
|
||||
String id = createInstance("reboot-moved-db", null).getId();
|
||||
InfluxDbEndpoint moved = new InfluxDbEndpoint("container-1", "reassigned-host", 28086);
|
||||
when(containerManager.restart("container-1")).thenReturn(moved);
|
||||
if (unhealthy) {
|
||||
doThrow(new IllegalStateException("not healthy")).when(containerManager).waitUntilReady(moved);
|
||||
}
|
||||
|
||||
service.rebootDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION);
|
||||
|
||||
verify(containerManager).waitUntilReady(moved);
|
||||
DbInstance stored = service.getDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION);
|
||||
assertEquals(unhealthy ? "REBOOT_FAILED" : "AVAILABLE", stored.getStatus());
|
||||
assertEquals("reassigned-host", stored.getEndpoint());
|
||||
assertEquals(28086, stored.getPort());
|
||||
assertEquals("container-1", stored.getContainerId());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"false, false", "false, true", "true, false", "true, true"})
|
||||
void rebootPropagatesTheRediscoveredEndpointToClusterAndMembers(boolean memberReboot, boolean unhealthy)
|
||||
throws Exception {
|
||||
String id = service.createDbCluster(json("""
|
||||
{"name":"moved-cluster","dbInstanceType":"db.influx.large","allocatedStorage":20,
|
||||
"username":"admin","password":"password123","organization":"org","bucket":"bucket",
|
||||
"vpcSubnetIds":["subnet-1"],"vpcSecurityGroupIds":["sg-1"]}
|
||||
"""), REGION).resource().getId();
|
||||
InfluxDbEndpoint moved = new InfluxDbEndpoint("container-1", "reassigned-host", 28086);
|
||||
when(containerManager.restart("container-1")).thenReturn(moved);
|
||||
|
||||
if (unhealthy) {
|
||||
doThrow(new IllegalStateException("not healthy")).when(containerManager).waitUntilReady(moved);
|
||||
}
|
||||
List<DbInstance> before = service.listDbInstancesForCluster(
|
||||
json("{\"dbClusterId\":\"" + id + "\"}"), REGION).items();
|
||||
assertTrue(before.size() > 1);
|
||||
if (memberReboot) {
|
||||
String memberId = before.getFirst().getId();
|
||||
service.rebootDbInstance(json("{\"identifier\":\"" + memberId + "\"}"), REGION);
|
||||
} else {
|
||||
service.rebootDbCluster(json("{\"dbClusterId\":\"" + id + "\"}"), REGION);
|
||||
}
|
||||
|
||||
verify(containerManager).waitUntilReady(moved);
|
||||
DbCluster stored = service.getDbCluster(json("{\"dbClusterId\":\"" + id + "\"}"), REGION);
|
||||
assertEquals(unhealthy ? "REBOOT_FAILED" : "AVAILABLE", stored.getStatus());
|
||||
assertEquals("reassigned-host", stored.getEndpoint());
|
||||
assertEquals("reassigned-host", stored.getReaderEndpoint());
|
||||
List<DbInstance> members = service.listDbInstancesForCluster(
|
||||
json("{\"dbClusterId\":\"" + id + "\"}"), REGION).items();
|
||||
assertTrue(!members.isEmpty());
|
||||
for (DbInstance member : members) {
|
||||
assertEquals("reassigned-host", member.getEndpoint());
|
||||
assertEquals(28086, member.getPort());
|
||||
assertEquals(unhealthy ? "REBOOT_FAILED" : "AVAILABLE", member.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void backupCapturesContainerDataAndRestoreLoadsItIntoANewContainer() throws Exception {
|
||||
String sourceId = createInstance("backup-db", null).getId();
|
||||
|
||||
+72
-1
@@ -2,8 +2,10 @@ package io.github.hectorvent.floci.services.timestreaminfluxdb.container;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.command.RestartContainerCmd;
|
||||
import com.github.dockerjava.api.exception.NotFoundException;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerExecStubs;
|
||||
@@ -11,6 +13,8 @@ import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.ContainerInfo;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.EndpointInfo;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
|
||||
import io.github.hectorvent.floci.core.common.docker.CurrentContainerNetworkResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.PortAllocator;
|
||||
import io.github.hectorvent.floci.core.common.docker.RetryingTarCopier;
|
||||
import io.github.hectorvent.floci.services.timestreaminfluxdb.container.TimestreamInfluxDbContainerManager.InfluxDbEndpoint;
|
||||
@@ -20,7 +24,9 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.NullSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -29,6 +35,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
@@ -37,10 +44,12 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -54,6 +63,7 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
private PortAllocator portAllocator;
|
||||
private TimestreamInfluxDbContainerManager manager;
|
||||
private EmulatorConfig.StorageConfig storage;
|
||||
private EmulatorConfig.TimestreamInfluxDbServiceConfig influx;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -61,13 +71,14 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
ContainerBuilder containerBuilder = mock(ContainerBuilder.class);
|
||||
builder = mock(ContainerBuilder.Builder.class, Mockito.RETURNS_SELF);
|
||||
when(containerBuilder.newContainer(anyString())).thenReturn(builder);
|
||||
when(containerBuilder.resolveDockerNetwork(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
when(builder.build()).thenReturn(new ContainerSpec("test-image"));
|
||||
portAllocator = mock(PortAllocator.class);
|
||||
when(portAllocator.allocate(8086, 8185)).thenReturn(8090);
|
||||
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.TimestreamInfluxDbServiceConfig influx = mock(EmulatorConfig.TimestreamInfluxDbServiceConfig.class);
|
||||
influx = mock(EmulatorConfig.TimestreamInfluxDbServiceConfig.class);
|
||||
storage = mock(EmulatorConfig.StorageConfig.class);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(config.storage()).thenReturn(storage);
|
||||
@@ -81,6 +92,66 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
mock(ContainerDetector.class), portAllocator, config);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = "service-network")
|
||||
void restartResolvesTheCurrentEndpointAfterDockerCompletes(String network) {
|
||||
DockerClient docker = mock(DockerClient.class);
|
||||
RestartContainerCmd restart = mock(RestartContainerCmd.class);
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(docker);
|
||||
when(docker.restartContainerCmd("container-id")).thenReturn(restart);
|
||||
when(influx.dockerNetwork()).thenReturn(Optional.ofNullable(network));
|
||||
when(lifecycleManager.resolveEndpoint("container-id", 8086, network))
|
||||
.thenReturn(new EndpointInfo("reassigned-host", 18086));
|
||||
|
||||
assertEquals(new InfluxDbEndpoint("container-id", "reassigned-host", 18086),
|
||||
manager.restart("container-id"));
|
||||
|
||||
InOrder order = inOrder(restart, lifecycleManager);
|
||||
order.verify(restart).exec();
|
||||
order.verify(lifecycleManager).resolveEndpoint("container-id", 8086, network);
|
||||
verify(portAllocator, never()).allocate(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"service", "global", "detected", "none"})
|
||||
void restartUsesTheSameEffectiveNetworkAsCreation(String selection) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
CurrentContainerNetworkResolver networks = mock(CurrentContainerNetworkResolver.class);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.timestreamInfluxdb()).thenReturn(influx);
|
||||
when(influx.dockerNetwork()).thenReturn("service".equals(selection)
|
||||
? Optional.of("service-network") : Optional.empty());
|
||||
when(services.dockerNetwork()).thenReturn("service".equals(selection) || "global".equals(selection)
|
||||
? Optional.of("global-network") : Optional.empty());
|
||||
when(networks.resolveNetworkName()).thenReturn("none".equals(selection)
|
||||
? Optional.empty() : Optional.of("detected-network"));
|
||||
ContainerBuilder realBuilder = new ContainerBuilder(config, mock(DockerHostResolver.class),
|
||||
mock(EmbeddedDnsServer.class), networks);
|
||||
String expectedNetwork = "none".equals(selection) ? null : selection + "-network";
|
||||
assertEquals(expectedNetwork,
|
||||
realBuilder.resolveDockerNetwork(influx.dockerNetwork()).orElse(null));
|
||||
TimestreamInfluxDbContainerManager networkManager = new TimestreamInfluxDbContainerManager(
|
||||
realBuilder, lifecycleManager, mock(ContainerDetector.class), portAllocator, config);
|
||||
DockerClient docker = mock(DockerClient.class);
|
||||
RestartContainerCmd restart = mock(RestartContainerCmd.class);
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(docker);
|
||||
when(docker.restartContainerCmd("container-id")).thenReturn(restart);
|
||||
when(lifecycleManager.resolveEndpoint(eq("container-id"), eq(8086), any()))
|
||||
.thenAnswer(invocation -> new EndpointInfo(
|
||||
Objects.equals(expectedNetwork, invocation.getArgument(2))
|
||||
? "reachable-workload" : "unreachable-bridge", 8086));
|
||||
|
||||
assertEquals(new InfluxDbEndpoint("container-id", "reachable-workload", 8086),
|
||||
networkManager.restart("container-id"));
|
||||
|
||||
InOrder order = inOrder(restart, lifecycleManager);
|
||||
order.verify(restart).exec();
|
||||
order.verify(lifecycleManager).resolveEndpoint("container-id", 8086, expectedNetwork);
|
||||
verify(portAllocator, never()).allocate(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startRunsImageSetupPublishesTheHttpPortAndLabelsTheContainer() {
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(new ContainerInfo("container-id",
|
||||
|
||||
Reference in new issue
Block a user