Skip to content
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

fix(discovery): check container discovery domain socket readability before start #251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion smoketest/compose/cryostat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ services:
QUARKUS_HTTP_HOST: "cryostat"
QUARKUS_HTTP_PORT: ${CRYOSTAT_HTTP_PORT}
QUARKUS_HIBERNATE_ORM_LOG_SQL: "true"
CRYOSTAT_DISCOVERY_PODMAN_ENABLED: "true"
CRYOSTAT_DISCOVERY_JDP_ENABLED: "true"
CRYOSTAT_DISCOVERY_PODMAN_ENABLED: "true"
CRYOSTAT_DISCOVERY_DOCKER_ENABLED: "true"
JAVA_OPTS_APPEND: "-XX:+FlightRecorder -XX:StartFlightRecording=name=onstart,settings=default,disk=true,maxage=5m -XX:StartFlightRecording=name=startup,settings=profile,disk=true,duration=30s -Dcom.sun.management.jmxremote.autodiscovery=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9091 -Dcom.sun.management.jmxremote.rmi.port=9091 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false"
restart: unless-stopped
healthcheck:
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/cryostat/ConfigProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class ConfigProperties {
public static final String AWS_OBJECT_EXPIRATION_LABELS =
"storage.buckets.archives.expiration-label";

public static final String CONTAINERS_POLL_PERIOD = "cryostat.discovery.containers.poll-period";
public static final String CONTAINERS_REQUEST_TIMEOUT =
"cryostat.discovery.containers.request-timeout";

public static final String CONNECTIONS_MAX_OPEN = "cryostat.connections.max-open";
public static final String CONNECTIONS_TTL = "cryostat.connections.ttl";
public static final String CONNECTIONS_FAILED_BACKOFF = "cryostat.connections.failed-backoff";
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/io/cryostat/discovery/ContainerDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -34,8 +36,10 @@

import javax.management.remote.JMXServiceURL;

import io.cryostat.ConfigProperties;
import io.cryostat.URIUtil;
import io.cryostat.core.net.JFRConnectionToolkit;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.targets.Target;
import io.cryostat.targets.Target.Annotations;
import io.cryostat.targets.Target.EventKind;
Expand Down Expand Up @@ -131,11 +135,18 @@ public abstract class ContainerDiscovery {
public static final String JMX_PORT_LABEL = "io.cryostat.jmxPort";

@Inject Logger logger;
@Inject FileSystem fs;
@Inject Vertx vertx;
@Inject WebClient webClient;
@Inject JFRConnectionToolkit connectionToolkit;
@Inject ObjectMapper mapper;

@ConfigProperty(name = ConfigProperties.CONTAINERS_POLL_PERIOD)
Duration pollPeriod;

@ConfigProperty(name = ConfigProperties.CONTAINERS_REQUEST_TIMEOUT)
Duration requestTimeout;

protected long timerId;

protected final CopyOnWriteArrayList<ContainerSpec> containers = new CopyOnWriteArrayList<>();
Expand All @@ -146,6 +157,15 @@ void onStart(@Observes StartupEvent evt) {
return;
}

Path socketPath = Path.of(getSocket().path());
if (!(fs.exists(socketPath) && fs.isReadable(socketPath))) {
logger.errorv(
"{0} enabled but socket {1} is not accessible!",
getClass().getName(), socketPath);
return;
}
logger.infov("{0} started", getClass().getName());

DiscoveryNode universe = DiscoveryNode.getUniverse();
if (DiscoveryNode.getRealm(getRealm()).isEmpty()) {
DiscoveryPlugin plugin = new DiscoveryPlugin();
Expand All @@ -158,7 +178,7 @@ void onStart(@Observes StartupEvent evt) {
}

queryContainers();
this.timerId = vertx.setPeriodic(10_000, unused -> queryContainers());
this.timerId = vertx.setPeriodic(pollPeriod.toMillis(), unused -> queryContainers());
}

void onStop(@Observes ShutdownEvent evt) {
Expand Down Expand Up @@ -219,7 +239,7 @@ private void doContainerListRequest(Consumer<List<ContainerSpec>> successHandler
.addQueryParam(
"filters",
mapper.writeValueAsString(Map.of("label", List.of(DISCOVERY_LABEL))))
.timeout(2_000L)
.timeout(requestTimeout.toMillis())
.as(BodyCodec.string())
.send()
.subscribe()
Expand Down Expand Up @@ -249,7 +269,7 @@ private CompletableFuture<ContainerDetails> doContainerInspectRequest(ContainerS
URI requestPath = URI.create(getContainerQueryURL(container));
webClient
.request(HttpMethod.GET, getSocket(), 80, "localhost", requestPath.toString())
.timeout(2_000L)
.timeout(requestTimeout.toMillis())
.as(BodyCodec.string())
.send()
.subscribe()
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
quarkus.naming.enable-jndi=true
cryostat.discovery.jdp.enabled=false
cryostat.discovery.containers.poll-period=10s
cryostat.discovery.containers.request-timeout=2s
cryostat.discovery.podman.enabled=false
cryostat.discovery.docker.enabled=false
quarkus.test.integration-test-profile=test
Expand Down
Loading