Skip to content

Commit 831645c

Browse files
committed
make exceptions more specific, undo unrelated changes to pom and generate script
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
1 parent 6ebab1b commit 831645c

File tree

3 files changed

+12
-41
lines changed

3 files changed

+12
-41
lines changed

prometheus-metrics-exposition-formats-shaded/pom.xml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
</properties>
2424

2525
<dependencies>
26-
<!-- Ensures reactor builds exposition-formats first so generated protobuf sources exist before copy -->
27-
<dependency>
28-
<groupId>io.prometheus</groupId>
29-
<artifactId>prometheus-metrics-exposition-formats-no-protobuf</artifactId>
30-
<version>${project.version}</version>
31-
<scope>provided</scope>
32-
</dependency>
3326
<dependency>
3427
<groupId>io.prometheus</groupId>
3528
<artifactId>prometheus-metrics-exposition-textformats</artifactId>
@@ -76,26 +69,22 @@
7669
<executions>
7770
<execution>
7871
<id>copy-metrics-exposition-formats-main</id>
79-
<phase>generate-sources</phase>
72+
<phase>validate</phase>
8073
<goals>
8174
<goal>copy-resources</goal>
8275
</goals>
8376
<configuration>
8477
<outputDirectory>target/metrics-exposition-formats/src/main</outputDirectory>
85-
<overwrite>true</overwrite>
8678
<resources>
8779
<resource>
8880
<directory>../prometheus-metrics-exposition-formats/src/main</directory>
89-
<includes>
90-
<include>**/*</include>
91-
</includes>
9281
</resource>
9382
</resources>
9483
</configuration>
9584
</execution>
9685
<execution>
9786
<id>copy-metrics-exposition-formats-test</id>
98-
<phase>generate-sources</phase>
87+
<phase>validate</phase>
9988
<goals>
10089
<goal>copy-resources</goal>
10190
</goals>

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

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@ set -euo pipefail
66
# I could not figure out how to use a protoc Maven plugin to use the shaded module,
77
# so I ran this command to generate the sources manually.
88

9-
# Use gsed on macOS (requires: brew install gnu-sed) for in-place edits
10-
# BSD sed requires -i '' for in-place with no backup; GNU sed uses -i alone.
11-
if [[ "$OSTYPE" == "darwin"* ]] && command -v gsed >/dev/null 2>&1; then
12-
SED='gsed'
13-
SED_I=(-i)
14-
else
15-
SED='sed'
16-
# BSD sed: -i requires backup extension; '' = no backup
17-
[[ "$OSTYPE" == "darwin"* ]] && SED_I=(-i '') || SED_I=(-i)
18-
fi
19-
20-
# Use mise-provided protoc if available
21-
if command -v mise >/dev/null 2>&1; then
22-
PROTOC="mise exec -- protoc"
23-
else
24-
PROTOC='protoc'
25-
fi
26-
279
TARGET_DIR=$1
2810
PROTO_DIR=src/main/protobuf
2911
PROTOBUF_VERSION_STRING=$2
@@ -36,23 +18,22 @@ mkdir -p "$TARGET_DIR"
3618
rm -rf $PROTO_DIR || true
3719
mkdir -p $PROTO_DIR
3820

39-
OLD_PACKAGE=$($SED -nE 's/import (io.prometheus.metrics.expositionformats.generated.*).Metrics;/\1/p' src/main/java/io/prometheus/metrics/expositionformats/internal/PrometheusProtobufWriterImpl.java)
21+
OLD_PACKAGE=$(sed -nE 's/import (io.prometheus.metrics.expositionformats.generated.*).Metrics;/\1/p' src/main/java/io/prometheus/metrics/expositionformats/internal/PrometheusProtobufWriterImpl.java)
4022
PACKAGE="io.prometheus.metrics.expositionformats.generated.com_google_protobuf_${PROTOBUF_VERSION_STRING}"
4123

4224
if [[ $OLD_PACKAGE != "$PACKAGE" ]]; then
4325
echo "Replacing package $OLD_PACKAGE with $PACKAGE in all java files"
44-
find .. -type f -name "*.java" -exec "${SED}" "${SED_I[@]}" "s/$OLD_PACKAGE/$PACKAGE/g" {} +
26+
find .. -type f -name "*.java" -exec sed -i "s/$OLD_PACKAGE/$PACKAGE/g" {} +
4527
fi
4628

4729
curl -sL https://raw.githubusercontent.com/prometheus/client_model/master/io/prometheus/client/metrics.proto -o $PROTO_DIR/metrics.proto
4830

49-
"${SED}" "${SED_I[@]}" "s/java_package = \"io.prometheus.client\"/java_package = \"$PACKAGE\"/" $PROTO_DIR/metrics.proto
50-
$PROTOC --java_out "$TARGET_DIR" $PROTO_DIR/metrics.proto
51-
find src/main/generated/io -type f -exec "${SED}" "${SED_I[@]}" '1 i\
52-
//CHECKSTYLE:OFF: checkstyle' {} \;
53-
find src/main/generated/io -type f -exec "${SED}" "${SED_I[@]}" -e $'$a\\\n//CHECKSTYLE:ON: checkstyle' {} \;
31+
sed -i "s/java_package = \"io.prometheus.client\"/java_package = \"$PACKAGE\"/" $PROTO_DIR/metrics.proto
32+
protoc --java_out "$TARGET_DIR" $PROTO_DIR/metrics.proto
33+
sed -i '1 i\//CHECKSTYLE:OFF: checkstyle' "$(find src/main/generated/io -type f)"
34+
sed -i -e $'$a\\\n//CHECKSTYLE:ON: checkstyle' "$(find src/main/generated/io -type f)"
5435

55-
GENERATED_WITH=$($SED -n 's/.*\/\/ Protobuf Java Version: \(.*\)/\1/p' "$TARGET_DIR/${PACKAGE//\.//}"/Metrics.java)
36+
GENERATED_WITH=$(grep -oP '\/\/ Protobuf Java Version: \K.*' "$TARGET_DIR/${PACKAGE//\.//}"/Metrics.java)
5637

5738
function help() {
5839
echo "Please use https://mise.jdx.dev/ - this will use the version specified in mise.toml"

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ public void register(Collector collector) {
211211
collectorMetadata.put(
212212
collector, new CollectorRegistration(prometheusName, normalizedLabels));
213213
}
214-
} catch (Exception e) {
214+
215+
} catch (RuntimeException e) {
215216
collectors.remove(collector);
216217
CollectorRegistration reg = collectorMetadata.remove(collector);
217218
if (reg != null && reg.prometheusName != null) {
@@ -243,7 +244,7 @@ public void register(MultiCollector collector) {
243244
}
244245

245246
multiCollectorMetadata.put(collector, registrations);
246-
} catch (Exception e) {
247+
} catch (RuntimeException e) {
247248
multiCollectors.remove(collector);
248249
for (MultiCollectorRegistration registration : registrations) {
249250
unregisterLabelSchema(registration.prometheusName, registration.labelNames);

0 commit comments

Comments
 (0)