Skip to content

Commit

Permalink
fix(registration): JMX URL defaults to reusing callback host part (cr…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Jun 12, 2024
1 parent 2d588a1 commit c3031d1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ and how it advertises itself to a Cryostat server instance. Properties that requ
- [ ] `cryostat.agent.app.name` [`String`]: a human-friendly name for this application. Default `cryostat-agent`.
- [ ] `cryostat.agent.app.jmx.port` [`int`]: the JMX RMI port that the application is listening on. The default is to attempt to determine this from the `com.sun.management.jmxremote.port` system property.
- [ ] `cryostat.agent.registration.retry-ms` [`long`]: the duration in milliseconds between attempts to register with the Cryostat server. Default `5000`.
- [ ] `cryostat.agent.registration.jmx.ignore` [`boolean`]: if the Agent detects that the host JVM has its JMX server enabled, then setting this property to `true` will cause the Agent to ignore the JMX server and not publish a JMX Service URL after registering with the Cryostat server. Default `false`.
- [ ] `cryostat.agent.registration.jmx.use-callback-host` [`boolean`]: if the Agent should use the host part of the callback URL when constructing the JMX Service URL for registration. If set to `false` then the URL will contain the automatically detected hostname instead. Default `true`.
- [ ] `cryostat.agent.exit.signals` [`[String]`]: a comma-separated list of signals that the agent should handle. When any of these signals is caught the agent initiates an orderly shutdown, deregistering from the Cryostat server and potentially uploading the latest harvested JFR data. Default `INT,TERM`.
- [ ] `cryostat.agent.exit.deregistration.timeout-ms` [`long`]: the duration in milliseconds to wait for a response from the Cryostat server when attempting to deregister at shutdown time . Default `3000`.
- [ ] `cryostat.agent.harvester.period-ms` [`long`]: the length of time between JFR collections and pushes by the harvester. This also controls the maximum age of data stored in the buffer for the harvester's managed Flight Recording. Every `period-ms` the harvester will upload a JFR binary file to the `cryostat.agent.baseuri` archives. Default `-1`, which indicates no scheduled harvest uploading will be performed.
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/cryostat/agent/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public abstract class ConfigModule {
"cryostat.agent.registration.retry-ms";
public static final String CRYOSTAT_AGENT_REGISTRATION_CHECK_MS =
"cryostat.agent.registration.check-ms";
public static final String CRYOSTAT_AGENT_REGISTRATION_JMX_IGNORE =
"cryostat.agent.registration.jmx.ignore";
public static final String CRYOSTAT_AGENT_REGISTRATION_JMX_USE_CALLBACK_HOST =
"cryostat.agent.registration.jmx.use-callback-host";
public static final String CRYOSTAT_AGENT_EXIT_SIGNALS = "cryostat.agent.exit.signals";
public static final String CRYOSTAT_AGENT_EXIT_DEREGISTRATION_TIMEOUT_MS =
"cryostat.agent.exit.deregistration.timeout-ms";
Expand Down Expand Up @@ -316,6 +320,20 @@ public static int provideCryostatAgentRegistrationCheckMs(Config config) {
return config.getValue(CRYOSTAT_AGENT_REGISTRATION_CHECK_MS, int.class);
}

@Provides
@Singleton
@Named(CRYOSTAT_AGENT_REGISTRATION_JMX_IGNORE)
public static boolean provideCryostatAgentRegistrationJmxIgnore(Config config) {
return config.getValue(CRYOSTAT_AGENT_REGISTRATION_JMX_IGNORE, boolean.class);
}

@Provides
@Singleton
@Named(CRYOSTAT_AGENT_REGISTRATION_JMX_USE_CALLBACK_HOST)
public static boolean provideCryostatAgentRegistrationJmxUseCallbackHost(Config config) {
return config.getValue(CRYOSTAT_AGENT_REGISTRATION_JMX_USE_CALLBACK_HOST, boolean.class);
}

@Provides
@Singleton
@Named(CRYOSTAT_AGENT_HARVESTER_PERIOD_MS)
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/io/cryostat/agent/MainModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ public static Registration provideRegistration(
@Named(ConfigModule.CRYOSTAT_AGENT_HOSTNAME) String hostname,
@Named(ConfigModule.CRYOSTAT_AGENT_APP_JMX_PORT) int jmxPort,
@Named(ConfigModule.CRYOSTAT_AGENT_REGISTRATION_RETRY_MS) int registrationRetryMs,
@Named(ConfigModule.CRYOSTAT_AGENT_REGISTRATION_CHECK_MS) int registrationCheckMs) {

@Named(ConfigModule.CRYOSTAT_AGENT_REGISTRATION_CHECK_MS) int registrationCheckMs,
@Named(ConfigModule.CRYOSTAT_AGENT_REGISTRATION_JMX_IGNORE)
boolean registrationJmxIgnore,
@Named(ConfigModule.CRYOSTAT_AGENT_REGISTRATION_JMX_USE_CALLBACK_HOST)
boolean registrationJmxUseCallbackHost) {
Logger log = LoggerFactory.getLogger(Registration.class);
return new Registration(
Executors.newSingleThreadScheduledExecutor(
Expand All @@ -249,7 +252,9 @@ public static Registration provideRegistration(
hostname,
jmxPort,
registrationRetryMs,
registrationCheckMs);
registrationCheckMs,
registrationJmxIgnore,
registrationJmxUseCallbackHost);
}

@Provides
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/cryostat/agent/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class Registration {
private final int jmxPort;
private final int registrationRetryMs;
private final int registrationCheckMs;
private final boolean registrationJmxIgnore;
private final boolean registrationJmxUseCallbackHost;

private final PluginInfo pluginInfo = new PluginInfo();
private final Set<Consumer<RegistrationEvent>> listeners = new HashSet<>();
Expand All @@ -77,7 +79,9 @@ public class Registration {
String hostname,
int jmxPort,
int registrationRetryMs,
int registrationCheckMs) {
int registrationCheckMs,
boolean registrationJmxIgnore,
boolean registrationJmxUseCallbackHost) {
this.executor = executor;
this.cryostat = cryostat;
this.callback = callback;
Expand All @@ -90,6 +94,8 @@ public class Registration {
this.jmxPort = jmxPort;
this.registrationRetryMs = registrationRetryMs;
this.registrationCheckMs = registrationCheckMs;
this.registrationJmxIgnore = registrationJmxIgnore;
this.registrationJmxUseCallbackHost = registrationJmxUseCallbackHost;
}

void start() {
Expand Down Expand Up @@ -296,12 +302,13 @@ private Set<DiscoveryNode> defineSelf() throws UnknownHostException, URISyntaxEx
discoveryNodes.add(
new DiscoveryNode(appName + "-agent-" + pluginInfo.getId(), NODE_TYPE, httpSelf));

if (jmxPort > 0) {
if (!registrationJmxIgnore && jmxPort > 0) {
uri =
URI.create(
String.format(
"service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi",
hostname, jmxPort));
registrationJmxUseCallbackHost ? uri.getHost() : hostname,
jmxPort));
port = jmxPort;
DiscoveryNode.Target jmxSelf =
new DiscoveryNode.Target(
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/microprofile-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ cryostat.agent.realm=
cryostat.agent.exit.signals=INT,TERM
cryostat.agent.registration.retry-ms=5000
cryostat.agent.registration.check-ms=60000
cryostat.agent.registration.jmx.ignore=false
cryostat.agent.registration.jmx.use-callback-host=true
cryostat.agent.exit.deregistration.timeout-ms=3000

cryostat.agent.harvester.period-ms=-1
Expand Down

0 comments on commit c3031d1

Please sign in to comment.