This is an automated email from the ASF dual-hosted git repository. penghui pushed a commit to branch branch-2.7 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 62fde99cb6338f4cd784c8681a0a8a6c46252298 Author: Enrico Olivelli <[email protected]> AuthorDate: Thu Nov 26 06:11:37 2020 +0100 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 55e40feeb04eeee075784736ffc9e826e132c455) --- .../java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java | 2 +- .../src/main/java-templates/org/apache/pulsar/PulsarVersion.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java index a47a680..96e396f 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java @@ -565,7 +565,7 @@ public class PrometheusMetricsTest extends BrokerTestBase { } Matcher matcher = pattern.matcher(line); - assertTrue(matcher.matches()); + assertTrue(matcher.matches(), "line " + line + " does not match pattern " + pattern); String name = matcher.group(1); Metric m = new Metric(); diff --git a/pulsar-common/src/main/java-templates/org/apache/pulsar/PulsarVersion.java b/pulsar-common/src/main/java-templates/org/apache/pulsar/PulsarVersion.java index 6bc9c17..07f97cd 100644 --- a/pulsar-common/src/main/java-templates/org/apache/pulsar/PulsarVersion.java +++ b/pulsar-common/src/main/java-templates/org/apache/pulsar/PulsarVersion.java @@ -70,6 +70,11 @@ public class PulsarVersion { public static String getGitSha() { String commit = "${git.commit.id}"; String dirtyString = "${git.dirty}"; + if (commit.contains("git.commit.id")){ + // this case may happen if you are building the sources + // out of the git repository + commit = ""; + } if (dirtyString == null || Boolean.valueOf(dirtyString)) { return commit + "(dirty)"; } else {
