Skip to content

Commit

Permalink
include shaded protobuf directly (#1063)
Browse files Browse the repository at this point in the history
* include shaded protobuf directly

Signed-off-by: Gregor Zeitlinger <[email protected]>

* include shaded protobuf directly

Signed-off-by: Gregor Zeitlinger <[email protected]>

� Conflicts:
�	prometheus-metrics-shaded-dependencies/pom.xml

* remove shaded deps

Signed-off-by: Gregor Zeitlinger <[email protected]>

* format

Signed-off-by: Gregor Zeitlinger <[email protected]>

* fix shading

Signed-off-by: Gregor Zeitlinger <[email protected]>

* fix shading

Signed-off-by: Gregor Zeitlinger <[email protected]>

* fix shading

Signed-off-by: Gregor Zeitlinger <[email protected]>

* re-enable shading

Signed-off-by: Gregor Zeitlinger <[email protected]>

* re-enable shading

Signed-off-by: Gregor Zeitlinger <[email protected]>

* only build proto on CI

Signed-off-by: Gregor Zeitlinger <[email protected]>

* only build proto on CI

Signed-off-by: Gregor Zeitlinger <[email protected]>

* update protobuf

Signed-off-by: Gregor Zeitlinger <[email protected]>

* update protobuf

Signed-off-by: Gregor Zeitlinger <[email protected]>

* update protobuf

Signed-off-by: Gregor Zeitlinger <[email protected]>

* update protobuf

Signed-off-by: Gregor Zeitlinger <[email protected]>

---------

Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger authored Oct 9, 2024
1 parent cdcf2d2 commit c9bb30b
Show file tree
Hide file tree
Showing 22 changed files with 2,114 additions and 2,773 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ jobs:
java-version: 17
distribution: temurin
cache: 'maven'
- name: Shaded dependencies
run: |
cd prometheus-metrics-shaded-dependencies
../mvnw clean install
- name: Install Protoc
run: |
VERSION=28.2
curl -sL -o protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-linux-x86_64.zip
sudo unzip protoc.zip -d /usr/local
- name: Run the Maven verify phase
env:
PROTO_GENERATION: true
REQUIRE_PROTO_UP_TO_DATE: true
run: |
./mvnw clean install
./mvnw javadoc:javadoc
22 changes: 8 additions & 14 deletions .github/workflows/github-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@ jobs:
HUGO_VERSION: 0.115.4
JAVA_HOME: /usr/lib/jvm/java-17-openjdk-amd64
steps:
- name: Install OpenJDK 17
run: sudo apt-get -q install -y openjdk-17-jdk
- name: Make 17 the default java version
run: sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
- name: Make 17 the default javadoc version
run: sudo update-alternatives --set javadoc /usr/lib/jvm/java-17-openjdk-amd64/bin/javadoc
- name: Print java and javadoc versions
run: |
echo 'java --version' && \
java --version && \
echo 'javadoc --version' && \
javadoc --version && \
echo 'echo $JAVA_HOME' && \
echo $JAVA_HOME
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'maven'
- name: Install Protoc
uses: zchee/setup-protoc@v1
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
Expand Down
4 changes: 4 additions & 0 deletions MAINTAINER_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ Create a commit to remove dependencies from the build (undoing the first step):

* Comment out the `prometheus-metrics-shaded-dependencies` module to the root `pom.xml`.
* Change the versions of the shaded dependencies to the latest released version on Maven Central in `prometheus-metrics-exporter-opentelemetry`, `prometheus-metrics-exposition-formats`, and `prometheus-metrics-bom`.

## Notes

- `PROTO_GENERATION=true mvn clean install` to generate protobuf classes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io.prometheus.client.it.common.LogConsumer;
import io.prometheus.client.it.common.Volume;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_3_25_3.Metrics;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<module>prometheus-metrics-instrumentation-dropwizard5</module>
<module>prometheus-metrics-instrumentation-guava</module>
<module>prometheus-metrics-simpleclient-bridge</module>
<!-- <module>prometheus-metrics-shaded-dependencies</module> -->
<module>examples</module>
<module>benchmarks</module>
<module>integration-tests</module>
Expand Down
12 changes: 0 additions & 12 deletions prometheus-metrics-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@
<artifactId>prometheus-metrics-tracer-otel-agent</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-shaded-dependencies</artifactId>
<version>${prometheus.metrics.shaded.dependencies.version}</version>
<!-- <version>${project.version}</version> -->
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-shaded-protobuf</artifactId>
<version>${prometheus.metrics.shaded.dependencies.version}</version>
<!-- <version>${project.version}</version> -->
</dependency>
</dependencies>
</dependencyManagement>
</project>
3 changes: 2 additions & 1 deletion prometheus-metrics-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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">
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import io.prometheus.metrics.core.exemplars.ExemplarSamplerConfigTestUtil;
import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_3_25_3.Metrics;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
import io.prometheus.metrics.model.snapshots.Exemplar;
import io.prometheus.metrics.model.snapshots.Label;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.Unit;
import io.prometheus.metrics.shaded.com_google_protobuf_3_25_3.TextFormat;
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat;
import io.prometheus.metrics.tracer.common.SpanContext;
import io.prometheus.metrics.tracer.initializer.SpanContextSupplier;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import io.prometheus.metrics.core.exemplars.ExemplarSamplerConfigTestUtil;
import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_3_25_3.Metrics;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
import io.prometheus.metrics.model.snapshots.ClassicHistogramBucket;
import io.prometheus.metrics.model.snapshots.Exemplar;
import io.prometheus.metrics.model.snapshots.Exemplars;
import io.prometheus.metrics.model.snapshots.HistogramSnapshot;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.shaded.com_google_protobuf_3_25_3.TextFormat;
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat;
import io.prometheus.metrics.tracer.common.SpanContext;
import io.prometheus.metrics.tracer.initializer.SpanContextSupplier;
import java.io.ByteArrayOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_3_25_3.Metrics;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.shaded.com_google_protobuf_3_25_3.TextFormat;
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
34 changes: 24 additions & 10 deletions prometheus-metrics-exposition-formats/generate-protobuf.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#!/bin/bash

set -e
set -euo pipefail

# We use the shaded protobuf JAR from the protobuf-shaded module.
# I could not figure out how to use a protoc Maven plugin to use the shaded module, so I ran this command to generate the sources manually.

# The version string must be the same as in protobuf-shaded/pom.xml.
#export PROTOBUF_VERSION_STRING="3_21_7"
export PROTOBUF_VERSION_STRING="3_25_3"
TARGET_DIR=$1
PROTO_DIR=src/main/protobuf
PROTOBUF_VERSION_STRING=$2

rm -rf src/main/protobuf/*
curl -sL https://raw.githubusercontent.com/prometheus/client_model/master/io/prometheus/client/metrics.proto -o src/main/protobuf/metrics.proto
sed -i "s/java_package = \"io.prometheus.client\"/java_package = \"io.prometheus.metrics.expositionformats.generated.com_google_protobuf_${PROTOBUF_VERSION_STRING}\"/" src/main/protobuf/metrics.proto
rm -rf src/main/generated/*
protoc --java_out src/main/generated src/main/protobuf/metrics.proto
sed -i "s/com\\.google\\.protobuf/io.prometheus.metrics.shaded.com_google_protobuf_${PROTOBUF_VERSION_STRING}/g" "src/main/generated/io/prometheus/metrics/expositionformats/generated/com_google_protobuf_${PROTOBUF_VERSION_STRING}/Metrics.java"
echo "Generating protobuf sources for version $PROTOBUF_VERSION_STRING in $TARGET_DIR"

rm -rf TARGET_DIR || true
mkdir -p $TARGET_DIR
rm -rf $PROTO_DIR || true
mkdir -p $PROTO_DIR

curl -sL https://raw.githubusercontent.com/prometheus/client_model/master/io/prometheus/client/metrics.proto -o $PROTO_DIR/metrics.proto
sed -i "s/java_package = \"io.prometheus.client\"/java_package = \"io.prometheus.metrics.expositionformats.generated.com_google_protobuf_${PROTOBUF_VERSION_STRING}\"/" $PROTO_DIR/metrics.proto
protoc --java_out $TARGET_DIR $PROTO_DIR/metrics.proto

# stop the build if there class is not up-to-date
# show local changes
DIFF=$(git diff)
if [[ ${REQUIRE_PROTO_UP_TO_DATE:-false} == "true" && -n "$DIFF" ]]; then
echo "Generated protobuf sources are not up-to-date. Please run 'PROTO_GENERATION=true mvn clean install' and commit the changes."
echo "Local changes:"
echo "$DIFF"
exit 1
fi
100 changes: 95 additions & 5 deletions prometheus-metrics-exposition-formats/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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">
<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>
Expand All @@ -18,6 +19,7 @@

<properties>
<automatic.module.name>io.prometheus.metrics.expositionformats</automatic.module.name>
<protobuf-java.version>4.28.2</protobuf-java.version>
</properties>

<dependencies>
Expand All @@ -32,15 +34,69 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-shaded-protobuf</artifactId>
<version>1.3.1</version>
<!-- <version>${project.version}</version> -->
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf-java.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>protobuf-java.string-version</name>
<value>${protobuf-java.version}</value>
<regex>\.</regex>
<replacement>_</replacement>
<failIfNoMatch>true</failIfNoMatch>
</configuration>
</execution>
<execution>
<id>negate-prop</id>
<phase>initialize</phase>
<goals>
<goal>bsh-property</goal>
</goals>
<configuration>
<source>skip.protobuf.generation = !"true".equals(System.getenv("PROTO_GENERATION"));</source>
<properties>
<property>skip.protobuf.generation</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>3.4.1</version>
<executions>
<execution>
<id>Generate Protobuf</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<skip>${skip.protobuf.generation}</skip>
<executable>${project.basedir}/generate-protobuf.sh</executable>
<arguments>
<argument>${project.basedir}/src/main/generated</argument>
<argument>${protobuf-java.string-version}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand All @@ -66,6 +122,40 @@
<sourcepath>src/main/java;src/main/generated</sourcepath>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadeSourcesContent>true</shadeSourcesContent>
<createSourcesJar>true</createSourcesJar>
<relocations>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>
io.prometheus.metrics.shaded.com_google_protobuf_${protobuf-java.string-version}
</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>com.google.protobuf:protobuf-java</artifact>
<excludes>
<exclude>META-INF/maven/com.google.protobuf/**</exclude>
<exclude>**/*.proto</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions prometheus-metrics-exposition-formats/src/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
protobuf/
Loading

0 comments on commit c9bb30b

Please sign in to comment.