Skip to content

Commit 09d9eac

Browse files
authored
fix Protoc build (#1196)
* fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> * fix protoc generation Signed-off-by: Gregor Zeitlinger <[email protected]> --------- Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 0ef12e2 commit 09d9eac

File tree

10 files changed

+949
-930
lines changed

10 files changed

+949
-930
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14-
- name: Set up JDK
15-
uses: actions/setup-java@v4
14+
- name: Setup ASDF
15+
uses: equisoft-actions/with-asdf-vm@v2
16+
- name: Cache local Maven repository
17+
uses: actions/cache@v4
1618
with:
17-
java-version: 17
18-
distribution: temurin
19-
cache: 'maven'
20-
- name: Install Protoc
21-
run: |
22-
VERSION=28.2
23-
curl -sL -o protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-linux-x86_64.zip
24-
sudo unzip protoc.zip -d /usr/local
19+
path: ~/.m2/repository
20+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
21+
restore-keys: |
22+
${{ runner.os }}-maven-
2523
- name: Run the Maven verify phase
2624
env:
2725
PROTO_GENERATION: true
2826
REQUIRE_PROTO_UP_TO_DATE: true
2927
run: |
28+
echo "Java version: $(java -version) in $(which java), Maven version: $(mvn -v)"
29+
echo "JAVA_HOME: $JAVA_HOME"
3030
./mvnw clean install
3131
./mvnw javadoc:javadoc -P javadoc # just to check if javadoc is generated

.tool-versions

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
java temurin-17.0.7+7
1+
java temurin-17.0.13+11
2+
protoc 28.3

integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import io.prometheus.client.it.common.LogConsumer;
88
import io.prometheus.client.it.common.Volume;
9-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
9+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_3.Metrics;
1010
import java.io.ByteArrayInputStream;
1111
import java.io.IOException;
1212
import java.io.InputStream;

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import io.prometheus.metrics.core.exemplars.ExemplarSamplerConfigTestUtil;
99
import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter;
1010
import io.prometheus.metrics.expositionformats.TextFormatUtil;
11-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
11+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_3.Metrics;
1212
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
1313
import io.prometheus.metrics.model.snapshots.Exemplar;
1414
import io.prometheus.metrics.model.snapshots.Label;

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
1111
import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter;
1212
import io.prometheus.metrics.expositionformats.TextFormatUtil;
13-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
13+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_3.Metrics;
1414
import io.prometheus.metrics.model.snapshots.ClassicHistogramBucket;
1515
import io.prometheus.metrics.model.snapshots.Exemplar;
1616
import io.prometheus.metrics.model.snapshots.Exemplars;

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/InfoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter;
77
import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter;
88
import io.prometheus.metrics.expositionformats.TextFormatUtil;
9-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
9+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_3.Metrics;
1010
import io.prometheus.metrics.model.snapshots.Labels;
1111
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
1212
import io.prometheus.metrics.model.snapshots.Unit;

prometheus-metrics-exposition-formats/generate-protobuf.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,42 @@ set -euo pipefail
88
TARGET_DIR=$1
99
PROTO_DIR=src/main/protobuf
1010
PROTOBUF_VERSION_STRING=$2
11+
PROTOBUF_VERSION="${PROTOBUF_VERSION_STRING//_/.}"
1112

12-
echo "Generating protobuf sources for version $PROTOBUF_VERSION_STRING in $TARGET_DIR"
13+
echo "Generating protobuf sources for version $PROTOBUF_VERSION in $TARGET_DIR"
1314

14-
rm -rf TARGET_DIR || true
15+
rm -rf $TARGET_DIR
1516
mkdir -p $TARGET_DIR
1617
rm -rf $PROTO_DIR || true
1718
mkdir -p $PROTO_DIR
1819

20+
OLD_PACKAGE=$(sed -nE 's/import (io.prometheus.metrics.expositionformats.generated.*).Metrics;/\1/p' src/main/java/io/prometheus/metrics/expositionformats/PrometheusProtobufWriter.java)
21+
PACKAGE="io.prometheus.metrics.expositionformats.generated.com_google_protobuf_${PROTOBUF_VERSION_STRING}"
22+
23+
if [[ $OLD_PACKAGE != "$PACKAGE" ]]; then
24+
echo "Replacing package $OLD_PACKAGE with $PACKAGE in all java files"
25+
find .. -type f -name "*.java" -exec sed -i "s/$OLD_PACKAGE/$PACKAGE/g" {} +
26+
fi
27+
1928
curl -sL https://raw.githubusercontent.com/prometheus/client_model/master/io/prometheus/client/metrics.proto -o $PROTO_DIR/metrics.proto
20-
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
29+
30+
sed -i "s/java_package = \"io.prometheus.client\"/java_package = \"$PACKAGE\"/" $PROTO_DIR/metrics.proto
2131
protoc --java_out $TARGET_DIR $PROTO_DIR/metrics.proto
2232

23-
# stop the build if there class is not up-to-date
24-
# show local changes
25-
DIFF=$(git diff)
26-
if [[ ${REQUIRE_PROTO_UP_TO_DATE:-false} == "true" && -n "$DIFF" ]]; then
33+
GENERATED_WITH=$(grep -oP '\/\/ Protobuf Java Version: \K.*' "$TARGET_DIR/${PACKAGE//\.//}"/Metrics.java)
34+
35+
if [[ $GENERATED_WITH != "$PROTOBUF_VERSION" ]]; then
36+
echo "Generated protobuf sources version $GENERATED_WITH does not match provided version $PROTOBUF_VERSION"
37+
echo "Please update the protoc version .tool-versions to the latest version of https://github.com/protocolbuffers/protobuf/releases"
38+
echo "Please use https://github.com/asdf-vm/asdf - this will use the version specified in .tool-versions"
39+
exit 1
40+
fi
41+
42+
STATUS=$(git status --porcelain)
43+
if [[ ${REQUIRE_PROTO_UP_TO_DATE:-false} == "true" && -n "$STATUS" ]]; then
2744
echo "Generated protobuf sources are not up-to-date. Please run 'PROTO_GENERATION=true mvn clean install' and commit the changes."
2845
echo "Local changes:"
29-
echo "$DIFF"
46+
echo "$STATUS"
3047
exit 1
3148
fi
49+

0 commit comments

Comments
 (0)