Skip to content

Commit

Permalink
remove HTML-based rules report generation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Sep 22, 2023
1 parent f7df109 commit 6958104
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 329 deletions.
1 change: 0 additions & 1 deletion src/main/java/io/cryostat/configuration/Variables.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private Variables() {}
// report generation
public static final String REPORT_GENERATOR_ENV = "CRYOSTAT_REPORT_GENERATOR";
public static final String SUBPROCESS_MAX_HEAP_ENV = "CRYOSTAT_REPORT_GENERATION_MAX_HEAP";
public static final String REPORT_STATS_PATH = "CRYOSTAT_REPORT_STATS_PATH";
public static final String ACTIVE_REPORTS_CACHE_EXPIRY_ENV =
"CRYOSTAT_ACTIVE_REPORTS_CACHE_EXPIRY_SECONDS";
public static final String ACTIVE_REPORTS_CACHE_REFRESH_ENV =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ protected AbstractReportGeneratorService(

@Override
public final CompletableFuture<Path> exec(
RecordingDescriptor recordingDescriptor, String filter, boolean formatted)
throws Exception {
RecordingDescriptor recordingDescriptor, String filter) throws Exception {
Path recording =
getRecordingFromLiveTarget(
recordingDescriptor.recordingName,
recordingDescriptor.connectionDescriptor);
Path saveFile = fs.createTempFile(null, null);

CompletableFuture<Path> cf = exec(recording, saveFile, filter, formatted);
CompletableFuture<Path> cf = exec(recording, saveFile, filter);
return cf.whenComplete(
(p, t) -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
class ActiveRecordingReportCache implements NotificationListener<Map<String, Object>> {
protected final Provider<ReportGeneratorService> reportGeneratorServiceProvider;
protected final FileSystem fs;
protected final LoadingCache<RecordingDescriptor, String> htmlCache;
protected final LoadingCache<RecordingDescriptor, String> jsonCache;
protected final TargetConnectionManager targetConnectionManager;
protected final long generationTimeoutSeconds;
Expand All @@ -71,86 +70,52 @@ class ActiveRecordingReportCache implements NotificationListener<Map<String, Obj
this.cacheExpirySeconds = cacheExpirySeconds;
this.cacheRefreshSeconds = cacheRefreshSeconds;
this.logger = logger;
this.htmlCache =
Caffeine.newBuilder()
.scheduler(Scheduler.systemScheduler())
.expireAfterWrite(30, TimeUnit.MINUTES)
.refreshAfterWrite(5, TimeUnit.MINUTES)
.softValues()
.build((k) -> getReport(k, true));
this.jsonCache =
Caffeine.newBuilder()
.scheduler(Scheduler.systemScheduler())
.expireAfterWrite(cacheExpirySeconds, TimeUnit.SECONDS)
.refreshAfterWrite(cacheRefreshSeconds, TimeUnit.SECONDS)
.softValues()
.build((k) -> getReport(k, false));
.build(this::getReport);
}

Future<String> get(
ConnectionDescriptor connectionDescriptor,
String recordingName,
String filter,
boolean formatted) {
ConnectionDescriptor connectionDescriptor, String recordingName, String filter) {
CompletableFuture<String> f = new CompletableFuture<>();
try {
if (formatted) {
if (filter.isBlank()) {
f.complete(
htmlCache.get(
new RecordingDescriptor(connectionDescriptor, recordingName)));
} else {
f.complete(
getReport(
new RecordingDescriptor(connectionDescriptor, recordingName),
filter,
true));
}
if (filter.isBlank()) {
f.complete(
jsonCache.get(
new RecordingDescriptor(connectionDescriptor, recordingName)));
} else {
if (filter.isBlank()) {
f.complete(
jsonCache.get(
new RecordingDescriptor(connectionDescriptor, recordingName)));
} else {
f.complete(
getReport(
new RecordingDescriptor(connectionDescriptor, recordingName),
filter,
false));
}
f.complete(
getReport(
new RecordingDescriptor(connectionDescriptor, recordingName),
filter));
}

} catch (Exception e) {
f.completeExceptionally(e);
}
return f;
}

boolean delete(
ConnectionDescriptor connectionDescriptor, String recordingName, boolean formatted) {
boolean delete(ConnectionDescriptor connectionDescriptor, String recordingName) {
RecordingDescriptor key = new RecordingDescriptor(connectionDescriptor, recordingName);
boolean hasKey =
formatted ? htmlCache.asMap().containsKey(key) : jsonCache.asMap().containsKey(key);
boolean hasKey = jsonCache.asMap().containsKey(key);
if (hasKey) {
logger.trace("Invalidated active report cache for {}", recordingName);
if (formatted) {
htmlCache.invalidate(key);
} else {
jsonCache.invalidate(key);
}
jsonCache.invalidate(key);
} else {
logger.trace("No cache entry for {} to invalidate", recordingName);
}
return hasKey;
}

protected String getReport(RecordingDescriptor recordingDescriptor, boolean formatted)
throws Exception {
return getReport(recordingDescriptor, EMPTY_FILTERS, formatted);
protected String getReport(RecordingDescriptor recordingDescriptor) throws Exception {
return getReport(recordingDescriptor, EMPTY_FILTERS);
}

protected String getReport(
RecordingDescriptor recordingDescriptor, String filter, boolean formatted)
protected String getReport(RecordingDescriptor recordingDescriptor, String filter)
throws Exception {
Path saveFile = null;
try {
Expand All @@ -160,16 +125,13 @@ protected String getReport(
saveFile =
reportGeneratorServiceProvider
.get()
.exec(recordingDescriptor, filter, formatted)
.exec(recordingDescriptor, filter)
.get(generationTimeoutSeconds, TimeUnit.SECONDS);
return fs.readString(saveFile);
} catch (ExecutionException | CompletionException e) {
logger.error(e);

delete(
recordingDescriptor.connectionDescriptor,
recordingDescriptor.recordingName,
formatted);
delete(recordingDescriptor.connectionDescriptor, recordingDescriptor.recordingName);

if (e.getCause()
instanceof SubprocessReportGenerator.SubprocessReportGenerationException) {
Expand Down Expand Up @@ -217,7 +179,7 @@ public void onNotification(Notification<Map<String, Object>> notification) {
((HyperlinkedSerializableRecordingDescriptor)
notification.getMessage().get("recording"))
.getName();
delete(new ConnectionDescriptor(targetId), recordingName, true);
delete(new ConnectionDescriptor(targetId), recordingName);
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ class ArchivedRecordingReportCache {
this.logger = logger;
}

Future<Path> getFromPath(
String subdirectoryName, String recordingName, String filter, boolean formatted) {
Future<Path> getFromPath(String subdirectoryName, String recordingName, String filter) {
CompletableFuture<Path> f = new CompletableFuture<>();
Path dest = null;
try {
dest =
recordingArchiveHelper
.getCachedReportPathFromPath(
subdirectoryName, recordingName, filter, formatted)
.getCachedReportPathFromPath(subdirectoryName, recordingName, filter)
.get();
if (fs.isReadable(dest) && fs.isRegularFile(dest)) {
f.complete(dest);
Expand All @@ -73,7 +71,7 @@ Future<Path> getFromPath(
Path saveFile =
reportGeneratorServiceProvider
.get()
.exec(archivedRecording, dest, filter, formatted)
.exec(archivedRecording, dest, filter)
.get(generationTimeoutSeconds, TimeUnit.SECONDS);
f.complete(saveFile);
} catch (Exception e) {
Expand All @@ -88,17 +86,17 @@ Future<Path> getFromPath(
return f;
}

Future<Path> get(String recordingName, String filter, boolean formatted) {
return this.get(null, recordingName, filter, formatted);
Future<Path> get(String recordingName, String filter) {
return this.get(null, recordingName, filter);
}

Future<Path> get(String sourceTarget, String recordingName, String filter, boolean formatted) {
Future<Path> get(String sourceTarget, String recordingName, String filter) {
CompletableFuture<Path> f = new CompletableFuture<>();
Path dest = null;
try {
dest =
recordingArchiveHelper
.getCachedReportPath(sourceTarget, recordingName, filter, formatted)
.getCachedReportPath(sourceTarget, recordingName, filter)
.get();
if (fs.isReadable(dest) && fs.isRegularFile(dest)) {
f.complete(dest);
Expand All @@ -111,7 +109,7 @@ Future<Path> get(String sourceTarget, String recordingName, String filter, boole
Path saveFile =
reportGeneratorServiceProvider
.get()
.exec(archivedRecording, dest, filter, formatted)
.exec(archivedRecording, dest, filter)
.get(generationTimeoutSeconds, TimeUnit.SECONDS);
f.complete(saveFile);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class RemoteReportGenerator extends AbstractReportGeneratorService {

@Override
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
public CompletableFuture<Path> exec(
Path recording, Path destination, String filter, boolean formatted) {
public CompletableFuture<Path> exec(Path recording, Path destination, String filter) {
String reportGenerator = env.getEnv(Variables.REPORT_GENERATOR_ENV);
logger.trace("POSTing {} to {}", recording, reportGenerator);
var form =
Expand All @@ -73,7 +72,7 @@ public CompletableFuture<Path> exec(
HttpMimeType.OCTET_STREAM.mime());

var f = new CompletableFuture<Path>();
String acceptHeader = formatted ? HttpMimeType.HTML.mime() : HttpMimeType.JSON.mime();
String acceptHeader = HttpMimeType.JSON.mime();
this.http
.postAbs(String.format("%s/report", reportGenerator))
.putHeader(HttpHeaders.ACCEPT.toString(), acceptHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import java.util.concurrent.CompletableFuture;

interface ReportGeneratorService {
CompletableFuture<Path> exec(Path in, Path out, String filter, boolean formatted)
throws Exception;
CompletableFuture<Path> exec(Path in, Path out, String filter) throws Exception;

CompletableFuture<Path> exec(RecordingDescriptor rd, String filter, boolean formatted)
throws Exception;
CompletableFuture<Path> exec(RecordingDescriptor rd, String filter) throws Exception;
}
26 changes: 10 additions & 16 deletions src/main/java/io/cryostat/net/reports/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,24 @@ public class ReportService {
this.archivedCache = archivedCache;
}

public Future<Path> getFromPath(
String subdirectoryName, String recordingName, String filter, boolean formatted) {
return archivedCache.getFromPath(subdirectoryName, recordingName, filter, formatted);
public Future<Path> getFromPath(String subdirectoryName, String recordingName, String filter) {
return archivedCache.getFromPath(subdirectoryName, recordingName, filter);
}

public Future<Path> get(String recordingName, String filter, boolean formatted) {
return archivedCache.get(recordingName, filter, formatted);
public Future<Path> get(String recordingName, String filter) {
return archivedCache.get(recordingName, filter);
}

public Future<Path> get(
String sourceTarget, String recordingName, String filter, boolean formatted) {
return archivedCache.get(sourceTarget, recordingName, filter, formatted);
public Future<Path> get(String sourceTarget, String recordingName, String filter) {
return archivedCache.get(sourceTarget, recordingName, filter);
}

public Future<String> get(
ConnectionDescriptor connectionDescriptor,
String recordingName,
String filter,
boolean formatted) {
return activeCache.get(connectionDescriptor, recordingName, filter, formatted);
ConnectionDescriptor connectionDescriptor, String recordingName, String filter) {
return activeCache.get(connectionDescriptor, recordingName, filter);
}

public boolean delete(
ConnectionDescriptor connectionDescriptor, String recordingName, boolean formatted) {
return activeCache.delete(connectionDescriptor, recordingName, formatted);
public boolean delete(ConnectionDescriptor connectionDescriptor, String recordingName) {
return activeCache.delete(connectionDescriptor, recordingName);
}
}
34 changes: 0 additions & 34 deletions src/main/java/io/cryostat/net/reports/ReportTransformerModule.java

This file was deleted.

13 changes: 1 addition & 12 deletions src/main/java/io/cryostat/net/reports/ReportsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
*/
package io.cryostat.net.reports;

import java.util.Set;

import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import io.cryostat.configuration.Variables;
import io.cryostat.core.log.Logger;
import io.cryostat.core.reports.ReportTransformer;
import io.cryostat.core.sys.Environment;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.messaging.notifications.NotificationListener;
Expand All @@ -32,18 +29,14 @@
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.util.JavaProcess;

import com.google.gson.Gson;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;
import io.vertx.core.Vertx;
import io.vertx.ext.web.client.WebClient;

@Module(
includes = {
ReportTransformerModule.class,
})
@Module
public abstract class ReportsModule {

public static final String REPORT_GENERATION_TIMEOUT_SECONDS =
Expand Down Expand Up @@ -144,19 +137,15 @@ static RemoteReportGenerator provideRemoteReportGenerator(
@Provides
static SubprocessReportGenerator provideSubprocessReportGenerator(
Environment env,
Gson gson,
FileSystem fs,
TargetConnectionManager targetConnectionManager,
Set<ReportTransformer> reportTransformers,
Provider<JavaProcess.Builder> javaProcessBuilder,
@Named(REPORT_GENERATION_TIMEOUT_SECONDS) long generationTimeoutSeconds,
Logger logger) {
return new SubprocessReportGenerator(
env,
gson,
fs,
targetConnectionManager,
reportTransformers,
javaProcessBuilder,
generationTimeoutSeconds,
logger);
Expand Down
Loading

0 comments on commit 6958104

Please sign in to comment.