10000 fix(remote): improve response status codes, don't include harvester snapshots in listing by andrewazores · Pull Request #380 · cryostatio/cryostat-agent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(remote): improve response status codes, don't include harvester snapshots in listing #380

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

Merged
merged 3 commits into from
Apr 23, 2024
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
2 changes: 2 additions & 0 deletions src/main/java/io/cryostat/agent/harvest/HarvestModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public static Harvester provideHarvester(
FlightRecorderHelper flightRecorderHelper,
Registration registration) {
RecordingSettings exitSettings = new RecordingSettings();
exitSettings.name = Harvester.RECORDING_NAME_ON_EXIT;
exitSettings.maxAge = exitMaxAge;
exitSettings.maxSize = exitMaxSize;
RecordingSettings periodicSettings = new RecordingSettings();
periodicSettings.name = Harvester.RECORDING_NAME_HARVESTER_SNAPSHOT;
periodicSettings.maxAge = maxAge > 0 ? maxAge : (long) (period * 1.5);
periodicSettings.maxSize = maxSize;
return new Harvester(
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/cryostat/agent/harvest/Harvester.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@

public class Harvester implements FlightRecorderListener {

public static final String RECORDING_NAME_ON_EXIT = "onexit";
public static final String RECORDING_NAME_HARVESTER_SNAPSHOT = "harvester_snapshot";

private final Logger log = LoggerFactory.getLogger(getClass());

private final ScheduledExecutorService executor;
Expand Down Expand Up @@ -382,11 +385,15 @@ public enum PushType {
}

public static class RecordingSettings implements UnaryOperator<Recording> {
public String name;
public long maxSize;
public long maxAge;

@Override
public Recording apply(Recording r) {
if (StringUtils.isNotBlank(name)) {
r.setName(name);
}
if (maxSize > 0) {
r.setMaxSize(maxSize);
}
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/io/cryostat/agent/remote/RecordingsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
Expand All @@ -35,6 +34,7 @@
import javax.inject.Inject;

import io.cryostat.agent.FlightRecorderHelper;
import io.cryostat.agent.harvest.Harvester;
import io.cryostat.agent.util.StringUtils;
import io.cryostat.core.serialization.SerializableRecordingDescriptor;
import io.cryostat.core.templates.MutableTemplateService.InvalidEventTemplateException;
Expand All @@ -43,6 +43,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpExchange;
import jdk.jfr.Recording;
import jdk.jfr.RecordingState;
import org.apache.http.HttpStatus;
import org.eclipse.microprofile.config.Config;
import org.slf4j.Logger;
Expand Down Expand Up @@ -130,6 +131,10 @@ private void handleGetList(HttpExchange exchange) {
try (OutputStream response = exchange.getResponseBody()) {
List<SerializableRecordingDescriptor> recordings =
flightRecorder.getRecordings().stream()
.filter(
r ->
!Harvester.RECORDING_NAME_HARVESTER_SNAPSHOT.equals(
r.getName()))
.map(SerializableRecordingDescriptor::new)
.collect(Collectors.toList());
exchange.sendResponseHeaders(HttpStatus.SC_OK, BODY_LENGTH_UNKNOWN);
Expand Down Expand Up @@ -288,8 +293,16 @@ private void handleStopOrUpdate(HttpExchange exchange, long recordingId) throws
}
}
if (shouldStop) {
if (!recording.stop()) {
sendHeader(exchange, HttpStatus.SC_BAD_REQUEST);
try {
if (!recording.stop()) {
sendHeader(exchange, HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
} catch (IllegalStateException e) {
sendHeader(
exchange,
recording.getState().equals(RecordingState.STOPPED)
? HttpStatus.SC_NO_CONTENT
: HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}

Expand All @@ -316,10 +329,13 @@ private void handleStopOrUpdate(HttpExchange exchange, long recordingId) throws

private void handleDelete(HttpExchange exchange, long recordingId) throws IOException {
try {
flightRecorder.getRecording(recordingId).orElseThrow().close();
Optional<Recording> opt = flightRecorder.getRecording(recordingId);
if (opt.isEmpty()) {
sendHeader(exchange, HttpStatus.SC_NOT_FOUND);
return;
}
opt.get().close();
sendHeader(exchange, HttpStatus.SC_NO_CONTENT);
} catch (NoSuchElementException e) {
sendHeader(exchange, HttpStatus.SC_NOT_FOUND);
} catch (Exception e) {
log.error("Operation failed", e);
sendHeader(exchange, HttpStatus.SC_INTERNAL_SERVER_ERROR);
Expand Down
0