Skip to content

Commit

Permalink
fix(template): correct return of String-encoded Optional (cryostatio#482
Browse files Browse the repository at this point in the history
)

* build container image in CI, therefore enabling container-only itests

* enable test case in CI

* fix incorrect return of String-encoded Optional

* remove outdated event types

* update TargetConnectionManager event types

* rename and enable match expression events
  • Loading branch information
andrewazores authored May 30, 2024
1 parent f913208 commit 20d0b66
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
- name: Set DOCKER_HOST environment variable
run: echo "DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock" >> "$GITHUB_ENV"
- name: Build application
run: ./mvnw -B -U -Dquarkus.container-image.build=false clean verify
run: ./mvnw -B -U clean verify
continue-on-error: ${{ matrix.java != '17' }}

- name: Add workflow result as comment on PR
Expand Down
36 changes: 7 additions & 29 deletions src/main/docker/include/cryostat.jfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,36 @@
see Window -> Flight Recorder Template Manager.
-->
<configuration version="2.0" label="Cryostat" description="Continuous self-profiling for Cryostat" provider="Cryostat">
<event name="io.cryostat.net.OpenShiftAuthManager.AuthRequest">
<setting name="enabled">
true
</setting>
<setting name="threshold">
0 ms
</setting>
<setting name="stackTrace">
true
</setting>
</event>
<event name="io.cryostat.net.TargetConnectionManager.JMXConnectionOpened">
<event name="io.cryostat.targets.TargetConnectionManager.TargetConnectionOpened">
<setting name="enabled">
true
</setting>
<setting name="threshold">
0 ms
</setting>
</event>
<event name="io.cryostat.net.TargetConnectionManager.JMXConnectionClosed">
<event name="io.cryostat.targets.TargetConnectionManager.TargetConnectionClosed">
<setting name="enabled">
true
</setting>
<setting name="threshold">
0 ms
</setting>
</event>
<event name="io.cyostat.net.web.WebServer.WebServerRequest">
<event name="io.cryostat.expressions.MatchExpressionEvaluator.MatchExpressionApplies">
<setting name="enabled">
true
</setting>
<setting name="threshold">
0 ms
</setting>
<setting name="stackTrace">
true
</setting>
</event>
<event name="io.cyostat.net.web.MessagingServer.WsMessageEmitted">
<setting name="enabled">
true
</setting>
<setting name="threshold">
0 ms
0 ms
</setting>
</event>
<event name="io.cryostat.core.reports.InterruptibleReportGenerator.ReportRuleEvalEvent">
<event name="io.cryostat.expressions.MatchExpressionEvaluator.ScriptCreation">
<setting name="enabled">
true
true
</setting>
<setting name="threshold">
0 ms
0 ms
</setting>
</event>
<event name="jdk.ThreadAllocationStatistics">
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/io/cryostat/events/TargetTemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ public List<Template> getTemplates() throws FlightRecorderException {
@Override
public Optional<String> getXml(String templateName, TemplateType unused)
throws FlightRecorderException {
Optional doc =
connectionManager.executeConnectedTask(
target,
conn ->
conn.getTemplateService()
.getXml(templateName, TemplateType.TARGET));
return doc.isPresent() ? Optional.of(doc.toString()) : Optional.empty();
return connectionManager.executeConnectedTask(
target,
conn -> conn.getTemplateService().getXml(templateName, TemplateType.TARGET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void onMessage(ExpressionEvent event) {
}

Script createScript(String matchExpression) throws ScriptCreateException {
ScriptCreationEvent evt = new ScriptCreationEvent();
ScriptCreation evt = new ScriptCreation();
try {
evt.begin();
return scriptHost
Expand Down Expand Up @@ -113,7 +113,7 @@ void invalidate(String matchExpression) {
}

public boolean applies(MatchExpression matchExpression, Target target) throws ScriptException {
MatchExpressionAppliesEvent evt = new MatchExpressionAppliesEvent(matchExpression);
MatchExpressionApplies evt = new MatchExpressionApplies(matchExpression);
try {
evt.begin();
return load(matchExpression.script, target);
Expand Down Expand Up @@ -147,27 +147,27 @@ public List<Target> getMatchedTargets(MatchExpression matchExpression) {
}
}

@Name("io.cryostat.rules.MatchExpressionEvaluator.MatchExpressionAppliesEvent")
@Name("io.cryostat.rules.MatchExpressionEvaluator.MatchExpressionApplies")
@Label("Match Expression Evaluation")
@Category("Cryostat")
@SuppressFBWarnings(value = {"EI_EXPOSE_REP", "URF_UNREAD_FIELD"})
public static class MatchExpressionAppliesEvent extends Event {
public static class MatchExpressionApplies extends Event {

String matchExpression;

MatchExpressionAppliesEvent(MatchExpression matchExpression) {
MatchExpressionApplies(MatchExpression matchExpression) {
this.matchExpression = matchExpression.script;
}
}

@Name("io.cryostat.rules.MatchExpressionEvaluator.ScriptCreationEvent")
@Name("io.cryostat.rules.MatchExpressionEvaluator.ScriptCreation")
@Label("Match Expression Script Creation")
@Category("Cryostat")
// @SuppressFBWarnings(
// value = "URF_UNREAD_FIELD",
// justification = "The event fields are recorded with JFR instead of accessed
// directly")
public static class ScriptCreationEvent extends Event {}
public static class ScriptCreation extends Event {}

/**
* Restricted view of a {@link io.cryostat.targets.Target} with only particular
Expand Down
14 changes: 3 additions & 11 deletions src/test/java/itest/CryostatTemplateIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,22 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;

@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
@QuarkusIntegrationTest
public class CryostatTemplateIT extends StandardSelfTest {

File file;

@BeforeEach
void setup() throws Exception {
@Test
public void shouldHaveCryostatTemplate() throws Exception {
String url =
String.format(
"/api/v1/targets/%s/templates/Cryostat/type/TARGET",
getSelfReferenceConnectUrlEncoded());
file =
File file =
downloadFile(url, "cryostat", ".jfc")
.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.toFile();
}

@Test
public void shouldHaveCryostatTemplate() throws Exception {
XMLModel model = EventConfiguration.createModel(file);
model.checkErrors();

Expand Down

0 comments on commit 20d0b66

Please sign in to comment.