Skip to content

Commit 034fce8

Browse files
committed
mp_metrics: switch to Quarkus
1 parent ed22355 commit 034fce8

19 files changed

+882
-73
lines changed

build.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
set -e
44

5-
for dir in client_java mp_metrics; do
6-
pushd $dir
7-
mvn clean package
8-
docker build -t $dir:latest .
9-
popd
10-
done
5+
pushd client_java
6+
mvn clean package
7+
docker build -t client_java:latest .
8+
popd
9+
10+
pushd mp_metrics
11+
./mvnw package -Pnative -Dquarkus.native.container-build=true
12+
docker build -f src/main/docker/Dockerfile.native -t mp_metrics:latest .
13+
popd
1114

1215
pushd micrometer
1316
gradle assemble

mp_metrics/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*

mp_metrics/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings/
5+
bin/
6+
7+
# IntelliJ
8+
.idea
9+
*.ipr
10+
*.iml
11+
*.iws
12+
13+
# NetBeans
14+
nb-configuration.xml
15+
16+
# Visual Studio Code
17+
.vscode
18+
19+
# OSX
20+
.DS_Store
21+
22+
# Vim
23+
*.swp
24+
*.swo
25+
26+
# patch
27+
*.orig
28+
*.rej
29+
30+
# Maven
31+
target/
32+
pom.xml.tag
33+
pom.xml.releaseBackup
34+
pom.xml.versionsBackup
35+
release.properties
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.io.File;
18+
import java.io.FileInputStream;
19+
import java.io.FileOutputStream;
20+
import java.io.IOException;
21+
import java.net.Authenticator;
22+
import java.net.PasswordAuthentication;
23+
import java.net.URL;
24+
import java.nio.channels.Channels;
25+
import java.nio.channels.ReadableByteChannel;
26+
import java.util.Properties;
27+
28+
public class MavenWrapperDownloader {
29+
30+
private static final String WRAPPER_VERSION = "0.5.5";
31+
/**
32+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
33+
*/
34+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
35+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
36+
37+
/**
38+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
39+
* use instead of the default one.
40+
*/
41+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
42+
".mvn/wrapper/maven-wrapper.properties";
43+
44+
/**
45+
* Path where the maven-wrapper.jar will be saved to.
46+
*/
47+
private static final String MAVEN_WRAPPER_JAR_PATH =
48+
".mvn/wrapper/maven-wrapper.jar";
49+
50+
/**
51+
* Name of the property which should be used to override the default download url for the wrapper.
52+
*/
53+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
54+
55+
public static void main(String args[]) {
56+
System.out.println("- Downloader started");
57+
File baseDirectory = new File(args[0]);
58+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
59+
60+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
61+
// wrapperUrl parameter.
62+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
63+
String url = DEFAULT_DOWNLOAD_URL;
64+
if(mavenWrapperPropertyFile.exists()) {
65+
FileInputStream mavenWrapperPropertyFileInputStream = null;
66+
try {
67+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
68+
Properties mavenWrapperProperties = new Properties();
69+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
70+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
71+
} catch (IOException e) {
72+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
73+
} finally {
74+
try {
75+
if(mavenWrapperPropertyFileInputStream != null) {
76+
mavenWrapperPropertyFileInputStream.close();
77+
}
78+
} catch (IOException e) {
79+
// Ignore ...
80+
}
81+
}
82+
}
83+
System.out.println("- Downloading from: " + url);
84+
85+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
86+
if(!outputFile.getParentFile().exists()) {
87+
if(!outputFile.getParentFile().mkdirs()) {
88+
System.out.println(
89+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
90+
}
91+
}
92+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
93+
try {
94+
downloadFileFromURL(url, outputFile);
95+
System.out.println("Done");
96+
System.exit(0);
97+
} catch (Throwable e) {
98+
System.out.println("- Error downloading");
99+
e.printStackTrace();
100+
System.exit(1);
101+
}
102+
}
103+
104+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
106+
String username = System.getenv("MVNW_USERNAME");
107+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
108+
Authenticator.setDefault(new Authenticator() {
109+
@Override
110+
protected PasswordAuthentication getPasswordAuthentication() {
111+
return new PasswordAuthentication(username, password);
112+
}
113+
});
114+
}
115+
URL website = new URL(urlString);
116+
ReadableByteChannel rbc;
117+
rbc = Channels.newChannel(website.openStream());
118+
FileOutputStream fos = new FileOutputStream(destination);
119+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
120+
fos.close();
121+
rbc.close();
122+
}
123+
124+
}
49.5 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

mp_metrics/Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

mp_metrics/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
This example is a very simple application running on Thorntail that exposes a service on `http://localhost:8080`.
1+
This example is a very simple [Quarkus](https://quarkus.io/) application that exposes a service on `http://localhost:8080/hello`.
22

33
It offers 2 endpoints:
44

5-
* `/hello` responding `200 OK` with `Hello from Thorntail!`. The endpoint
5+
* `/hello` responding `200 OK` with `Hello from Quarkus!`. The endpoint
66
* adds a random delay to generate different response times. From time to time,
77
* it will fail with `500 SERVER UNAVAILABLE`.
88
* `/metrics` exposing the MicroProfile metrics with the Prometheus format.
99

10-
## Running it
10+
## Running the application in dev mode
1111

12-
```bash
13-
mvn thorntail:run
12+
You can run your application in dev mode that enables live coding using:
13+
```
14+
./mvnw quarkus:dev
1415
```
1516

17+
## Packaging and running the application
18+
19+
The application is packageable using `./mvnw package`.
20+
It produces the executable `restful-endpoint-1.0.0-SNAPSHOT-runner.jar` file in `/target` directory.
21+
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/lib` directory.
22+
23+
The application is now runnable using `java -jar target/restful-endpoint-1.0.0-SNAPSHOT-runner.jar`.
24+
25+
## Creating a native executable
26+
27+
You can create a native executable using: `./mvnw package -Pnative`.
28+
29+
Or you can use Docker to build the native executable using: `./mvnw package -Pnative -Dquarkus.native.container-build=true`.
30+
31+
You can then execute your binary: `./target/restful-endpoint-1.0.0-SNAPSHOT-runner`
32+
33+
If you want to learn more about building native executables, please consult https://quarkus.io/guides/building-native-image-guide .
34+
35+
## Using it
36+
1637
Visit `http://localhost:8080/hello` a couple of times. Then go to `http://localhost:8080/metrics` to view the metrics.
1738

1839
MicroProfile metrics encompass base, vendor and application metrics. Even

0 commit comments

Comments
 (0)