Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Aug 25, 2023
1 parent bb8f767 commit cd9cf6e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class InProcessReportsService implements ReportsService {
public Uni<Map<String, RuleEvaluation>> reportFor(
ActiveRecording recording, Predicate<IRule> predicate) {
try {
logger.infov(
logger.tracev(
"inprocess reportFor active recording {0} {1}",
recording.target.jvmId, recording.remoteId);
return Uni.createFrom()
Expand All @@ -69,7 +69,7 @@ public Uni<Map<String, RuleEvaluation>> reportFor(
@Override
public Uni<Map<String, RuleEvaluation>> reportFor(
String jvmId, String filename, Predicate<IRule> predicate) {
logger.infov("inprocess reportFor archived recording {0} {1}", jvmId, filename);
logger.tracev("inprocess reportFor archived recording {0} {1}", jvmId, filename);
return Uni.createFrom()
.future(
reportGenerator.generateEvalMapInterruptibly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ class MemoryCachingReportsService implements ReportsService {
@Override
public Uni<Map<String, RuleEvaluation>> reportFor(
ActiveRecording recording, Predicate<IRule> predicate) {
logger.infov("reportFor {0}", key(recording));
logger.tracev("reportFor {0}", key(recording));
return activeCache.getAsync(
key(recording),
key -> {
logger.infov("reportFor {0} cache miss", key(recording));
logger.tracev("reportFor {0} cache miss", key(recording));
return delegate.reportFor(recording);
});
}

@Override
public Uni<Map<String, RuleEvaluation>> reportFor(
String jvmId, String filename, Predicate<IRule> predicate) {
logger.infov("reportFor {0}", key(jvmId, filename));
logger.tracev("reportFor {0}", key(jvmId, filename));
return archivedCache.getAsync(
key(jvmId, filename),
key -> {
logger.infov("reportFor {0} cache miss", key(jvmId, filename));
logger.tracev("reportFor {0} cache miss", key(jvmId, filename));
return delegate.reportFor(jvmId, filename);
});
}
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/io/cryostat/reports/Producers.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,22 @@
*/
package io.cryostat.reports;

import java.io.IOException;
import java.net.URI;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ForkJoinPool;

import io.cryostat.core.reports.InterruptibleReportGenerator;
import io.cryostat.recordings.RecordingHelper;
import io.cryostat.reports.ReportsService.RuleEvaluation;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.quarkus.arc.DefaultBean;
import io.quarkus.cache.Cache;
import io.quarkus.cache.CacheManager;
import io.quarkus.cache.CacheName;
import io.quarkus.jackson.ObjectMapperCustomizer;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Singleton;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

public class Producers {

Expand Down Expand Up @@ -80,30 +69,4 @@ public static ReportsService produceReportsService(
}
return svc;
}

@Singleton
public static class ObjectMapperCustomization implements ObjectMapperCustomizer {
@Override
public void customize(ObjectMapper mapper) {
var module = new SimpleModule();
module.addDeserializer(RuleEvaluation.class, new RuleEvaluationDeserializer());
mapper.registerModule(module);
}
}

static class RuleEvaluationDeserializer extends JsonDeserializer<RuleEvaluation> {
static final Logger logger = Logger.getLogger(RuleEvaluationDeserializer.class);

@Override
public RuleEvaluation deserialize(JsonParser p, DeserializationContext ctx)
throws IOException, JacksonException {
JsonNode node = p.readValueAsTree();
logger.info(node.toString());
var score = node.get("score").asDouble(-1);
var name = node.get("name").asText();
var topic = node.get("topic").asText();
var description = node.get("description").asText();
return new RuleEvaluation(score, name, topic, description);
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/io/cryostat/reports/ReportsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@
*/
package io.cryostat.reports;

import java.io.IOException;
import java.util.Map;
import java.util.function.Predicate;

import org.openjdk.jmc.flightrecorder.rules.IRule;

import io.cryostat.recordings.ActiveRecording;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.quarkus.jackson.ObjectMapperCustomizer;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Singleton;

public interface ReportsService {
Uni<Map<String, RuleEvaluation>> reportFor(
Expand Down Expand Up @@ -51,4 +61,27 @@ public static RuleEvaluation from(
evaluation.getDescription());
}
}

@Singleton
public static class ObjectMapperCustomization implements ObjectMapperCustomizer {
@Override
public void customize(ObjectMapper mapper) {
var module = new SimpleModule();
module.addDeserializer(RuleEvaluation.class, new RuleEvaluationDeserializer());
mapper.registerModule(module);
}
}

static class RuleEvaluationDeserializer extends JsonDeserializer<RuleEvaluation> {
@Override
public RuleEvaluation deserialize(JsonParser p, DeserializationContext ctx)
throws IOException, JacksonException {
JsonNode node = p.readValueAsTree();
var score = node.get("score").asDouble(-1);
var name = node.get("name").asText();
var topic = node.get("topic").asText();
var description = node.get("description").asText();
return new RuleEvaluation(score, name, topic, description);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/cryostat/reports/SidecarReportsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SidecarReportsService implements ReportsService {
@Override
public Uni<Map<String, RuleEvaluation>> reportFor(
ActiveRecording recording, Predicate<IRule> predicate) {
logger.infov(
logger.tracev(
"sidecar reportFor active recording {0} {1}",
recording.target.jvmId, recording.remoteId);
var cf = new CompletableFuture<Map<String, RuleEvaluation>>();
Expand All @@ -68,7 +68,7 @@ public Uni<Map<String, RuleEvaluation>> reportFor(
@Override
public Uni<Map<String, RuleEvaluation>> reportFor(
String jvmId, String filename, Predicate<IRule> predicate) {
logger.infov("sidecar reportFor archived recording {0} {1}", jvmId, filename);
logger.tracev("sidecar reportFor archived recording {0} {1}", jvmId, filename);
var cf = new CompletableFuture<Map<String, RuleEvaluation>>();
try {
fireRequest(cf, helper.getArchivedRecordingStream(jvmId, filename));
Expand Down

0 comments on commit cd9cf6e

Please sign in to comment.