Skip to content

Commit

Permalink
fix(jmxauth): tolerate JMX auth failures at discovery, re-attempt if …
Browse files Browse the repository at this point in the history
…new matching Credentials added
  • Loading branch information
andrewazores committed Mar 20, 2024
1 parent e73ae62 commit 05ef44f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/main/java/io/cryostat/targets/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@ void prePersist(Target target) throws JvmIdException {
.await()
.atMost(Duration.ofSeconds(10));
} catch (Exception e) {
// TODO tolerate this in the condition that the connection failed because of JMX
// auth. In that instance then persist the entity with a null jvmId, but listen for
// new Credentials and test them against any targets with null jvmIds to see if we
// can populate them.
throw new JvmIdException(e);
logger.info(e);
}
}

Expand Down
44 changes: 44 additions & 0 deletions src/main/java/io/cryostat/targets/Targets.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,62 @@
package io.cryostat.targets;

import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Optional;

import io.cryostat.credentials.Credential;
import io.cryostat.expressions.MatchExpressionEvaluator;

import io.quarkus.vertx.ConsumeEvent;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestResponse;
import org.projectnessie.cel.tools.ScriptException;

@Path("")
public class Targets {

@Inject MatchExpressionEvaluator matchExpressionEvaluator;
@Inject TargetConnectionManager connectionManager;
@Inject Logger logger;

@ConsumeEvent(value = Credential.CREDENTIALS_STORED, blocking = true)
@Transactional
void updateCredential(Credential credential) {
Target.<Target>find("jvmId", (String) null)
.list()
.forEach(
t -> {
try {
if (matchExpressionEvaluator.applies(
credential.matchExpression, t)) {
t.jvmId =
connectionManager
.executeDirect(
t,
Optional.empty(),
conn ->
conn.getJvmIdentifier()
.getHash())
.await()
.atMost(Duration.ofSeconds(10));
t.persist();
}
} catch (ScriptException e) {
logger.error(e);
} catch (Exception e) {
logger.warn(e);
}
});
}

@GET
@Path("/api/v1/targets")
@RolesAllowed("read")
Expand Down

0 comments on commit 05ef44f

Please sign in to comment.