Skip to content

Commit

Permalink
fix(discovery): properly delete nodes when targets disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Apr 22, 2024
1 parent a05895c commit e3686da
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/cryostat/discovery/ContainerDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void onStart(@Observes StartupEvent evt) {
universe.persist();
}

logger.info(String.format("Starting %s client", getRealm()));
logger.infov("Starting {0} client", getRealm());

queryContainers();
this.timerId = vertx.setPeriodic(pollPeriod.toMillis(), unused -> queryContainers());
Expand All @@ -187,7 +187,7 @@ void onStop(@Observes ShutdownEvent evt) {
if (!enabled()) {
return;
}
logger.info(String.format("Shutting down %s client", getRealm()));
logger.infov("Shutting down {0} client", getRealm());
vertx.cancelTimer(timerId);
}

Expand Down Expand Up @@ -399,6 +399,7 @@ public void handleContainerEvent(ContainerSpec desc, EventKind evtKind) {
} else {
realm.children.remove(t.discoveryNode);
}
t.discoveryNode.parent = null;
realm.persist();
t.delete();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/cryostat/discovery/CustomDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public Response delete(@RestPath long id) throws URISyntaxException {
Target target = Target.find("id", id).singleResult();
DiscoveryNode realm = DiscoveryNode.getRealm(REALM).orElseThrow();
realm.children.remove(target.discoveryNode);
target.discoveryNode = null;
realm.persist();
target.delete();
return Response.noContent().build();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/cryostat/discovery/JDPDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public synchronized void handleJdpEvent(JvmDiscoveryEvent evt) {
case LOST:
Target t = Target.getTargetByConnectUrl(connectUrl);
realm.children.remove(t.discoveryNode);
t.discoveryNode.parent = null;
realm.persist();
t.delete();
break;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/cryostat/discovery/KubeApiDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public void handleEndpointEvent(String namespace) {

if (!nsNode.hasChildren()) {
realm.children.remove(nsNode);
nsNode.parent = null;
} else if (!realm.children.contains(nsNode)) {
realm.children.add(nsNode);
nsNode.parent = realm;
Expand Down Expand Up @@ -275,6 +276,7 @@ private void pruneOwnerChain(DiscoveryNode nsNode, Target target) {
}

parent.children.remove(child);
child.parent = null;
parent.persist();

if (parent.hasChildren()
Expand Down

0 comments on commit e3686da

Please sign in to comment.