Skip to content

Commit

Permalink
don't emit notifications when externally-created (or cross-url, for d…
Browse files Browse the repository at this point in the history
…uplicated target definitions) recordings are observed
  • Loading branch information
andrewazores committed Apr 2, 2024
1 parent 5282bc0 commit 0bc5399
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.cryostat.ws.MessagingServer;
import io.cryostat.ws.Notification;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.quarkus.hibernate.orm.panache.PanacheEntity;
import io.vertx.mutiny.core.eventbus.EventBus;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -79,6 +80,12 @@ public class ActiveRecording extends PanacheEntity {
@PositiveOrZero public long maxSize;
@PositiveOrZero public long maxAge;

/**
* true if the recording was discovered on the Target and must have been created by some
* external process (not Cryostat), false if created by Cryostat.
*/
@JsonIgnore public boolean external;

@JdbcTypeCode(SqlTypes.JSON)
@NotNull
public Metadata metadata;
Expand Down Expand Up @@ -150,6 +157,9 @@ static class Listener {

@PostPersist
public void postPersist(ActiveRecording activeRecording) {
if (activeRecording.external) {
return;
}
bus.publish(
Recordings.RecordingEventCategory.ACTIVE_CREATED.category(), activeRecording);
notify(
Expand All @@ -160,6 +170,9 @@ public void postPersist(ActiveRecording activeRecording) {

@PostUpdate
public void postUpdate(ActiveRecording activeRecording) {
if (activeRecording.external) {
return;
}
if (RecordingState.STOPPED.equals(activeRecording.state)) {
bus.publish(
Recordings.RecordingEventCategory.ACTIVE_STOPPED.category(),
Expand All @@ -173,6 +186,9 @@ public void postUpdate(ActiveRecording activeRecording) {

@PostRemove
public void postRemove(ActiveRecording activeRecording) {
if (activeRecording.external) {
return;
}
bus.publish(
Recordings.RecordingEventCategory.ACTIVE_DELETED.category(), activeRecording);
notify(
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,38 @@ public List<ActiveRecording> listActiveRecordings(Target target) {
boolean updated = false;
for (var descriptor : descriptors) {
if (previousIds.contains(descriptor.getId())) {
var recording = target.getRecordingById(descriptor.getId());
switch (descriptor.getState()) {
case CREATED:
recording.state = RecordingState.DELAYED;
updated |= true;
break;
case RUNNING:
recording.state = RecordingState.RUNNING;
updated |= true;
break;
case STOPPING:
recording.state = RecordingState.RUNNING;
updated |= true;
break;
case STOPPED:
recording.state = RecordingState.STOPPED;
updated |= true;
break;
default:
recording.state = RecordingState.NEW;
updated |= true;
break;
}
if (updated) {
recording.persist();
}
continue;
}
updated |= true;
// TODO is there any metadata to attach here?
var recording = ActiveRecording.from(target, descriptor, new Metadata(Map.of()));
recording.external = true;
// FIXME this is a hack. Older Cryostat versions enforced that recordings' names
// were unique within the target JVM, but this could only be enforced when Cryostat
// was originating the recording creation. Recordings already have unique IDs, so
Expand Down

0 comments on commit 0bc5399

Please sign in to comment.