Skip to content

Commit

Permalink
Configure jfr-datasource/grafana-dashboard in itests (cryostatio#528)
Browse files Browse the repository at this point in the history
* Use pre-configured grafana-dashboard

* Update jfr-datasource version

* Add properties for skipping unit tests and integration tests

* Configure jfr-datasource/grafana-dashboard in itests
  • Loading branch information
andrewazores committed Jun 24, 2021
1 parent 19a75ba commit a4f07c5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 115 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Once the `cryostat-core` local dependency is made available,
`mvn compile` will build the project.

Unit tests can be run with `mvn test`. Integration tests and additional quality
tools can be run with `mvn verify`.
tools can be run with `mvn verify`. `-DskipUTs=true` can be used to skip unit
tests and `-DskipITs=true` can be used to skip integration tests;
`-DskipTests=true` can be used to skip both.

To re-run integration tests without a rebuild, do
`mvn exec:exec@create-pod exec:exec@start-container exec:exec@wait-for-container
Expand Down
62 changes: 61 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<node.version>v12.5.0</node.version>
<yarn.version>v1.22.10</yarn.version>

<skipTests>false</skipTests>
<skipITs>${skipTests}</skipITs>
<skipUTs>${skipTests}</skipUTs>
<cryostat.minimal>false</cryostat.minimal>
<cryostat.imageStream>quay.io/cryostat/cryostat</cryostat.imageStream>
<cryostat.entrypoint>/app/entrypoint.sh</cryostat.entrypoint>
Expand All @@ -30,6 +33,12 @@
<cryostat.listenPort>9090</cryostat.listenPort>
<cryostat.itest.webPort>8181</cryostat.itest.webPort>
<cryostat.itest.podName>cryostat-itests</cryostat.itest.podName>
<cryostat.itest.grafana-dashboard.port>3000</cryostat.itest.grafana-dashboard.port>
<cryostat.itest.grafana-dashboard.imageStream>quay.io/cryostat/cryostat-grafana-dashboard</cryostat.itest.grafana-dashboard.imageStream>
<cryostat.itest.grafana-dashboard.version>1.0.0</cryostat.itest.grafana-dashboard.version>
<cryostat.itest.jfr-datasource.port>8080</cryostat.itest.jfr-datasource.port>
<cryostat.itest.jfr-datasource.imageStream>quay.io/cryostat/jfr-datasource</cryostat.itest.jfr-datasource.imageStream>
<cryostat.itest.jfr-datasource.version>1.0.0</cryostat.itest.jfr-datasource.version>

<org.apache.maven.plugins.compiler.version>3.8.1</org.apache.maven.plugins.compiler.version>
<org.apache.maven.plugins.surefire.version>2.22.2</org.apache.maven.plugins.surefire.version>
Expand Down Expand Up @@ -262,6 +271,50 @@
<argument>${cryostat.rjmxPort}:${cryostat.rjmxPort}</argument>
<argument>--publish</argument>
<argument>${cryostat.itest.webPort}:${cryostat.itest.webPort}</argument>
<argument>--publish</argument>
<argument>${cryostat.itest.jfr-datasource.port}:${cryostat.itest.jfr-datasource.port}</argument>
<argument>--publish</argument>
<argument>${cryostat.itest.grafana-dashboard.port}:${cryostat.itest.grafana-dashboard.port}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>start-jfr-datasource</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${imageBuilder}</executable>
<arguments>
<argument>run</argument>
<argument>--pod=${cryostat.itest.podName}</argument>
<argument>--name=jfr-datasource-itest</argument>
<argument>--detach</argument>
<argument>--rm</argument>
<argument>${cryostat.itest.jfr-datasource.imageStream}:${cryostat.itest.jfr-datasource.version}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>start-grafana-dashboard</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${imageBuilder}</executable>
<arguments>
<argument>run</argument>
<argument>--pod=${cryostat.itest.podName}</argument>
<argument>--name=grafana-itest</argument>
<argument>--env</argument>
<argument>GF_INSTALL_PLUGINS=grafana-simple-json-datasource</argument>
<argument>--env</argument>
<argument>GF_AUTH_ANONYMOUS_ENABLED=true</argument>
<argument>--detach</argument>
<argument>--rm</argument>
<argument>${cryostat.itest.grafana-dashboard.imageStream}:${cryostat.itest.grafana-dashboard.version}</argument>
</arguments>
</configuration>
</execution>
Expand Down Expand Up @@ -304,7 +357,9 @@
<argument>--env</argument>
<argument>CRYOSTAT_TEMPLATE_PATH=/opt/cryostat.d/templates.d</argument>
<argument>--env</argument>
<argument>GRAFANA_DATASOURCE_URL=http://abc</argument>
<argument>GRAFANA_DATASOURCE_URL=http://0.0.0.0:8080</argument>
<argument>--env</argument>
<argument>GRAFANA_DASHBOARD_URL=http://0.0.0.0:3000</argument>
<argument>--detach</argument>
<argument>--rm</argument>
<argument>${cryostat.imageStream}:${cryostat.imageVersion}</argument>
Expand Down Expand Up @@ -363,6 +418,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${org.apache.maven.plugins.surefire.version}</version>
<configuration>
<skipTests>${skipUTs}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -378,6 +436,8 @@
</execution>
</executions>
<configuration>
<skipTests>${skipTests}</skipTests>
<skipITs>${skipITs}</skipITs>
<runOrder>random</runOrder>
<systemPropertyVariables>
<cryostatWebPort>${cryostat.itest.webPort}</cryostatWebPort>
Expand Down
26 changes: 3 additions & 23 deletions smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,7 @@ function runJfrDatasource() {
podman run \
--name jfr-datasource \
--pod cryostat \
--rm -d quay.io/cryostat/jfr-datasource:1.0.0-BETA6
}

function configureGrafanaDatasource() {
while ! curl "http://0.0.0.0:3000/api/health"; do
sleep 5
done
local TEMP="$(mktemp -d)"
pushd "$TEMP"

echo "{" > datasource.json
echo '"name":"jfr-datasource",' >> datasource.json
echo '"type":"grafana-simple-json-datasource",' >> datasource.json
echo '"url":"http://0.0.0.0:8080",' >> datasource.json
echo '"access":"proxy",' >> datasource.json
echo '"basicAuth":false,' >> datasource.json
echo '"isDefault":true' >> datasource.json
echo "}" >> datasource.json

curl -X POST -H "Content-Type: application/json" "http://admin:admin@0.0.0.0:3000/api/datasources" -T - < datasource.json
popd
--rm -d quay.io/cryostat/jfr-datasource:1.0.0
}

function runGrafana() {
Expand All @@ -83,8 +63,8 @@ function runGrafana() {
--pod cryostat \
--env GF_INSTALL_PLUGINS=grafana-simple-json-datasource \
--env GF_AUTH_ANONYMOUS_ENABLED=true \
--rm -d quay.io/cryostat/cryostat-grafana-dashboard:1.0.0-BETA3
configureGrafanaDatasource
--env JFR_DATASOURCE_URL="http://0.0.0.0:8080" \
--rm -d quay.io/cryostat/cryostat-grafana-dashboard:1.0.0
}

function createPod() {
Expand Down
77 changes: 0 additions & 77 deletions src/test/java/itest/GrafanaDatasourceIT.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,29 @@
import io.vertx.ext.web.client.HttpRequest;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class GrafanaDashboardIT extends TestBase {
public class GrafanaSetupIT extends TestBase {

HttpRequest<Buffer> req;

@BeforeEach
void createRequest() {
req = webClient.get("/api/v1/grafana_dashboard_url");
@Test
public void shouldHaveConfiguredDatasource() throws Exception {
HttpRequest<Buffer> req = webClient.get("/api/v1/grafana_datasource_url");
CompletableFuture<Integer> future = new CompletableFuture<>();
req.send(
ar -> {
if (ar.succeeded()) {
future.complete(ar.result().statusCode());
} else {
future.completeExceptionally(ar.cause());
}
});
MatcherAssert.assertThat(
future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), Matchers.equalTo(200));
}

@Test
public void shouldFail() throws Exception {
public void shouldHaveConfiguredDashboard() throws Exception {
HttpRequest<Buffer> req = webClient.get("/api/v1/grafana_dashboard_url");
CompletableFuture<Integer> future = new CompletableFuture<>();
req.send(
ar -> {
Expand All @@ -68,6 +77,6 @@ public void shouldFail() throws Exception {
}
});
MatcherAssert.assertThat(
future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), Matchers.equalTo(500));
future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS), Matchers.equalTo(200));
}
}
8 changes: 4 additions & 4 deletions src/test/java/itest/UploadRecordingIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class UploadRecordingIT extends TestBase {
Expand Down Expand Up @@ -90,9 +91,8 @@ public static void deleteRecording() throws Exception {
deleteRespFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

/* Since no other integration test currently tests upload-recording,
* GRAFANA_DATASOURCE_URL is just set to an invalid URL, so that we can do this test.
*/
@Disabled(
"TODO, this test needs to be updated to actually trigger a file to be uploaded to jfr-datasource/grafana-dashboard now that the integration tests have these additional containers configured")
@Test
public void shouldHandleBadDatasourceUrl() throws Exception {
CompletableFuture<Integer> uploadRespFuture = new CompletableFuture<>();
Expand All @@ -111,6 +111,6 @@ public void shouldHandleBadDatasourceUrl() throws Exception {
uploadRespFuture.complete(result.statusCode());
});
int statusCode = uploadRespFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat(statusCode, Matchers.equalTo(500));
MatcherAssert.assertThat(statusCode, Matchers.equalTo(200));
}
}

0 comments on commit a4f07c5

Please sign in to comment.