Skip to content

Commit 6284222

Browse files
committed
Prometheus Metrics 1.0.x - Initial Commit
Signed-off-by: Fabian Stäber <[email protected]>
1 parent 98967b8 commit 6284222

File tree

177 files changed

+30756
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+30756
-409
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- checkout
1717
- restore_cache:
1818
key: maven-dependencies-{{ checksum "pom.xml" }}
19+
- run: cd protobuf-shaded && ../mvnw install && cd ..
1920
- run: ./mvnw clean install
2021
- run: ./mvnw javadoc:jar
2122
- save_cache:

benchmarks/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
<parent>
66
<groupId>io.prometheus</groupId>
7-
<artifactId>parent</artifactId>
8-
<version>0.16.1-SNAPSHOT</version>
7+
<artifactId>client_java</artifactId>
8+
<version>1.0.0-alpha-1-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>benchmarks</artifactId>

examples/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>io.prometheus</groupId>
7+
<artifactId>client_java</artifactId>
8+
<version>1.0.0-alpha-1-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>examples</artifactId>
12+
<packaging>pom</packaging>
13+
14+
<name>Prometheus Metrics Examples</name>
15+
<description>
16+
Example projects for the Prometheus Metrics Library.
17+
</description>
18+
19+
<licenses>
20+
<license>
21+
<name>The Apache Software License, Version 2.0</name>
22+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
23+
<distribution>repo</distribution>
24+
</license>
25+
</licenses>
26+
27+
<developers>
28+
<developer>
29+
<id>fstab</id>
30+
<name>Fabian Stäber</name>
31+
<email>[email protected]</email>
32+
</developer>
33+
</developers>
34+
35+
<modules>
36+
<module>tomcat-servlet-example</module>
37+
</modules>
38+
39+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>io.prometheus</groupId>
8+
<artifactId>examples</artifactId>
9+
<version>1.0.0-alpha-1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>tomcat-servlet-example</artifactId>
13+
14+
<name>Tomcat Servlet Example</name>
15+
<description>
16+
Prometheus Metrics Example using Embedded Tomcat and the Exporter Servlet
17+
</description>
18+
19+
<licenses>
20+
<license>
21+
<name>The Apache Software License, Version 2.0</name>
22+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
23+
<distribution>repo</distribution>
24+
</license>
25+
</licenses>
26+
27+
<developers>
28+
<developer>
29+
<id>fstab</id>
30+
<name>Fabian Stäber</name>
31+
<email>[email protected]</email>
32+
</developer>
33+
</developers>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>io.prometheus</groupId>
38+
<artifactId>prometheus-metrics-core</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.prometheus</groupId>
43+
<artifactId>prometheus-metrics-exporter-servlet-jakarta</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.tomcat.embed</groupId>
48+
<artifactId>tomcat-embed-core</artifactId>
49+
<version>10.1.11</version>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-shade-plugin</artifactId>
58+
<executions>
59+
<execution>
60+
<phase>package</phase>
61+
<goals>
62+
<goal>shade</goal>
63+
</goals>
64+
<configuration>
65+
<transformers>
66+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
67+
<mainClass>io.prometheus.metrics.examples.tomcat_servlet.Main</mainClass>
68+
</transformer>
69+
</transformers>
70+
</configuration>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.prometheus.metrics.examples.tomcat_servlet;
2+
3+
import io.prometheus.metrics.core.metrics.Counter;
4+
import io.prometheus.metrics.core.metrics.Histogram;
5+
import io.prometheus.metrics.model.snapshots.Unit;
6+
import jakarta.servlet.http.HttpServlet;
7+
import jakarta.servlet.http.HttpServletRequest;
8+
import jakarta.servlet.http.HttpServletResponse;
9+
10+
import java.io.IOException;
11+
import java.util.Random;
12+
13+
import static io.prometheus.metrics.model.snapshots.Unit.nanosToSeconds;
14+
15+
public class HelloWorldServlet extends HttpServlet {
16+
17+
private final Random random = new Random(0);
18+
19+
private final Counter counter = Counter.newBuilder()
20+
.withName("requests_total")
21+
.withHelp("total number of requests")
22+
.withLabelNames("http_status")
23+
.register();
24+
25+
private final Histogram histogram = Histogram.newBuilder()
26+
.withName("request_duration_seconds")
27+
.withHelp("request duration in seconds")
28+
.withUnit(Unit.SECONDS)
29+
.withLabelNames("http_status")
30+
.register();
31+
32+
@Override
33+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
34+
long start = System.nanoTime();
35+
try {
36+
Thread.sleep((long) (Math.abs((random.nextGaussian() + 1.0) * 100.0)));
37+
resp.setStatus(200);
38+
resp.setContentType("text/plain");
39+
resp.getWriter().println("Hello, World!");
40+
} catch (InterruptedException e) {
41+
throw new RuntimeException(e);
42+
} finally {
43+
counter.withLabelValues("200").inc();
44+
histogram.withLabelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
45+
}
46+
}
47+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.prometheus.metrics.examples.tomcat_servlet;
2+
3+
import io.prometheus.metrics.config.PrometheusProperties;
4+
import io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet;
5+
import io.prometheus.metrics.model.registry.PrometheusRegistry;
6+
import org.apache.catalina.Context;
7+
import org.apache.catalina.LifecycleException;
8+
import org.apache.catalina.startup.Tomcat;
9+
10+
import java.io.File;
11+
12+
/**
13+
* Simple example using embedded Tomcat an the {@link PrometheusMetricsServlet}.
14+
*/
15+
public class Main {
16+
17+
public static void main(String[] args) throws LifecycleException {
18+
19+
Tomcat tomcat = new Tomcat();
20+
tomcat.setPort(8080);
21+
22+
Context ctx = tomcat.addContext("", new File(".").getAbsolutePath());
23+
24+
Tomcat.addServlet(ctx, "hello", new HelloWorldServlet());
25+
ctx.addServletMappingDecoded("/*", "hello");
26+
27+
Tomcat.addServlet(ctx, "metrics", new PrometheusMetricsServlet());
28+
ctx.addServletMappingDecoded("/metrics", "metrics");
29+
30+
tomcat.getConnector();
31+
tomcat.start();
32+
tomcat.getServer().await();
33+
}
34+
}

