-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * make protobuf optional Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * plugin management Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * smoke test Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * smoke test Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * smoke test Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * smoke test Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * release automation Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * cache delegate Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * annotations should be provided Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * fix rebase Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * fix rebase Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * checkstyle Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> * add docs Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> --------- Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
- Loading branch information
1 parent
03609eb
commit 66f4dc8
Showing
57 changed files
with
987 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: GraalVM Native Tests | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
native-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: graalvm | ||
cache: 'maven' | ||
- name: Run the Maven verify phase | ||
run: ./scripts/run-native-tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
integration-tests/it-common/src/test/java/io/prometheus/client/it/common/ExporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package io.prometheus.client.it.common; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_3.Metrics; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.zip.GZIPInputStream; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
public abstract class ExporterTest { | ||
private final GenericContainer<?> sampleAppContainer; | ||
private final Volume sampleAppVolume; | ||
protected final String sampleApp; | ||
|
||
public ExporterTest(String sampleApp) throws IOException, URISyntaxException { | ||
this.sampleApp = sampleApp; | ||
this.sampleAppVolume = | ||
Volume.create("it-exporter") | ||
.copy("../../it-" + sampleApp + "/target/" + sampleApp + ".jar"); | ||
this.sampleAppContainer = | ||
new GenericContainer<>("openjdk:17") | ||
.withFileSystemBind(sampleAppVolume.getHostPath(), "/app", BindMode.READ_ONLY) | ||
.withWorkingDirectory("/app") | ||
.withLogConsumer(LogConsumer.withPrefix(sampleApp)) | ||
.withExposedPorts(9400); | ||
} | ||
|
||
// @BeforeEach? | ||
protected void start() { | ||
start("success"); | ||
} | ||
|
||
protected void start(String outcome) { | ||
sampleAppContainer | ||
.withCommand("java", "-jar", "/app/" + sampleApp + ".jar", "9400", outcome) | ||
.start(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() throws IOException { | ||
sampleAppContainer.stop(); | ||
sampleAppVolume.remove(); | ||
} | ||
|
||
public static void assertContentType(String expected, String actual) { | ||
if (!expected.replace(" ", "").equals(actual)) { | ||
assertThat(actual).isEqualTo(expected); | ||
} | ||
} | ||
|
||
protected Response scrape(String method, String queryString, String... requestHeaders) | ||
throws IOException { | ||
return scrape( | ||
method, | ||
new URL( | ||
"http://localhost:" | ||
+ sampleAppContainer.getMappedPort(9400) | ||
+ "/metrics?" | ||
+ queryString), | ||
requestHeaders); | ||
} | ||
|
||
public static Response scrape(String method, URL url, String... requestHeaders) | ||
throws IOException { | ||
long timeoutMillis = TimeUnit.SECONDS.toMillis(5); | ||
HttpURLConnection con = (HttpURLConnection) url.openConnection(); | ||
con.setRequestMethod(method); | ||
for (int i = 0; i < requestHeaders.length; i += 2) { | ||
con.setRequestProperty(requestHeaders[i], requestHeaders[i + 1]); | ||
} | ||
long start = System.currentTimeMillis(); | ||
Exception exception = null; | ||
while (System.currentTimeMillis() - start < timeoutMillis) { | ||
try { | ||
if (con.getResponseCode() == 200) { | ||
return new Response( | ||
con.getResponseCode(), | ||
con.getHeaderFields(), | ||
IOUtils.toByteArray(con.getInputStream())); | ||
} else { | ||
return new Response( | ||
con.getResponseCode(), | ||
con.getHeaderFields(), | ||
IOUtils.toByteArray(con.getErrorStream())); | ||
} | ||
} catch (Exception e) { | ||
exception = e; | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException ignored) { | ||
// ignore | ||
} | ||
} | ||
} | ||
if (exception != null) { | ||
exception.printStackTrace(); | ||
} | ||
fail("timeout while getting metrics from " + url); | ||
return null; // will not happen | ||
} | ||
|
||
public static class Response { | ||
public final int status; | ||
private final Map<String, String> headers; | ||
public final byte[] body; | ||
|
||
private Response(int status, Map<String, List<String>> headers, byte[] body) { | ||
this.status = status; | ||
this.headers = new HashMap<>(headers.size()); | ||
this.body = body; | ||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) { | ||
if (entry.getKey() | ||
!= null) { // HttpUrlConnection uses pseudo key "null" for the status line | ||
this.headers.put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue().get(0)); | ||
} | ||
} | ||
} | ||
|
||
public String getHeader(String name) { | ||
// HTTP headers are case-insensitive | ||
return headers.get(name.toLowerCase(Locale.ROOT)); | ||
} | ||
|
||
public String stringBody() { | ||
return new String(body, UTF_8); | ||
} | ||
|
||
public String gzipBody() throws IOException { | ||
return new String( | ||
IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(body))), UTF_8); | ||
} | ||
|
||
public List<Metrics.MetricFamily> protoBody() throws IOException { | ||
List<Metrics.MetricFamily> metrics = new ArrayList<>(); | ||
InputStream in = new ByteArrayInputStream(body); | ||
while (in.available() > 0) { | ||
metrics.add(Metrics.MetricFamily.parseDelimitedFrom(in)); | ||
} | ||
return metrics; | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
integration-tests/it-exporter/it-exporter-no-protobuf/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>it-exporter</artifactId> | ||
<version>1.3.3</version> | ||
</parent> | ||
|
||
<artifactId>it-exporter-no-protobuf</artifactId> | ||
|
||
<name>Integration Tests - HTTPServer Exporter Sample - no protobuf</name> | ||
<description> | ||
HTTPServer Sample for the Exporter Integration Test without protobuf | ||
</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>prometheus-metrics-exporter-httpserver</artifactId> | ||
<version>${project.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>prometheus-metrics-exposition-formats</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>prometheus-metrics-core</artifactId> | ||
<version>${project.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>prometheus-metrics-exposition-formats</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>exporter-no-protobuf</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>io.prometheus.metrics.it.exporter.httpserver.HTTPServerSample</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.