Skip to content

Commit 62fde99

Browse files
eolivellicodelipenghui
authored andcommitted
Fix PrometheusMetricsTest on source tarball (#8702)
When you run the tests from the sources in the source release tarball there is no git reference and we are publishing on the metrics a placeholder. `pulsar_version_info{cluster="test",version="2.7.0",commit="${git.commit.id}"} ` I noticed the problem because PrometheusMetricsTest.java is failing on 2.7.0 sources The fix is to detect this fact an publish only an empty string. The change affects PulsarVersion, that in turn is used in Prometheus metrics endpoint (cherry picked from commit 55e40fe)
1 parent 35ca55c commit 62fde99

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private static Multimap<String, Metric> parseMetrics(String metrics) {
565565
}
566566

567567
Matcher matcher = pattern.matcher(line);
568-
assertTrue(matcher.matches());
568+
assertTrue(matcher.matches(), "line " + line + " does not match pattern " + pattern);
569569
String name = matcher.group(1);
570570

571571
Metric m = new Metric();

pulsar-common/src/main/java-templates/org/apache/pulsar/PulsarVersion.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public static String getVersion() {
7070
public static String getGitSha() {
7171
String commit = "${git.commit.id}";
7272
String dirtyString = "${git.dirty}";
73+
if (commit.contains("git.commit.id")){
74+
// this case may happen if you are building the sources
75+
// out of the git repository
76+
commit = "";
77+
}
7378
if (dirtyString == null || Boolean.valueOf(dirtyString)) {
7479
return commit + "(dirty)";
7580
} else {

0 commit comments

Comments
 (0)