integration_tests/it_common/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.prometheus</groupId>
77
<artifactId>integration_tests</artifactId>
8-
<version>0.16.1-SNAPSHOT</version>
8+
<version>1.0.0-alpha-1-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>it_common</artifactId>
@@ -32,14 +32,6 @@
3232
</testResource>
3333
</testResources>
3434
<plugins>
35-
<plugin>
36-
<groupId>org.apache.maven.plugins</groupId>
37-
<artifactId>maven-compiler-plugin</artifactId>
38-
<configuration>
39-
<source>1.8</source>
40-
<target>1.8</target>
41-
</configuration>
42-
</plugin>
4335
<plugin>
4436
<groupId>org.apache.maven.plugins</groupId>
4537
<artifactId>maven-jar-plugin</artifactId>

integration_tests/it_exemplars_otel_agent/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.prometheus</groupId>
77
<artifactId>integration_tests</artifactId>
8-
<version>0.16.1-SNAPSHOT</version>
8+
<version>1.0.0-alpha-1-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>it_exemplars_otel_agent</artifactId>
@@ -85,14 +85,6 @@
8585
</execution>
8686
</executions>
8787
</plugin>
88-
<plugin>
89-
<groupId>org.apache.maven.plugins</groupId>
90-
<artifactId>maven-compiler-plugin</artifactId>
91-
<configuration>
92-
<source>1.8</source>
93-
<target>1.8</target>
94-
</configuration>
95-
</plugin>
9688
<plugin>
9789
<groupId>org.apache.maven.plugins</groupId>
9890
<artifactId>maven-failsafe-plugin</artifactId>

integration_tests/it_exemplars_otel_sdk/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.prometheus</groupId>
77
<artifactId>integration_tests</artifactId>
8-
<version>0.16.1-SNAPSHOT</version>
8+
<version>1.0.0-alpha-1-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>it_exemplars_otel_sdk</artifactId>
@@ -63,14 +63,6 @@
6363
<build>
6464
<finalName>example-open-telemetry-app</finalName>
6565
<plugins>
66-
<plugin>
67-
<groupId>org.apache.maven.plugins</groupId>
68-
<artifactId>maven-compiler-plugin</artifactId>
69-
<configuration>
70-
<source>1.8</source>
71-
<target>1.8</target>
72-
</configuration>
73-
</plugin>
7466
<plugin>
7567
<groupId>org.apache.maven.plugins</groupId>
7668
<artifactId>maven-failsafe-plugin</artifactId>

integration_tests/it_exemplars_otel_sdk/src/test/java/io/prometheus/client/it/exemplars_otel/ExemplarsOpenTelemetrySdkIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/**
1818
* Test if traces from the OpenTelemetry SDK are picked up as Exemplars.
19-
* <p/>
19+
* <p>
2020
* In addition, we make sure that missing OpenTelemetry dependencies do not cause client_java to crash the application.
2121
**/
2222
public class ExemplarsOpenTelemetrySdkIT {
@@ -65,7 +65,7 @@ public void testGoodCase() throws IOException {
6565
/**
6666
* The dependency simpleclient_tracer_otel_agent is for getting the trace context from the OpenTelemetry Java agent.
6767
* As we are getting the trace context from the OpenTelemetry SDK and not from the agent, Exemplars should work.
68-
* <p/>
68+
* <p>
6969
* We test this because if a user excludes simpleclient_tracer_otel_agent from the transitive dependencies for some reason
7070
* we don't want client_java to break.
7171
*/
@@ -78,7 +78,7 @@ public void testOtelAgentMissing() throws IOException, URISyntaxException {
7878
/**
7979
* The dependency simpleclient_tracer_otel is for getting the trace context from the OpenTelemetry SDK.
8080
* If this dependency is missing, Exemplars will be missing, but metrics should still work.
81-
* <p/>
81+
* <p>
8282
* We test this because users may exclude simpleclient_tracer_otel as a way to disable OpenTelemetry Exemplars.
8383
*/
8484
@Test

0 commit comments

Comments
 (0)