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(reports): implement report generation #51

Merged
merged 14 commits into from
Aug 23, 2023
Merged
2 changes: 2 additions & 0 deletions smoketest/compose/s3-localstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
QUARKUS_S3_AWS_CREDENTIALS_TYPE: static
QUARKUS_S3_AWS_CREDENTIALS_STATIC_PROVIDER_ACCESS_KEY_ID: unused
QUARKUS_S3_AWS_CREDENTIALS_STATIC_PROVIDER_SECRET_ACCESS_KEY: unused
AWS_ACCESS_KEY_ID: unused
AWS_SECRET_ACCESS_KEY: unused
s3:
image: docker.io/localstack/localstack:1.4.0
hostname: s3
Expand Down
4 changes: 3 additions & 1 deletion smoketest/compose/s3-minio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ services:
QUARKUS_S3_AWS_CREDENTIALS_TYPE: static
QUARKUS_S3_AWS_CREDENTIALS_STATIC_PROVIDER_ACCESS_KEY_ID: minioroot
QUARKUS_S3_AWS_CREDENTIALS_STATIC_PROVIDER_SECRET_ACCESS_KEY: minioroot
AWS_ACCESS_KEY_ID: minioroot
AWS_SECRET_ACCESS_KEY: minioroot
s3:
image: docker.io/minio/minio:latest
hostname: minio
hostname: s3
ports:
- "9001:9001"
- "9000:9000"
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/io/cryostat/Producers.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
package io.cryostat;

import java.net.URI;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ScheduledExecutorService;

import io.cryostat.core.reports.InterruptibleReportGenerator;
import io.cryostat.core.sys.Clock;
import io.cryostat.core.sys.FileSystem;

import io.quarkus.arc.DefaultBean;
import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.ext.web.client.WebClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.projectnessie.cel.tools.ScriptHost;
import org.projectnessie.cel.types.jackson.JacksonRegistry;
Expand All @@ -37,6 +43,8 @@

public class Producers {

public static final String BASE64_URL = "BASE64_URL";

@Produces
@ApplicationScoped
@DefaultBean
Expand All @@ -51,16 +59,34 @@ public static FileSystem produceFileSystem() {
return new FileSystem();
}

@Produces
@ApplicationScoped
@DefaultBean
@Named(BASE64_URL)
public static Base64 produceBase64Url() {
return new Base64(0, null, true);
}

@Produces
@ApplicationScoped
@DefaultBean
public static ScheduledExecutorService produceScheduledExecutorService() {
return Executors.newSingleThreadScheduledExecutor();
}

@Produces
// RequestScoped so that each individual report generation request has its own interruptible
// generator with an independent task queueing thread which dispatches to the shared common pool
@RequestScoped
@DefaultBean
public static InterruptibleReportGenerator produceInterruptibleReportGenerator() {
return new InterruptibleReportGenerator(
io.cryostat.core.log.Logger.INSTANCE, Set.of(), ForkJoinPool.commonPool());
}

@Produces
@DefaultBean
public WebClient provideWebClient(Vertx vertx) {
public WebClient produceWebClient(Vertx vertx) {
return WebClient.create(vertx);
}

Expand Down Expand Up @@ -90,7 +116,7 @@ public static S3Presigner produceS3Presigner(
@Produces
@ApplicationScoped
@DefaultBean
public static ScriptHost provideScriptHost() {
public static ScriptHost produceScriptHost() {
return ScriptHost.newBuilder().registry(JacksonRegistry.newRegistry()).build();
}
}
29 changes: 7 additions & 22 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.IOException;
import java.net.URI;
import java.util.Map;

import org.openjdk.jmc.common.unit.UnitLookup;
import org.openjdk.jmc.rjmx.ServiceNotAvailableException;
Expand Down Expand Up @@ -64,7 +63,7 @@ public class ActiveRecording extends PanacheEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_id")
private Target target;
public Target target;

@Column(nullable = false)
public String name;
Expand Down Expand Up @@ -100,7 +99,8 @@ public static ActiveRecording from(Target target, LinkedRecordingDescriptor desc
return recording;
}

public static ActiveRecording from(Target target, IRecordingDescriptor descriptor) {
public static ActiveRecording from(
Target target, IRecordingDescriptor descriptor, Metadata metadata) {
ActiveRecording recording = new ActiveRecording();

recording.target = target;
Expand Down Expand Up @@ -128,8 +128,7 @@ public static ActiveRecording from(Target target, IRecordingDescriptor descripto
recording.toDisk = descriptor.getToDisk();
recording.maxSize = descriptor.getMaxSize().in(UnitLookup.BYTE).longValue();
recording.maxAge = descriptor.getMaxAge().in(UnitLookup.MILLISECOND).longValue();
// TODO is there any metadata we can or should attach?
recording.metadata = new Metadata(Map.of());
recording.metadata = new Metadata(metadata);

return recording;
}
Expand All @@ -153,28 +152,13 @@ public static boolean deleteFromTarget(Target target, String recordingName) {
return false; // Recording not found or already deleted.
}

public LinkedRecordingDescriptor toExternalForm() {
return new LinkedRecordingDescriptor(
this.remoteId,
this.state,
this.duration,
this.startTime,
this.continuous,
this.toDisk,
this.maxSize,
this.maxAge,
this.name,
"TODO",
"TODO",
this.metadata);
}

@ApplicationScoped
static class Listener {

@Inject Logger logger;
@Inject EventBus bus;
@Inject TargetConnectionManager connectionManager;
@Inject RecordingHelper recordingHelper;

@PostPersist
public void postPersist(ActiveRecording activeRecording) {
Expand Down Expand Up @@ -234,7 +218,8 @@ private void notify(String category, ActiveRecording recording) {
new Notification(
category,
new RecordingEvent(
recording.target.connectUrl, recording.toExternalForm())));
recording.target.connectUrl,
recordingHelper.toExternalForm(recording))));
}

public record RecordingEvent(URI target, Object recording) {}
Expand Down
Loading
Loading