mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(core): report at startup which services an unreachable Docker affects (#5773)
* feat(core): report at startup which services an unreachable Docker affects Floci starts without Docker, but each container-backed service only reports the missing daemon on first use, and differently. RDS, ElastiCache, EKS and peers keep their control plane with no container behind it. Lambda, ECS, CodeBuild and others cannot run the work that needs a container: an invoke returns a Lambda.InitError, an ECS task stops, a build goes to FAULT. A native binary run without Docker gave no hint of this up front. DockerAvailabilityReport pings the daemon once after startup, off the startup path, and when it does not answer logs a single warning naming the enabled services in each group. Nothing is logged when Docker answers or when no affected service is enabled. A Lambda invoke that cannot start its container because Docker is unreachable now says so in its Lambda.InitError payload instead of the raw socket error. Refs #5767 Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(core): name every Docker-dependent service and the endpoint actually probed Review follow-ups for the no-Docker report: - redshift-serverless, rds-data and athena also need a container (the serverless runtime, the RDS database, floci-duck), so they are listed as failing on use. - A service whose container work goes elsewhere is left out: Lambda on the kubernetes executor, Athena with floci.services.duck.url, Verified Permissions with a cedar-url. Pipes is named for its Kafka sources only. - The warning names the endpoint the Docker client resolves (DOCKER_HOST, the active context, the Windows pipe), not the configured default. - The Lambda InitError names Docker only on the docker executor, and also for an unresolvable Docker host. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
167336fc73
commit
4c32fae5e3
4 files changed
+283
-7
No files matched your search
@@ -0,0 +1,98 @@
|
||||
package io.github.hectorvent.floci.lifecycle;
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.ServiceRegistry;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class DockerAvailabilityReportTest {
|
||||
|
||||
private final ContainerLifecycleManager lifecycle = mock(ContainerLifecycleManager.class);
|
||||
private final DockerClient docker = mock(DockerClient.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
private final ServiceRegistry registry = mock(ServiceRegistry.class);
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
private final DockerAvailabilityReport report = new DockerAvailabilityReport(lifecycle, registry, config);
|
||||
|
||||
@Test
|
||||
void unreachableDaemonReportsTheReason() {
|
||||
when(lifecycle.getDockerClient()).thenReturn(docker);
|
||||
when(docker.pingCmd().exec()).thenThrow(new RuntimeException("java.net.SocketException: No such file or directory"));
|
||||
|
||||
assertThat(report.unreachableReason(), containsString("No such file or directory"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reachableDaemonHasNoReason() {
|
||||
when(lifecycle.getDockerClient()).thenReturn(docker);
|
||||
|
||||
assertThat(report.unreachableReason(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noAffectedServiceEnabledSkipsTheProbe() {
|
||||
when(registry.getEnabledServices()).thenReturn(List.of("sqs", "s3", "dynamodb"));
|
||||
|
||||
report.report();
|
||||
|
||||
verify(lifecycle, never()).getDockerClient();
|
||||
}
|
||||
|
||||
@Test
|
||||
void affectedServicesAreProbed() {
|
||||
when(registry.getEnabledServices()).thenReturn(List.of("sqs", "lambda", "rds"));
|
||||
when(config.services().lambda().executor()).thenReturn("docker");
|
||||
when(lifecycle.getDockerClient()).thenReturn(docker);
|
||||
|
||||
report.report();
|
||||
|
||||
verify(lifecycle).getDockerClient();
|
||||
}
|
||||
|
||||
@Test
|
||||
void listsDoNotOverlap() {
|
||||
assertThat(DockerAvailabilityReport.METADATA_ONLY.stream()
|
||||
.filter(DockerAvailabilityReport.FAIL_ON_USE::contains).toList(), is(empty()));
|
||||
assertThat(DockerAvailabilityReport.FAIL_ON_USE, not(empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void servicesBackedByADockerRuntimeFailOnUse() {
|
||||
when(config.services().lambda().executor()).thenReturn("docker");
|
||||
when(config.services().duck().url()).thenReturn(Optional.empty());
|
||||
|
||||
assertThat(report.failOnUse(Set.of("redshift-serverless", "rds-data", "athena", "lambda", "sqs")),
|
||||
contains("lambda", "redshift-serverless", "rds-data", "athena"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void servicesPointedElsewhereAreNotReported() {
|
||||
when(config.services().lambda().executor()).thenReturn(" Kubernetes ");
|
||||
when(config.services().duck().url()).thenReturn(Optional.of("http://duck:8080"));
|
||||
when(config.services().verifiedpermissions().cedarUrl()).thenReturn(Optional.of("http://cedar:8080"));
|
||||
|
||||
assertThat(report.failOnUse(Set.of("lambda", "athena", "verifiedpermissions", "ecs")), contains("ecs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pipesIsQualifiedToItsKafkaSources() {
|
||||
assertThat(report.failOnUse(Set.of("pipes")), contains("pipes (Kafka sources)"));
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
class LambdaInitFailureMessageTest {
|
||||
|
||||
@Test
|
||||
void unreachableDockerIsNamed() {
|
||||
Exception e = new RuntimeException("java.net.SocketException: No such file or directory",
|
||||
new SocketException("No such file or directory"));
|
||||
|
||||
String message = LambdaExecutorService.initFailureMessage(e, true);
|
||||
|
||||
assertThat(message, containsString("Docker is not reachable (No such file or directory)"));
|
||||
assertThat(message, containsString("Lambda functions run in Docker containers"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherFailuresKeepTheirMessage() {
|
||||
assertThat(LambdaExecutorService.initFailureMessage(new IllegalStateException("image pull failed"), true),
|
||||
equalTo("Failed to start Lambda container: image pull failed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnresolvableDockerHostIsNamed() {
|
||||
Exception e = new RuntimeException("docker.internal", new UnknownHostException("docker.internal"));
|
||||
|
||||
assertThat(LambdaExecutorService.initFailureMessage(e, true),
|
||||
containsString("Docker is not reachable (docker.internal)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void kubernetesSocketErrorsDoNotBlameDocker() {
|
||||
Exception e = new RuntimeException("connect failed", new SocketException("Connection refused"));
|
||||
|
||||
assertThat(LambdaExecutorService.initFailureMessage(e, false),
|
||||
equalTo("Failed to start Lambda container: connect failed"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user