Skip to content

Commit

Permalink
tiered jmxUrl/jmxHost+jmxPort labelling, new required discovery label
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Jun 1, 2023
1 parent 7887689 commit fb25cf2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
2 changes: 2 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ podman run \
--pod cryostat-pod \
--name cryostat \
--user 0 \
--label io.cryostat.discovery="true" \
--label io.cryostat.jmxHost="localhost" \
--label io.cryostat.jmxPort="0" \
--label io.cryostat.jmxUrl="service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi" \
--memory 768M \
--mount type=bind,source="$(dirname "$0")/archive",destination=/opt/cryostat.d/recordings.d,relabel=shared \
--mount type=bind,source="$(dirname "$0")/certs",destination=/certs,relabel=shared \
Expand Down
8 changes: 6 additions & 2 deletions smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ runDemoApps() {
--env CRYOSTAT_AGENT_TRUST_ALL="true" \
--env CRYOSTAT_AGENT_AUTHORIZATION="Basic $(echo user:pass | base64)" \
--pod cryostat-pod \
--label io.cryostat.discovery="true" \
--label io.cryostat.jmxHost="localhost" \
--label io.cryostat.jmxPort="9093" \
--rm -d quay.io/andrewazores/vertx-fib-demo:0.12.2
Expand All @@ -141,8 +142,10 @@ runDemoApps() {
--env CRYOSTAT_AGENT_TRUST_ALL="true" \
--env CRYOSTAT_AGENT_AUTHORIZATION="Basic $(echo user:pass | base64)" \
--pod cryostat-pod \
--label io.cryostat.discovery="true" \
--label io.cryostat.jmxHost="localhost" \
--label io.cryostat.jmxPort="9094" \
--label io.cryostat.jmxUrl="service:jmx:rmi:///jndi/rmi://localhost:9094/jmxrmi" \
--rm -d quay.io/andrewazores/vertx-fib-demo:0.12.2

podman run \
Expand All @@ -161,8 +164,8 @@ runDemoApps() {
--env CRYOSTAT_AGENT_TRUST_ALL="true" \
--env CRYOSTAT_AGENT_AUTHORIZATION="Basic $(echo user:pass | base64)" \
--pod cryostat-pod \
--label io.cryostat.jmxHost="localhost" \
--label io.cryostat.jmxPort="9095" \
--label io.cryostat.discovery="true" \
--label io.cryostat.jmxUrl="service:jmx:rmi:///jndi/rmi://localhost:9095/jmxrmi" \
--rm -d quay.io/andrewazores/vertx-fib-demo:0.12.2

# this config is broken on purpose (missing required env vars) to test the agent's behaviour
Expand Down Expand Up @@ -271,6 +274,7 @@ runReportGenerator() {
--name reports \
--pull "${PULL_IMAGES}" \
--pod cryostat-pod \
--label io.cryostat.discovery="true" \
--label io.cryostat.jmxHost="localhost" \
--label io.cryostat.jmxPort="${RJMX_PORT}" \
--cpus 1 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -70,6 +71,7 @@
import io.cryostat.platform.discovery.EnvironmentNode;
import io.cryostat.platform.discovery.NodeType;
import io.cryostat.platform.discovery.TargetNode;
import io.cryostat.util.URIUtil;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
Expand All @@ -85,6 +87,8 @@
public class PodmanPlatformClient extends AbstractPlatformClient {

public static final String REALM = "Podman";
public static final String DISCOVERY_LABEL = "io.cryostat.discovery";
public static final String JMX_URL_LABEL = "io.cryostat.jmxUrl";
public static final String JMX_HOST_LABEL = "io.cryostat.jmxHost";
public static final String JMX_PORT_LABEL = "io.cryostat.jmxPort";

Expand Down Expand Up @@ -195,7 +199,7 @@ private void doPodmanListRequest(Consumer<List<ContainerSpec>> successHandler) {
requestPath.toString())
.addQueryParam(
"filters",
gson.toJson(Map.of("label", List.of(JMX_PORT_LABEL))))
gson.toJson(Map.of("label", List.of(DISCOVERY_LABEL))))
.timeout(2_000L)
.as(BodyCodec.string())
.send(
Expand Down Expand Up @@ -253,18 +257,36 @@ private CompletableFuture<ContainerDetails> doPodmanInspectRequest(ContainerSpec

private ServiceRef convert(ContainerSpec desc) {
try {
int jmxPort = Integer.valueOf(desc.Labels.get(JMX_PORT_LABEL));
String hostname = desc.Labels.get(JMX_HOST_LABEL);
if (hostname == null) {
try {
hostname =
doPodmanInspectRequest(desc).get(2, TimeUnit.SECONDS).Config.Hostname;
} catch (InterruptedException | TimeoutException | ExecutionException e) {
logger.warn(e);
return null;
JMXServiceURL connectUrl;
String hostname;
int jmxPort;
if (desc.Labels.containsKey(JMX_URL_LABEL)) {
connectUrl = new JMXServiceURL(desc.Labels.get(JMX_URL_LABEL));
if (URIUtil.isRmiUrl(connectUrl)) {
URI serviceUrl = URIUtil.getRmiTarget(connectUrl);
hostname = serviceUrl.getHost();
jmxPort = serviceUrl.getPort();
} else {
hostname = connectUrl.getHost();
jmxPort = connectUrl.getPort();
}
} else {
jmxPort = Integer.valueOf(desc.Labels.get(JMX_PORT_LABEL));
hostname = desc.Labels.get(JMX_HOST_LABEL);
if (hostname == null) {
try {
hostname =
doPodmanInspectRequest(desc)
.get(2, TimeUnit.SECONDS)
.Config
.Hostname;
} catch (InterruptedException | TimeoutException | ExecutionException e) {
logger.warn(e);
return null;
}
}
connectUrl = connectionToolkit.get().createServiceURL(hostname, jmxPort);
}
JMXServiceURL connectUrl = connectionToolkit.get().createServiceURL(hostname, jmxPort);

Map<AnnotationKey, String> cryostatAnnotations = new HashMap<>();
cryostatAnnotations.put(AnnotationKey.REALM, REALM);
Expand All @@ -284,7 +306,7 @@ private ServiceRef convert(ContainerSpec desc) {
serviceRef.setLabels(desc.Labels);

return serviceRef;
} catch (MalformedURLException e) {
} catch (URISyntaxException | MalformedURLException e) {
logger.warn(e);
return null;
}
Expand Down

0 comments on commit fb25cf2

Please sign in to comment.