Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent): implement HTTP JFR snapshot creation #1627

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/java/io/cryostat/net/AgentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,57 @@ Future<IRecordingDescriptor> startRecording(StartRecordingRequest req) {
});
}

Future<IRecordingDescriptor> startSnapshot() {
StartRecordingRequest snapshotReq = new StartRecordingRequest("snapshot", "", "", 0, 0, 0);

Future<HttpResponse<String>> f =
invoke(
HttpMethod.POST,
"/recordings/",
Buffer.buffer(gson.toJson(snapshotReq)),
BodyCodec.string());

return f.map(
resp -> {
int statusCode = resp.statusCode();
if (HttpStatusCodeIdentifier.isSuccessCode(statusCode)) {
String body = resp.body();
return gson.fromJson(body, SerializableRecordingDescriptor.class)
.toJmcForm();
} else if (statusCode == 403) {
throw new UnsupportedOperationException();
} else {
throw new RuntimeException("Unknown failure");
}
});
}

Future<Void> updateRecordingOptions(long id, IConstrainedMap<String> newSettings) {

JsonObject jsonSettings = new JsonObject();
for (String key : newSettings.keySet()) {
jsonSettings.put(key, newSettings.get(key));
}
Future<HttpResponse<Void>> f =
invoke(
HttpMethod.PATCH,
String.format("/recordings/%d", id),
jsonSettings.toBuffer(),
BodyCodec.none());

return f.map(
resp -> {
int statusCode = resp.statusCode();
if (HttpStatusCodeIdentifier.isSuccessCode(statusCode)) {
return null;
} else if (statusCode == 403) {
throw new UnsupportedOperationException();
} else {
throw new RuntimeException("Unknown failure");
}
});
}

Future<Buffer> openStream(long id) {
Future<HttpResponse<Buffer>> f =
invoke(HttpMethod.GET, "/recordings/" + id, BodyCodec.buffer());
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/io/cryostat/net/AgentJFRService.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ public List<String> getServerTemplates() throws FlightRecorderException {

@Override
public IRecordingDescriptor getSnapshotRecording() throws FlightRecorderException {
throw new UnimplementedException();
try {
return client.startSnapshot().toCompletionStage().toCompletableFuture().get();
} catch (ExecutionException | InterruptedException e) {
throw new FlightRecorderException("Failed to create snapshot recording", e);
}
}

@Override
Expand Down Expand Up @@ -245,9 +249,18 @@ public void updateEventOptions(IRecordingDescriptor arg0, IConstrainedMap<EventO
}

@Override
public void updateRecordingOptions(IRecordingDescriptor arg0, IConstrainedMap<String> arg1)
public void updateRecordingOptions(
IRecordingDescriptor recordingDescriptor, IConstrainedMap<String> newSettings)
throws FlightRecorderException {
throw new UnimplementedException();
try {
long recordingId = recordingDescriptor.getId();
client.updateRecordingOptions(recordingId, newSettings)
.toCompletionStage()
.toCompletableFuture()
.get();
} catch (ExecutionException | InterruptedException e) {
throw new FlightRecorderException("Failed to update recording options", e);
}
}

@Override
Expand Down
Loading