Skip to content

Commit 9dc53c9

Browse files
committed
add option to skip the shaded protobuf libraries
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 25fe4d7 commit 9dc53c9

File tree

5 files changed

+163
-55
lines changed

5 files changed

+163
-55
lines changed

docs/content/exporters/formats.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,50 @@ You can exclude the protobuf exposition format by including the
3232
For example, in Maven:
3333

3434
```xml
35-
<dependency>
36-
<groupId>io.prometheus</groupId>
37-
<artifactId>prometheus-metrics-exporter-httpserver</artifactId>
38-
<exclusions>
39-
<exclusion>
40-
<groupId>io.prometheus</groupId>
41-
<artifactId>prometheus-metrics-exposition-formats</artifactId>
42-
</exclusion>
43-
</exclusions>
44-
</dependency>
35+
<dependencies>
36+
<dependency>
37+
<groupId>io.prometheus</groupId>
38+
<artifactId>prometheus-metrics-exporter-httpserver</artifactId>
39+
<exclusions>
40+
<exclusion>
41+
<groupId>io.prometheus</groupId>
42+
<artifactId>prometheus-metrics-exposition-formats</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.prometheus</groupId>
48+
<artifactId>prometheus-metrics-exposition-textformats</artifactId>
49+
</dependency>
50+
</dependencies>
4551
```
52+
53+
## Exclude the shaded protobuf classes
54+
55+
You can exclude the shaded protobuf classes including the
56+
`prometheus-metrics-exposition-formats-no-protobuf` module and excluding the
57+
`prometheus-metrics-exposition-formats` module in your build file.
58+
59+
For example, in Maven:
60+
61+
```xml
62+
<dependencies>
63+
<dependency>
64+
<groupId>io.prometheus</groupId>
65+
<artifactId>prometheus-metrics-exporter-httpserver</artifactId>
66+
<exclusions>
67+
<exclusion>
68+
<groupId>io.prometheus</groupId>
69+
<artifactId>prometheus-metrics-exposition-formats</artifactId>
70+
</exclusion>
71+
</exclusions>
72+
</dependency>
73+
<dependency>
74+
<groupId>io.prometheus</groupId>
75+
<artifactId>prometheus-metrics-exposition-formats-no-protobuf</artifactId>
76+
</dependency>
77+
</dependencies>
78+
```
79+
80+
81+
todo how to exclude shaded protobuf classes

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<properties>
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
<automatic.module.name>--module-name-need-to-be-overriden--</automatic.module.name>
21+
<protobuf-java.version>4.29.3</protobuf-java.version>
2122
<guava.version>33.4.0-jre</guava.version>
2223
<junit-jupiter.version>5.12.0</junit-jupiter.version>
2324
<otel.instrumentation.version>2.13.2-alpha</otel.instrumentation.version>
@@ -68,6 +69,7 @@
6869
<module>prometheus-metrics-model</module>
6970
<module>prometheus-metrics-tracer</module>
7071
<module>prometheus-metrics-exposition-formats</module>
72+
<module>prometheus-metrics-exposition-formats-shaded</module>
7173
<module>prometheus-metrics-exposition-textformats</module>
7274
<module>prometheus-metrics-exporter-common</module>
7375
<module>prometheus-metrics-exporter-servlet-jakarta</module>

