Skip to content

Commit

Permalink
fix deleteRecording mutation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed May 7, 2024
1 parent f018f84 commit 3019caa
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 184 deletions.
105 changes: 47 additions & 58 deletions src/main/java/io/cryostat/graphql/ActiveRecordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.openjdk.jmc.common.unit.QuantityConversionException;

Expand Down Expand Up @@ -58,18 +59,19 @@
@GraphQLApi
public class ActiveRecordings {

@Inject RecordingHelper recordingHelper;
@Inject Logger logger;
@Inject
RecordingHelper recordingHelper;
@Inject
Logger logger;

@ConfigProperty(name = ConfigProperties.CONNECTIONS_FAILED_TIMEOUT)
Duration timeout;

@Blocking
@Transactional
@Mutation
@Description(
"Start a new Flight Recording on all Targets under the subtrees of the discovery nodes"
+ " matching the given filter")
@Description("Start a new Flight Recording on all Targets under the subtrees of the discovery nodes"
+ " matching the given filter")
public List<ActiveRecording> createRecording(
@NonNull DiscoveryNodeFilter nodes, @NonNull RecordingSettings recording)
throws QuantityConversionException {
Expand Down Expand Up @@ -109,9 +111,8 @@ public List<ActiveRecording> createRecording(
@Blocking
@Transactional
@Mutation
@Description(
"Archive an existing Flight Recording matching the given filter, on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
@Description("Archive an existing Flight Recording matching the given filter, on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
public List<ArchivedRecording> archiveRecording(
@NonNull DiscoveryNodeFilter nodes, @Nullable ActiveRecordingsFilter recordings)
throws Exception {
Expand Down Expand Up @@ -141,9 +142,8 @@ public List<ArchivedRecording> archiveRecording(
@Blocking
@Transactional
@Mutation
@Description(
"Stop an existing Flight Recording matching the given filter, on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
@Description("Stop an existing Flight Recording matching the given filter, on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
public List<ActiveRecording> stopRecording(
@NonNull DiscoveryNodeFilter nodes, @Nullable ActiveRecordingsFilter recordings)
throws Exception {
Expand Down Expand Up @@ -172,10 +172,9 @@ public List<ActiveRecording> stopRecording(
@Blocking
@Transactional
@Mutation
@Description(
"Delete an existing Flight Recording matching the given filter, on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
public List<ActiveRecording> deleteRecording(
@Description("Delete an existing Flight Recording matching the given filter, on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
public Uni<List<ActiveRecording>> deleteRecording(
@NonNull DiscoveryNodeFilter nodes, @Nullable ActiveRecordingsFilter recordings) {
var list =
DiscoveryNode.<DiscoveryNode>listAll().stream()
Expand All @@ -202,9 +201,8 @@ public List<ActiveRecording> deleteRecording(
@Blocking
@Transactional
@Mutation
@Description(
"Create a Flight Recorder Snapshot on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
@Description("Create a Flight Recorder Snapshot on all Targets under"
+ " the subtrees of the discovery nodes matching the given filter")
public List<ActiveRecording> createSnapshot(@NonNull DiscoveryNodeFilter nodes) {
var targets =
DiscoveryNode.<DiscoveryNode>listAll().stream()
Expand All @@ -229,9 +227,8 @@ public ActiveRecording doStartRecording(
@Source Target target, @NonNull RecordingSettings recording)
throws QuantityConversionException {
var fTarget = Target.getTargetById(target.id);
Template template =
recordingHelper.getPreferredTemplate(
fTarget, recording.template, TemplateType.valueOf(recording.templateType));
Template template = recordingHelper.getPreferredTemplate(
fTarget, recording.template, TemplateType.valueOf(recording.templateType));
return recordingHelper
.startRecording(
fTarget,
Expand Down Expand Up @@ -284,8 +281,7 @@ public TargetNodes.ActiveRecordings active(

var in = recordings.active;
if (in != null && in.data != null) {
out.data =
in.data.stream().filter(r -> filter == null ? true : filter.test(r)).toList();
out.data = in.data.stream().filter(r -> filter == null ? true : filter.test(r)).toList();
out.aggregate = AggregateInfo.fromActive(out.data);
}

Expand Down Expand Up @@ -330,7 +326,8 @@ public static class MetadataLabels {

private Map<String, String> labels;

public MetadataLabels() {}
public MetadataLabels() {
}

public MetadataLabels(Map<String, String> labels) {
this.labels = new HashMap<>(labels);
Expand Down Expand Up @@ -365,44 +362,36 @@ public static class ActiveRecordingsFilter implements Predicate<ActiveRecording>

@Override
public boolean test(ActiveRecording r) {
Predicate<ActiveRecording> matchesName =
n -> name == null || Objects.equals(name, n.name);
Predicate<ActiveRecording> matchesName = n -> name == null || Objects.equals(name, n.name);
Predicate<ActiveRecording> matchesNames = n -> names == null || names.contains(n.name);
Predicate<ActiveRecording> matchesLabels =
n ->
labels == null
|| labels.stream()
.allMatch(
label ->
LabelSelectorMatcher.parse(label)
.test(n.metadata.labels()));
Predicate<ActiveRecording> matchesLabels = n -> labels == null
|| labels.stream()
.allMatch(
label -> LabelSelectorMatcher.parse(label)
.test(n.metadata.labels()));
Predicate<ActiveRecording> matchesState = n -> state == null || n.state.equals(state);
Predicate<ActiveRecording> matchesContinuous =
n -> continuous == null || continuous.equals(n.continuous);
Predicate<ActiveRecording> matchesToDisk =
n -> toDisk == null || toDisk.equals(n.toDisk);
Predicate<ActiveRecording> matchesDurationGte =
n ->
durationMsGreaterThanEqual == null
|| durationMsGreaterThanEqual >= n.duration;
Predicate<ActiveRecording> matchesDurationLte =
n -> durationMsLessThanEqual == null || durationMsLessThanEqual <= n.duration;
Predicate<ActiveRecording> matchesStartTimeAfter =
n -> startTimeMsAfterEqual == null || startTimeMsAfterEqual >= n.startTime;
Predicate<ActiveRecording> matchesStartTimeBefore =
n -> startTimeMsBeforeEqual == null || startTimeMsBeforeEqual <= n.startTime;
Predicate<ActiveRecording> matchesContinuous = n -> continuous == null || continuous.equals(n.continuous);
Predicate<ActiveRecording> matchesToDisk = n -> toDisk == null || toDisk.equals(n.toDisk);
Predicate<ActiveRecording> matchesDurationGte = n -> durationMsGreaterThanEqual == null
|| durationMsGreaterThanEqual >= n.duration;
Predicate<ActiveRecording> matchesDurationLte = n -> durationMsLessThanEqual == null
|| durationMsLessThanEqual <= n.duration;
Predicate<ActiveRecording> matchesStartTimeAfter = n -> startTimeMsAfterEqual == null
|| startTimeMsAfterEqual >= n.startTime;
Predicate<ActiveRecording> matchesStartTimeBefore = n -> startTimeMsBeforeEqual == null
|| startTimeMsBeforeEqual <= n.startTime;

return List.of(
matchesName,
matchesNames,
matchesLabels,
matchesState,
matchesContinuous,
matchesToDisk,
matchesDurationGte,
matchesDurationLte,
matchesStartTimeBefore,
matchesStartTimeAfter)
matchesName,
matchesNames,
matchesLabels,
matchesState,
matchesContinuous,
matchesToDisk,
matchesDurationGte,
matchesDurationLte,
matchesStartTimeBefore,
matchesStartTimeAfter)
.stream()
.reduce(x -> true, Predicate::and)
.test(r);
Expand Down
Loading

0 comments on commit 3019caa

Please sign in to comment.