Skip to content

Commit

Permalink
not sure why im getting 'always' instead of 'never'
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed Jul 13, 2023
1 parent 1ee7033 commit 5c6fc2e
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@
import javax.inject.Inject;
import javax.inject.Provider;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.openjdk.jmc.common.unit.QuantityConversionException;
import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

import io.cryostat.configuration.CredentialsManager;
import io.cryostat.core.log.Logger;
import io.cryostat.core.net.JFRConnection;
Expand All @@ -69,17 +75,11 @@
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
import io.cryostat.recordings.RecordingOptionsBuilderFactory;
import io.cryostat.recordings.RecordingTargetHelper;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.HttpException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

public class TargetRecordingsPostHandler extends AbstractAuthenticatedRequestHandler {

Expand Down Expand Up @@ -221,7 +221,8 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception {
eventSpecifier);
IRecordingDescriptor descriptor =
recordingTargetHelper.startRecording(
restart,
null,
"always",
connectionDescriptor,
builder.build(),
template.getLeft(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import graphql.schema.DataFetchingEnvironment;
import io.cryostat.configuration.CredentialsManager;
import io.cryostat.core.templates.TemplateType;
import io.cryostat.jmc.serialization.HyperlinkedSerializableRecordingDescriptor;
Expand All @@ -65,10 +69,6 @@
import io.cryostat.recordings.RecordingOptionsBuilderFactory;
import io.cryostat.recordings.RecordingTargetHelper;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import graphql.schema.DataFetchingEnvironment;

class StartRecordingOnTargetMutator
extends AbstractPermissionedDataFetcher<HyperlinkedSerializableRecordingDescriptor> {

Expand Down Expand Up @@ -179,7 +179,8 @@ public HyperlinkedSerializableRecordingDescriptor getAuthenticated(
}
IRecordingDescriptor desc =
recordingTargetHelper.startRecording(
restart,
null,
"always",
cd,
builder.build(),
(String) settings.get("template"),
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/io/cryostat/recordings/RecordingTargetHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.openjdk.jmc.common.unit.IConstrainedMap;
import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID;
import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder;
import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor.RecordingState;

import dagger.Lazy;
import io.cryostat.core.log.Logger;
import io.cryostat.core.net.JFRConnection;
import io.cryostat.core.templates.Template;
Expand All @@ -70,13 +73,9 @@
import io.cryostat.net.web.WebServer;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;

import dagger.Lazy;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

public class RecordingTargetHelper {

Expand Down Expand Up @@ -221,6 +220,8 @@ public IRecordingDescriptor startRecording(
throws Exception {
String recordingName = (String) recordingOptions.get(RecordingOptionsBuilder.KEY_NAME);
boolean restartRecording = shouldRestartRecording(replace, restart);
System.out.println("++==Restart value: " + restart); // Log the value of restart
System.out.println("++==Replace value: " + replace);

return targetConnectionManager.executeConnectedTask(
connectionDescriptor,
Expand Down Expand Up @@ -282,18 +283,40 @@ public IRecordingDescriptor startRecording(
}

private boolean shouldRestartRecording(String replace, String restart) {
if (replace != null) {
System.out.println("++replace: " + replace);
System.out.println("++restart: " + restart);

if (replace != null && !replace.isEmpty()) {
switch (replace) {
case "always":
System.out.println("++replace is 'always'");
return true;
case "stopped":
return restart == null || restart.equals("true");
System.out.println("replace is 'stopped'");
// Check if the recording is stopped
boolean isStopped = isRecordingStopped(replace);
System.out.println("++isStopped: " + isStopped);
return isStopped;
case "never":
default:
System.out.println("++replace is 'never'");
return false;
}
}
// Default behavior if 'replace' is not specified

// Handle restart parameter (deprecated)
if (restart != null && !restart.isEmpty()) { // Check 'restart' parameter here
System.out.println("++Handling restart parameter");
boolean isStopped = isRecordingStopped(restart);
System.out.println("++isStopped: " + isStopped);
return isStopped;
}
// if neither restart nor replace is specified, default to never
System.out.println("++Defaulting to 'never'");
return false;
}

private boolean isRecordingStopped(String restart) {
// If restart is null or "true", consider the recording as stopped
return restart != null && restart.equals("true");
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/cryostat/rules/RuleProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

import javax.script.ScriptException;

import org.apache.commons.lang3.tuple.Pair;
import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor;

Expand All @@ -73,10 +74,8 @@
import io.cryostat.rules.RuleRegistry.RuleEvent;
import io.cryostat.util.events.Event;
import io.cryostat.util.events.EventListener;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import org.apache.commons.lang3.tuple.Pair;

public class RuleProcessor extends AbstractVerticle implements Consumer<TargetDiscoveryEvent> {

Expand Down Expand Up @@ -405,7 +404,8 @@ private void startRuleRecording(ConnectionDescriptor connectionDescriptor, Rule
RecordingTargetHelper.parseEventSpecifierToTemplate(
rule.getEventSpecifier());
return recordingTargetHelper.startRecording(
true,
"true",
"always",
connectionDescriptor,
builder.build(),
template.getLeft(),
Expand Down
Loading

0 comments on commit 5c6fc2e

Please sign in to comment.