prometheus-metrics-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<artifactId>prometheus-metrics-exporter-servlet-javax</artifactId>
6363
<version>${project.version}</version>
6464
</dependency>
65+
<dependency>
66+
<groupId>io.prometheus</groupId>
67+
<artifactId>prometheus-metrics-exposition-formats-no-protobuf</artifactId>
68+
<version>${project.version}</version>
69+
</dependency>
6570
<dependency>
6671
<groupId>io.prometheus</groupId>
6772
<artifactId>prometheus-metrics-exposition-formats</artifactId>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.prometheus</groupId>
9+
<artifactId>client_java</artifactId>
10+
<version>10.0.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>prometheus-metrics-exposition-formats</artifactId>
14+
<packaging>bundle</packaging>
15+
16+
<name>Prometheus Metrics Exposition Formats</name>
17+
<description>
18+
Prometheus exposition formats.
19+
</description>
20+
21+
<properties>
22+
<automatic.module.name>io.prometheus.metrics.expositionformats</automatic.module.name>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>io.prometheus</groupId>
28+
<artifactId>prometheus-metrics-exposition-formats-no-protobuf</artifactId>
29+
<version>${project.version}</version>
30+
<exclusions>
31+
<exclusion>
32+
<groupId>com.google.protobuf</groupId>
33+
<artifactId>protobuf-java</artifactId>
34+
</exclusion>
35+
</exclusions>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.google.protobuf</groupId>
39+
<artifactId>protobuf-java</artifactId>
40+
<version>${protobuf-java.version}</version>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.codehaus.mojo</groupId>
48+
<artifactId>build-helper-maven-plugin</artifactId>
49+
<executions>
50+
<execution>
51+
<id>regex-property</id>
52+
<goals>
53+
<goal>regex-property</goal>
54+
</goals>
55+
<configuration>
56+
<name>protobuf-java.string-version</name>
57+
<value>${protobuf-java.version}</value>
58+
<regex>\.</regex>
59+
<replacement>_</replacement>
60+
<failIfNoMatch>true</failIfNoMatch>
61+
</configuration>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-shade-plugin</artifactId>
68+
<executions>
69+
<execution>
70+
<phase>package</phase>
71+
<goals>
72+
<goal>shade</goal>
73+
</goals>
74+
<configuration>
75+
<shadeSourcesContent>true</shadeSourcesContent>
76+
<createSourcesJar>true</createSourcesJar>
77+
<artifactSet>
78+
<includes>
79+
<include>com.google.protobuf:protobuf-java</include>
80+
</includes>
81+
</artifactSet>
82+
<relocations>
83+
<relocation>
84+
<pattern>com.google.protobuf</pattern>
85+
<shadedPattern>
86+
io.prometheus.metrics.shaded.com_google_protobuf_${protobuf-java.string-version}
87+
</shadedPattern>
88+
</relocation>
89+
</relocations>
90+
<filters>
91+
<filter>
92+
<artifact>com.google.protobuf:protobuf-java</artifact>
93+
<excludes>
94+
<exclude>META-INF/maven/com.google.protobuf/**</exclude>
95+
<exclude>**/*.proto</exclude>
96+
<exclude>META-INF/MANIFEST.MF</exclude>
97+
</excludes>
98+
</filter>
99+
</filters>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
</project>

prometheus-metrics-exposition-formats/pom.xml

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010
<version>10.0.0-SNAPSHOT</version>
1111
</parent>
1212

13-
<artifactId>prometheus-metrics-exposition-formats</artifactId>
13+
<artifactId>prometheus-metrics-exposition-formats-no-protobuf</artifactId>
1414
<packaging>bundle</packaging>
1515

16-
<name>Prometheus Metrics Exposition Formats</name>
16+
<name>Prometheus Metrics Exposition Formats no protobuf</name>
1717
<description>
18-
Prometheus exposition formats.
18+
Prometheus exposition formats without shaded Protobuf classes.
1919
</description>
2020

2121
<properties>
22-
<automatic.module.name>io.prometheus.metrics.expositionformats</automatic.module.name>
23-
<protobuf-java.version>4.29.3</protobuf-java.version>
22+
<automatic.module.name>io.prometheus.metrics.expositionformats.noprotobuf</automatic.module.name>
2423
</properties>
2524

2625
<dependencies>
@@ -34,7 +33,6 @@
3433
<artifactId>protobuf-java</artifactId>
3534
<version>${protobuf-java.version}</version>
3635
</dependency>
37-
3836
</dependencies>
3937

4038
<profiles>
@@ -138,45 +136,6 @@
138136
<sourcepath>src/main/java;src/main/generated</sourcepath>
139137
</configuration>
140138
</plugin>
141-
<plugin>
142-
<groupId>org.apache.maven.plugins</groupId>
143-
<artifactId>maven-shade-plugin</artifactId>
144-
<executions>
145-
<execution>
146-
<phase>package</phase>
147-
<goals>
148-
<goal>shade</goal>
149-
</goals>
150-
<configuration>
151-
<shadeSourcesContent>true</shadeSourcesContent>
152-
<createSourcesJar>true</createSourcesJar>
153-
<artifactSet>
154-
<includes>
155-
<include>com.google.protobuf:protobuf-java</include>
156-
</includes>
157-
</artifactSet>
158-
<relocations>
159-
<relocation>
160-
<pattern>com.google.protobuf</pattern>
161-
<shadedPattern>
162-
io.prometheus.metrics.shaded.com_google_protobuf_${protobuf-java.string-version}
163-
</shadedPattern>
164-
</relocation>
165-
</relocations>
166-
<filters>
167-
<filter>
168-
<artifact>com.google.protobuf:protobuf-java</artifact>
169-
<excludes>
170-
<exclude>META-INF/maven/com.google.protobuf/**</exclude>
171-
<exclude>**/*.proto</exclude>
172-
<exclude>META-INF/MANIFEST.MF</exclude>
173-
</excludes>
174-
</filter>
175-
</filters>
176-
</configuration>
177-
</execution>
178-
</executions>
179-
</plugin>
180139
</plugins>
181140
</build>
182141
</project>

0 commit comments

Comments
 (0)