Skip to content

Commit

Permalink
fix(discovery): ignore when target does not exist in db
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Apr 2, 2024
1 parent afbc9e5 commit a06797e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main/java/io/cryostat/discovery/KubeApiDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import jakarta.persistence.NoResultException;
import jakarta.transaction.Transactional;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
Expand Down Expand Up @@ -216,6 +217,8 @@ public void handleEndpointEvent(TargetTuple tuple, EventKind eventKind) {
}
break;
default:
logger.warnv("Unknown discovery event {0}", eventKind);
break;
}
}

Expand All @@ -234,7 +237,12 @@ private void pruneOwnerChain(DiscoveryNode nsNode, TargetTuple targetTuple) {
String targetKind = TargetTuple.getKind();
KubeDiscoveryNodeType targetType = KubeDiscoveryNodeType.fromKubernetesKind(targetKind);

Target target = Target.getTargetByConnectUrl(targetTuple.toTarget().connectUrl);
Target target;
try {
target = Target.getTargetByConnectUrl(targetTuple.toTarget().connectUrl);
} catch (NoResultException e) {
return;
}

DiscoveryNode targetNode = target.discoveryNode;

Expand Down Expand Up @@ -444,11 +452,11 @@ public void onUpdate(Endpoints oldEndpoints, Endpoints newEndpoints) {
return;
}

TargetTuple.compare(previousTuples).to(currentTuples).added().stream()
.forEach(tuple -> handleEndpointEvent(tuple, EventKind.FOUND));

TargetTuple.compare(previousTuples).to(currentTuples).removed().stream()
.forEach(tuple -> handleEndpointEvent(tuple, EventKind.LOST));

TargetTuple.compare(previousTuples).to(currentTuples).added().stream()
.forEach(tuple -> handleEndpointEvent(tuple, EventKind.FOUND));
}

@Override
Expand Down Expand Up @@ -523,11 +531,11 @@ public Target toTarget() {
.cryostat()
.putAll(
Map.of(
"REALM", // AnnotationKey.REALM,
"REALM",
REALM,
"HOST", // AnnotationKey.HOST,
"HOST",
addr.getIp(),
"PORT", // "AnnotationKey.PORT,
"PORT",
Integer.toString(port.getPort()),
"NAMESPACE",
objRef.getNamespace(),
Expand Down Expand Up @@ -558,8 +566,8 @@ public boolean equals(Object other) {
.append(objRef.getKind(), sr.objRef.getKind())
.append(objRef.getNamespace(), sr.objRef.getNamespace())
.append(objRef.getName(), sr.objRef.getName())
.append(addr, sr.addr)
.append(port, sr.port)
.append(addr.getIp(), sr.addr.getIp())
.append(port.getPort(), sr.port.getPort())
.build();
}

Expand Down

0 comments on commit a06797e

Please sign in to comment.