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

test(itest): enable jfr-datasource recording upload test #140

Merged
merged 32 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4d19672
test(health): add jfr-datasource + grafana resources to HealthIT
andrewazores Nov 3, 2023
e0315b4
fix(test): move datasource/dashboard configs into prod profile
andrewazores Nov 3, 2023
f086bfd
fix typo
andrewazores Nov 3, 2023
1526934
test(health): HealthIT checks for datasource/dashboard
andrewazores Nov 3, 2023
860ab8c
correct custom targets API paths
andrewazores Nov 3, 2023
a4d9802
fix logger variable interpolations
andrewazores Nov 3, 2023
16c685e
remove JDP requirement in StandardSelfTest, add automatic attempt to …
andrewazores Nov 3, 2023
1284f05
migrate UploadRecordingIT to a Quarkus "unit" test
andrewazores Nov 3, 2023
847a3c0
use encoded self URL
andrewazores Nov 3, 2023
0240499
add auth to requests
andrewazores Nov 3, 2023
60eec5b
follow redirects
andrewazores Nov 3, 2023
9c307f1
extract selftest alias, search for that alias when looking up own con…
andrewazores Nov 3, 2023
27586ff
tmp redirect handler
andrewazores Nov 3, 2023
7cbe05e
temporarily disabled
andrewazores Nov 6, 2023
3fc52fd
fixup! temporarily disabled
andrewazores Nov 6, 2023
857d419
increase timeout
andrewazores Nov 6, 2023
78a873a
replace ForkJoinPool.commonPool() with Executors.newCachedThreadPool(…
andrewazores Nov 6, 2023
8622cba
must wait for self-discovery before trying to get self-referential URL
andrewazores Nov 6, 2023
99489bc
increase timeouts
andrewazores Nov 6, 2023
566aecd
extract utility
andrewazores Nov 6, 2023
e444f71
log message fixup
andrewazores Nov 6, 2023
ae0f94f
clean up self custom target after run
andrewazores Nov 6, 2023
4eb77dc
more logging for troubleshooting
andrewazores Nov 6, 2023
bbb87cb
fix missing path segment in custom target creation location header
andrewazores Nov 6, 2023
37fbd38
don't log response bodies
andrewazores Nov 6, 2023
37e22ce
extract constant
andrewazores Nov 6, 2023
d3f0a1d
fixup! don't log response bodies
andrewazores Nov 6, 2023
385bd3b
cleanup
andrewazores Nov 6, 2023
fa47196
correct behaviour in waiting for self custom target to be defined
andrewazores Nov 7, 2023
3a4886e
fixup
andrewazores Nov 7, 2023
95c97e4
remove broken redirect handling
andrewazores Nov 7, 2023
1e49322
remove unnecessary properties
andrewazores Nov 7, 2023
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
10 changes: 5 additions & 5 deletions src/main/java/io/cryostat/discovery/CustomDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void onStart(@Observes StartupEvent evt) {

@Transactional(rollbackOn = {JvmIdException.class})
@POST
@Path("v2/targets")
@Path("/api/v2/targets")
@Consumes("application/json")
@RolesAllowed("write")
public Response create(Target target, @RestQuery boolean dryrun) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public Response create(Target target, @RestQuery boolean dryrun) {
node.persist();
realm.persist();

return Response.created(URI.create("v3/targets/" + target.id)).build();
return Response.created(URI.create("/api/v3/targets/" + target.id)).build();
} catch (Exception e) {
if (ExceptionUtils.indexOfType(e, ConstraintViolationException.class) >= 0) {
logger.warn("Invalid target definition", e);
Expand All @@ -127,7 +127,7 @@ public Response create(Target target, @RestQuery boolean dryrun) {

@Transactional
@POST
@Path("v2/targets")
@Path("/api/v2/targets")
@Consumes("multipart/form-data")
@RolesAllowed("write")
public Response create(
Expand All @@ -141,7 +141,7 @@ public Response create(

@Transactional
@DELETE
@Path("v2/targets/{connectUrl}")
@Path("/api/v2/targets/{connectUrl}")
@RolesAllowed("write")
public Response delete(@RestPath URI connectUrl) throws URISyntaxException {
Target target = Target.getTargetByConnectUrl(connectUrl);
Expand All @@ -152,7 +152,7 @@ public Response delete(@RestPath URI connectUrl) throws URISyntaxException {

@Transactional
@DELETE
@Path("v3/targets/{id}")
@Path("/api/v3/targets/{id}")
@RolesAllowed("write")
public Response delete(@RestPath long id) throws URISyntaxException {
Target target = Target.find("id", id).singleResult();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ public void deleteArchivedRecording(@RestPath String encodedJvmId, @RestPath Str
.map(c -> c.toString())
.orElseGet(() -> metadata.labels.computeIfAbsent("connectUrl", k -> jvmId));
logger.infov(
"Archived recording from connectUrl {1} has metadata: {1}", connectUrl, metadata);
"Archived recording from connectUrl {0} has metadata: {1}", connectUrl, metadata);
logger.infov(
"Sending S3 deletion request for {0} {1}",
archiveBucket, recordingHelper.archivedRecordingKey(jvmId, filename));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/cryostat/rules/RuleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ private void scheduleArchival(Rule rule, Target target, ActiveRecording recordin
quartz.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
logger.infov(
"Failed to schedule archival job for rule {} in target {}" + rule.name,
target.alias);
"Failed to schedule archival job for rule {0} in target {1}",
rule.name, target.alias);
logger.error(e);
}
jobs.add(jobDetail.getKey());
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ cryostat.discovery.podman.enabled=true
cryostat.discovery.docker.enabled=true
cryostat.auth.disabled=true

grafana-dashboard.url=http://grafana:3000
grafana-datasource.url=http://jfr-datasource:8080

quarkus.test.env.JAVA_OPTS_APPEND=-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dcom.sun.management.jmxremote.autodiscovery=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9091 -Dcom.sun.management.jmxremote.rmi.port=9091 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false

quarkus.datasource.devservices.enabled=true
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/cryostat/resources/GrafanaResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class GrafanaResource
private static Map<String, String> envMap =
Map.of(
"GF_INSTALL_PLUGINS", "grafana-simple-json-datasource",
"GF_AUTH_ANONYMOUS_ENABLED", "tru",
"GF_AUTH_ANONYMOUS_ENABLED", "true",
"JFR_DATASOURCE_URL", "http://jfr-datasource:8080");

private Optional<String> containerNetworkId;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/itest/CryostatTemplateIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@QuarkusIntegrationTest
public class CryostatTemplateIT extends StandardSelfTest {

static File file;
File file;

@BeforeAll
static void setup() throws Exception {
@BeforeEach
void setup() throws Exception {
String url =
String.format(
"/api/v1/targets/%s/templates/Cryostat/type/TARGET",
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/itest/CustomTargetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -51,7 +51,7 @@
@TestMethodOrder(OrderAnnotation.class)
public class CustomTargetsIT extends StandardSelfTest {

private final ExecutorService worker = ForkJoinPool.commonPool();
private final ExecutorService worker = Executors.newCachedThreadPool();
static final Map<String, String> NULL_RESULT = new HashMap<>();
private String itestJvmId;
private static StoredCredential storedCredential;
Expand Down
47 changes: 39 additions & 8 deletions src/test/java/itest/HealthIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import io.cryostat.resources.GrafanaResource;
import io.cryostat.resources.JFRDatasourceResource;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
Expand All @@ -27,21 +31,20 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

@QuarkusIntegrationTest
@QuarkusTestResource(GrafanaResource.class)
@QuarkusTestResource(JFRDatasourceResource.class)
public class HealthIT extends StandardSelfTest {

HttpRequest<Buffer> req;
JsonObject response;

@BeforeEach
void createRequest() {
req = webClient.get("/health");
}

@Test
void shouldIncludeApplicationVersion() throws Exception {
void createRequest() throws Exception {
CompletableFuture<JsonObject> future = new CompletableFuture<>();
HttpRequest<Buffer> req = webClient.get("/health");
req.send(
ar -> {
if (ar.failed()) {
Expand All @@ -50,12 +53,40 @@ void shouldIncludeApplicationVersion() throws Exception {
}
future.complete(ar.result().bodyAsJsonObject());
});
JsonObject response = future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
response = future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

@Test
void shouldIncludeApplicationVersion() {
Assertions.assertTrue(response.containsKey("cryostatVersion"));
MatcherAssert.assertThat(
response.getString("cryostatVersion"), Matchers.not(Matchers.emptyOrNullString()));
MatcherAssert.assertThat(
response.getString("cryostatVersion"), Matchers.not(Matchers.equalTo("unknown")));
MatcherAssert.assertThat(
response.getString("cryostatVersion"),
Matchers.matchesRegex("^v[\\d]\\.[\\d]\\.[\\d](?:-SNAPSHOT)?"));
}

@Disabled("TODO")
@Test
void shouldHaveAvailableDatasource() {
Assertions.assertTrue(response.containsKey("datasourceConfigured"));
MatcherAssert.assertThat(
response.getString("datasourceConfigured"), Matchers.equalTo("true"));
Assertions.assertTrue(response.containsKey("datasourceAvailable"));
MatcherAssert.assertThat(
response.getString("datasourceAvailable"), Matchers.equalTo("true"));
}

@Disabled("TODO")
@Test
void shouldHaveAvailableDashboard() {
Assertions.assertTrue(response.containsKey("dashboardConfigured"));
MatcherAssert.assertThat(
response.getString("dashboardConfigured"), Matchers.equalTo("true"));
Assertions.assertTrue(response.containsKey("dashboardAvailable"));
MatcherAssert.assertThat(
response.getString("dashboardAvailable"), Matchers.equalTo("true"));
}
}
23 changes: 15 additions & 8 deletions src/test/java/itest/TargetEventsGetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@
import itest.bases.StandardSelfTest;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@QuarkusIntegrationTest
public class TargetEventsGetIT extends StandardSelfTest {

static final String EVENT_REQ_URL =
String.format("/api/v1/targets/%s/events", getSelfReferenceConnectUrlEncoded());
static final String SEARCH_REQ_URL =
String.format("/api/v2/targets/%s/events", getSelfReferenceConnectUrlEncoded());
String eventReqUrl;
String searchReqUrl;

@BeforeEach
void setup() {
eventReqUrl =
String.format("/api/v1/targets/%s/events", getSelfReferenceConnectUrlEncoded());
searchReqUrl =
String.format("/api/v2/targets/%s/events", getSelfReferenceConnectUrlEncoded());
}

@Test
public void testGetTargetEventsReturnsListOfEvents() throws Exception {
CompletableFuture<HttpResponse<Buffer>> getResponse = new CompletableFuture<>();
webClient
.get(EVENT_REQ_URL)
.get(eventReqUrl)
.basicAuthentication("user", "pass")
.send(
ar -> {
Expand All @@ -67,7 +74,7 @@ public void testGetTargetEventsReturnsListOfEvents() throws Exception {
public void testGetTargetEventsV2WithNoQueryReturnsListOfEvents() throws Exception {
CompletableFuture<HttpResponse<Buffer>> getResponse = new CompletableFuture<>();
webClient
.get(SEARCH_REQ_URL)
.get(searchReqUrl)
.basicAuthentication("user", "pass")
.send(
ar -> {
Expand All @@ -92,7 +99,7 @@ public void testGetTargetEventsV2WithNoQueryReturnsListOfEvents() throws Excepti
public void testGetTargetEventsV2WithQueryReturnsRequestedEvents() throws Exception {
CompletableFuture<HttpResponse<Buffer>> getResponse = new CompletableFuture<>();
webClient
.get(String.format("%s?q=TargetConnectionOpened", SEARCH_REQ_URL))
.get(String.format("%s?q=TargetConnectionOpened", searchReqUrl))
.basicAuthentication("user", "pass")
.send(
ar -> {
Expand Down Expand Up @@ -155,7 +162,7 @@ public void testGetTargetEventsV2WithQueryReturnsRequestedEvents() throws Except
public void testGetTargetEventsV2WithQueryReturnsEmptyListWhenNoEventsMatch() throws Exception {
CompletableFuture<HttpResponse<Buffer>> getResponse = new CompletableFuture<>();
webClient
.get(String.format("%s?q=thisEventDoesNotExist", SEARCH_REQ_URL))
.get(String.format("%s?q=thisEventDoesNotExist", searchReqUrl))
.basicAuthentication("user", "pass")
.send(
ar -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import io.cryostat.resources.GrafanaResource;
import io.cryostat.resources.JFRDatasourceResource;
import io.cryostat.util.HttpMimeType;

import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.json.JsonArray;
Expand All @@ -39,9 +42,11 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

@QuarkusIntegrationTest
@Disabled("TODO")
public class UploadRecordingIT extends StandardSelfTest {
@QuarkusTest
@QuarkusTestResource(GrafanaResource.class)
andrewazores marked this conversation as resolved.
Show resolved Hide resolved
@QuarkusTestResource(JFRDatasourceResource.class)
public class UploadRecordingTest extends StandardSelfTest {

// TODO this should be a constant somewhere in the server sources
public static final String DATASOURCE_FILENAME = "cryostat-analysis.jfr";
Expand All @@ -56,7 +61,12 @@ public static void createRecording() throws Exception {
form.add("duration", String.valueOf(RECORDING_DURATION_SECONDS));
form.add("events", "template=ALL");
webClient
.post(String.format("/api/v1/targets/%s/recordings", getSelfReferenceConnectUrl()))
.post(
String.format(
"/api/v1/targets/%s/recordings",
getSelfReferenceConnectUrlEncoded()))
.basicAuthentication("user", "pass")
.followRedirects(true)
.sendForm(
form,
ar -> {
Expand All @@ -79,7 +89,9 @@ public static void deleteRecording() throws Exception {
.delete(
String.format(
"/api/v1/targets/%s/recordings/%s",
getSelfReferenceConnectUrl(), RECORDING_NAME))
getSelfReferenceConnectUrlEncoded(), RECORDING_NAME))
.basicAuthentication("user", "pass")
.followRedirects(true)
.send(
ar -> {
if (assertRequestStatus(ar, deleteRespFuture)) {
Expand All @@ -103,7 +115,9 @@ public void shouldLoadRecordingToDatasource() throws Exception {
.post(
String.format(
"/api/v1/targets/%s/recordings/%s/upload",
getSelfReferenceConnectUrl(), RECORDING_NAME))
getSelfReferenceConnectUrlEncoded(), RECORDING_NAME))
.basicAuthentication("user", "pass")
.followRedirects(true)
.send(
ar -> {
if (assertRequestStatus(ar, uploadRespFuture)) {
Expand Down
Loading
Loading